changeset 22753:6e59f4b282a8

lib-imap-client: Delay sending more commands while SELECT is running
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 25 Dec 2017 21:29:06 +0200
parents c150ff2c806e
children 209a63ed9de1
files src/lib-imap-client/imapc-connection.c
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-imap-client/imapc-connection.c	Mon Dec 25 18:49:15 2017 +0200
+++ b/src/lib-imap-client/imapc-connection.c	Mon Dec 25 21:29:06 2017 +0200
@@ -135,6 +135,7 @@
 	unsigned int idling:1;
 	unsigned int idle_stopping:1;
 	unsigned int idle_plus_waiting:1;
+	unsigned int select_waiting_reply:1;
 };
 
 static void imapc_connection_capability_cb(const struct imapc_command_reply *reply,
@@ -384,6 +385,7 @@
 		conn->idle_plus_waiting = FALSE;
 		conn->idle_stopping = FALSE;
 
+		conn->select_waiting_reply = FALSE;
 		conn->selecting_box = NULL;
 		conn->selected_box = NULL;
 		/* fall through */
@@ -1433,6 +1435,8 @@
 			conn->cur_tag, line, reply.text_full);
 		return -1;
 	}
+	if ((cmd->flags & IMAPC_COMMAND_FLAG_SELECT) != 0)
+		conn->select_waiting_reply = FALSE;
 
 	if (reply.state == IMAPC_COMMAND_STATE_BAD) {
 		i_error("imapc(%s): Command '%s' failed with BAD: %u %s",
@@ -2048,6 +2052,7 @@
 		   are for the mailbox we're selecting */
 		conn->selected_box = box;
 	}
+	conn->select_waiting_reply = TRUE;
 }
 
 static bool imapc_connection_is_throttled(struct imapc_connection *conn)
@@ -2103,6 +2108,10 @@
 		/* wait until existing commands have finished */
 		return;
 	}
+	if (conn->select_waiting_reply) {
+		/* wait for SELECT to finish */
+		return;
+	}
 	if (cmd->wait_for_literal) {
 		/* wait until we received '+' */
 		return;