changeset 22752:c150ff2c806e

lib-imap-client: After reconnection send retried commands last Previously only SELECT was sent before others. This allows sending more commands on reconnection before the retried commands.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 25 Dec 2017 18:49:15 +0200
parents 482337bf6a60
children 6e59f4b282a8
files src/lib-imap-client/imapc-connection.c
diffstat 1 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-imap-client/imapc-connection.c	Wed Nov 08 16:03:17 2017 +0200
+++ b/src/lib-imap-client/imapc-connection.c	Mon Dec 25 18:49:15 2017 +0200
@@ -2200,6 +2200,8 @@
 static void imapc_connection_cmd_send(struct imapc_command *cmd)
 {
 	struct imapc_connection *conn = cmd->conn;
+	struct imapc_command *const *cmds;
+	unsigned int i, count;
 
 	imapc_connection_send_idle_done(conn);
 
@@ -2211,14 +2213,13 @@
 		return;
 	}
 
-	if ((cmd->flags & IMAPC_COMMAND_FLAG_SELECT) != 0 &&
-	    conn->selected_box == NULL) {
-		/* reopening the mailbox. add it before other
-		   queued commands. */
-		array_insert(&conn->cmd_send_queue, 0, &cmd, 1);
-	} else {
-		array_append(&conn->cmd_send_queue, &cmd, 1);
+	/* add the command just before retried commands */
+	cmds = array_get(&conn->cmd_send_queue, &count);
+	for (i = count; i > 0; i--) {
+		if ((cmds[i-1]->flags & IMAPC_COMMAND_FLAG_RECONNECTED) == 0)
+			break;
 	}
+	array_insert(&conn->cmd_send_queue, i, &cmd, 1);
 	imapc_command_send_more(conn);
 }