changeset 22375:06def4e9a4a2

imap-client: Add const char *disconnect_reason to client This is to allow using reason given to client_disconnect() via timeout context.
author Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
date Tue, 04 Jul 2017 09:25:21 +0300
parents 542b9643d6b1
children dacbb97f754c
files src/imap/imap-client.c src/imap/imap-client.h
diffstat 2 files changed, 14 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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);
 
--- 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;