dovecot-1.2: imap: If selecting a mailbox fails, close the alrea...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Sep 1 18:43:02 EEST 2010
details: http://hg.dovecot.org/dovecot-1.2/rev/63857c491143
changeset: 9611:63857c491143
user: Timo Sirainen <tss at iki.fi>
date: Wed Sep 01 16:43:00 2010 +0100
description:
imap: If selecting a mailbox fails, close the already selected mailbox.
diffstat:
src/imap/cmd-select.c | 41 +++++++++++++++++++++++++----------------
1 files changed, 25 insertions(+), 16 deletions(-)
diffs (80 lines):
diff -r 4f84f3fe15eb -r 63857c491143 src/imap/cmd-select.c
--- a/src/imap/cmd-select.c Tue Aug 31 17:06:20 2010 +0100
+++ b/src/imap/cmd-select.c Wed Sep 01 16:43:00 2010 +0100
@@ -327,10 +327,28 @@
return 0;
}
+static void close_selected_mailbox(struct client *client)
+{
+ struct mail_storage *old_storage;
+ struct mailbox *box;
+
+ if (client->mailbox == NULL)
+ return;
+
+ old_storage = mailbox_get_storage(client->mailbox);
+ client_search_updates_free(client);
+ box = client->mailbox;
+ client->mailbox = NULL;
+
+ if (mailbox_close(&box) < 0)
+ client_send_untagged_storage_error(client, old_storage);
+ /* CLOSED response is required by QRESYNC */
+ client_send_line(client, "* OK [CLOSED] Previous mailbox closed.");
+}
+
bool cmd_select_full(struct client_command_context *cmd, bool readonly)
{
struct client *client = cmd->client;
- struct mailbox *box;
struct imap_select_context *ctx;
const struct imap_arg *args;
const char *mailbox;
@@ -342,6 +360,7 @@
if (!IMAP_ARG_TYPE_IS_STRING(args[0].type)) {
client_send_command_error(cmd, "Invalid arguments.");
+ close_selected_mailbox(client);
return FALSE;
}
mailbox = IMAP_ARG_STR(&args[0]);
@@ -349,12 +368,15 @@
ctx = p_new(cmd->pool, struct imap_select_context, 1);
ctx->cmd = cmd;
ctx->storage = client_find_storage(cmd, &mailbox);
- if (ctx->storage == NULL)
+ if (ctx->storage == NULL) {
+ close_selected_mailbox(client);
return TRUE;
+ }
if (args[1].type == IMAP_ARG_LIST) {
if (!select_parse_options(ctx, IMAP_ARG_LIST_ARGS(&args[1]))) {
select_context_free(ctx);
+ close_selected_mailbox(client);
return TRUE;
}
}
@@ -362,20 +384,7 @@
i_assert(client->mailbox_change_lock == NULL);
client->mailbox_change_lock = cmd;
- if (client->mailbox != NULL) {
- struct mail_storage *old_storage =
- mailbox_get_storage(client->mailbox);
-
- client_search_updates_free(client);
- box = client->mailbox;
- client->mailbox = NULL;
-
- if (mailbox_close(&box) < 0)
- client_send_untagged_storage_error(client, old_storage);
- /* CLOSED response is required by QRESYNC */
- client_send_line(client,
- "* OK [CLOSED] Previous mailbox closed.");
- }
+ close_selected_mailbox(client);
if (ctx->condstore) {
/* Enable while no mailbox is opened to avoid sending
More information about the dovecot-cvs
mailing list