changeset 19626:d9905cfd13fd

imapc: If command times out, reconnect and retry if possible.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Sun, 24 Jan 2016 20:07:58 +0200
parents 0473b9d7e0fd
children 7c7e554860c6
files src/lib-imap-client/imapc-connection.c
diffstat 1 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-imap-client/imapc-connection.c	Sun Jan 24 19:54:51 2016 +0200
+++ b/src/lib-imap-client/imapc-connection.c	Sun Jan 24 20:07:58 2016 +0200
@@ -1789,13 +1789,26 @@
 {
 	struct imapc_command *const *cmds;
 	unsigned int count;
+	string_t *str = t_str_new(128);
+	bool reconnect = imapc_connection_can_reconnect(conn);
 
 	cmds = array_get(&conn->cmd_wait_list, &count);
 	i_assert(count > 0);
 
-	i_error("imapc(%s): Command '%s' timed out, disconnecting",
-		conn->name, imapc_command_get_readable(cmds[0]));
-	imapc_connection_disconnect(conn);
+	str_printfa(str, "imapc(%s): Command '%s' timed out, ",
+		    conn->name, imapc_command_get_readable(cmds[0]));
+	if (reconnect)
+		str_append(str, "reconnecting");
+	else
+		str_append(str, "disconnecting");
+
+	if (reconnect) {
+		i_warning("%s", str_c(str));
+		imapc_connection_reconnect(conn);
+	} else {
+		i_error("%s", str_c(str));
+		imapc_connection_disconnect(conn);
+	}
 }
 
 static bool