From: Martti Rannanjärvi Date: Tue, 4 Jul 2017 06:25:21 +0000 (+0300) Subject: imap-client: Add const char *disconnect_reason to client X-Git-Tag: 2.3.0.rc1~1240 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d6bb1be2c65b5bef882946a6610e8fdcfd4ea27e;p=thirdparty%2Fdovecot%2Fcore.git imap-client: Add const char *disconnect_reason to client This is to allow using reason given to client_disconnect() via timeout context. --- diff --git a/src/imap/imap-client.c b/src/imap/imap-client.c index 92d74777f7..e4356e1864 100644 --- a/src/imap/imap-client.c +++ b/src/imap/imap-client.c @@ -379,14 +379,7 @@ static const char *client_get_commands_status(struct client *client) 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) @@ -395,11 +388,15 @@ static void client_default_destroy(struct client *client, const char *reason) 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); @@ -454,8 +451,10 @@ static void client_default_destroy(struct client *client, const char *reason) 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 @@ -490,8 +489,8 @@ void client_disconnect(struct client *client, const char *reason) 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 --git a/src/imap/imap-client.h b/src/imap/imap-client.h index cfbd679dde..e085ac613e 100644 --- a/src/imap/imap-client.h +++ b/src/imap/imap-client.h @@ -157,6 +157,7 @@ struct client { 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;