# HG changeset patch # User Martti Rannanjärvi # Date 1499149521 -10800 # Node ID 06def4e9a4a2e3c32ee9a58cd8b3bd1ecff15768 # Parent 542b9643d6b1424c54cc80416e6348791543b663 imap-client: Add const char *disconnect_reason to client This is to allow using reason given to client_disconnect() via timeout context. diff -r 542b9643d6b1 -r 06def4e9a4a2 src/imap/imap-client.c --- a/src/imap/imap-client.c Wed Jul 19 13:43:09 2017 +0300 +++ b/src/imap/imap-client.c Tue Jul 04 09:25:21 2017 +0300 @@ -386,14 +386,7 @@ static void client_log_disconnect(struct client *client, const char *reason) { - const char *cmd_status = ""; - - if (reason == NULL) { - reason = io_stream_get_disconnect_reason(client->input, - client->output); - cmd_status = client_get_commands_status(client); - } - i_info("%s%s %s", reason, cmd_status, client_stats(client)); + i_info("%s %s", reason, client_stats(client)); } static void client_default_destroy(struct client *client, const char *reason) @@ -402,11 +395,15 @@ i_assert(!client->destroyed); client->destroyed = TRUE; + client->disconnected = TRUE; - if (!client->disconnected) { - client->disconnected = TRUE; - client_log_disconnect(client, reason); - } + if (client->disconnect_reason != NULL) + reason = client->disconnect_reason; + if (reason == NULL) + reason = t_strconcat( + io_stream_get_disconnect_reason(client->input, + client->output), + client_get_commands_status(client), NULL); i_stream_close(client->input); o_stream_close(client->output); @@ -461,8 +458,10 @@ different from the non-hibernating IDLE case. For frequent hibernations it could also be doing unnecessarily much work. */ imap_refresh_proctitle(); - if (!client->hibernated) + if (!client->hibernated) { mail_user_autoexpunge(client->user); + client_log_disconnect(client, reason); + } mail_user_unref(&client->user); /* free the i/ostreams after mail_user_unref(), which could trigger @@ -497,8 +496,8 @@ if (client->disconnected) return; - client_log_disconnect(client, reason); client->disconnected = TRUE; + client->disconnect_reason = p_strdup(client->pool, reason); o_stream_nflush(client->output); o_stream_uncork(client->output); diff -r 542b9643d6b1 -r 06def4e9a4a2 src/imap/imap-client.h --- a/src/imap/imap-client.h Wed Jul 19 13:43:09 2017 +0300 +++ b/src/imap/imap-client.h Tue Jul 04 09:25:21 2017 +0300 @@ -157,6 +157,7 @@ const struct imap_settings *set; const struct lda_settings *lda_set; string_t *capability_string; + const char *disconnect_reason; struct mail_user *user; struct mailbox *mailbox;