dovecot-2.2: imapc: If connection isn't in selected state when d...

dovecot at dovecot.org dovecot at dovecot.org
Wed Sep 24 21:44:06 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/d467f4c20abb
changeset: 17830:d467f4c20abb
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Sep 25 00:40:48 2014 +0300
description:
imapc: If connection isn't in selected state when deleting mailbox, don't try to UNSELECT it.

diffstat:

 src/lib-imap-client/imapc-client.h       |   2 ++
 src/lib-imap-client/imapc-connection.c   |  14 ++++++++++++++
 src/lib-storage/index/imapc/imapc-list.c |  16 ++++++++++------
 3 files changed, 26 insertions(+), 6 deletions(-)

diffs (74 lines):

diff -r e1cc249ad417 -r d467f4c20abb src/lib-imap-client/imapc-client.h
--- a/src/lib-imap-client/imapc-client.h	Wed Sep 24 20:01:46 2014 +0000
+++ b/src/lib-imap-client/imapc-client.h	Thu Sep 25 00:40:48 2014 +0300
@@ -146,11 +146,13 @@
 		 imapc_command_callback_t *callback, void *context);
 void imapc_command_set_flags(struct imapc_command *cmd,
 			     enum imapc_command_flags flags);
+bool imapc_command_connection_is_selected(struct imapc_command *cmd);
 void imapc_command_send(struct imapc_command *cmd, const char *cmd_str);
 void imapc_command_sendf(struct imapc_command *cmd, const char *cmd_fmt, ...)
 	ATTR_FORMAT(2, 3);
 void imapc_command_sendvf(struct imapc_command *cmd,
 			  const char *cmd_fmt, va_list args) ATTR_FORMAT(2, 0);
+void imapc_command_abort(struct imapc_command **cmd);
 
 void imapc_client_register_untagged(struct imapc_client *client,
 				    imapc_untagged_callback_t *callback,
diff -r e1cc249ad417 -r d467f4c20abb src/lib-imap-client/imapc-connection.c
--- a/src/lib-imap-client/imapc-connection.c	Wed Sep 24 20:01:46 2014 +0000
+++ b/src/lib-imap-client/imapc-connection.c	Thu Sep 25 00:40:48 2014 +0300
@@ -1481,6 +1481,14 @@
 	pool_unref(&cmd->pool);
 }
 
+void imapc_command_abort(struct imapc_command **_cmd)
+{
+	struct imapc_command *cmd = *_cmd;
+
+	*_cmd = NULL;
+	imapc_command_free(cmd);
+}
+
 static void imapc_command_timeout(struct imapc_connection *conn)
 {
 	struct imapc_command *const *cmds;
@@ -1780,6 +1788,12 @@
 	box->pending_box_command_count++;
 }
 
+bool imapc_command_connection_is_selected(struct imapc_command *cmd)
+{
+	return cmd->conn->selected_box != NULL ||
+		cmd->conn->selecting_box != NULL;
+}
+
 void imapc_command_send(struct imapc_command *cmd, const char *cmd_str)
 {
 	unsigned int len = strlen(cmd_str);
diff -r e1cc249ad417 -r d467f4c20abb src/lib-storage/index/imapc/imapc-list.c
--- a/src/lib-storage/index/imapc/imapc-list.c	Wed Sep 24 20:01:46 2014 +0000
+++ b/src/lib-storage/index/imapc/imapc-list.c	Thu Sep 25 00:40:48 2014 +0300
@@ -800,12 +800,16 @@
 	capa = imapc_client_get_capabilities(list->client->client);
 
 	cmd = imapc_list_simple_context_init(&ctx, list);
-	imapc_command_set_flags(cmd, IMAPC_COMMAND_FLAG_SELECT);
-	if ((capa & IMAPC_CAPABILITY_UNSELECT) != 0)
-		imapc_command_sendf(cmd, "UNSELECT");
-	else
-		imapc_command_sendf(cmd, "SELECT \"~~~\"");
-	imapc_simple_run(&ctx);
+	if (!imapc_command_connection_is_selected(cmd))
+		imapc_command_abort(&cmd);
+	else {
+		imapc_command_set_flags(cmd, IMAPC_COMMAND_FLAG_SELECT);
+		if ((capa & IMAPC_CAPABILITY_UNSELECT) != 0)
+			imapc_command_sendf(cmd, "UNSELECT");
+		else
+			imapc_command_sendf(cmd, "SELECT \"~~~\"");
+		imapc_simple_run(&ctx);
+	}
 
 	cmd = imapc_list_simple_context_init(&ctx, list);
 	imapc_command_sendf(cmd, "DELETE %s", name);


More information about the dovecot-cvs mailing list