Mercurial > dovecot > original-hg > dovecot-1.2
changeset 9611:63857c491143 HEAD
imap: If selecting a mailbox fails, close the already selected mailbox.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 01 Sep 2010 16:43:00 +0100 |
parents | 4f84f3fe15eb |
children | c4b2e4f4ff79 |
files | src/imap/cmd-select.c |
diffstat | 1 files changed, 25 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- 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