dovecot-2.0: imap: If selecting a mailbox fails, close the alrea...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Sep 1 18:40:56 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/a428dd6fe3e7
changeset: 12055:a428dd6fe3e7
user: Timo Sirainen <tss at iki.fi>
date: Wed Sep 01 16:40:53 2010 +0100
description:
imap: If selecting a mailbox fails, close the already selected mailbox.
diffstat:
src/imap/cmd-select.c | 35 +++++++++++++++++++++++------------
1 files changed, 23 insertions(+), 12 deletions(-)
diffs (82 lines):
diff -r 5163d94d4272 -r a428dd6fe3e7 src/imap/cmd-select.c
--- a/src/imap/cmd-select.c Wed Sep 01 16:22:20 2010 +0100
+++ b/src/imap/cmd-select.c Wed Sep 01 16:40:53 2010 +0100
@@ -348,10 +348,25 @@
return 0;
}
+static void close_selected_mailbox(struct client *client)
+{
+ struct mailbox *box;
+
+ if (client->mailbox == NULL)
+ return;
+
+ client_search_updates_free(client);
+ box = client->mailbox;
+ client->mailbox = NULL;
+
+ mailbox_free(&box);
+ /* 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, *list_args;
enum mailbox_name_status status;
@@ -364,14 +379,17 @@
if (!imap_arg_get_astring(args, &mailbox)) {
client_send_command_error(cmd, "Invalid arguments.");
+ close_selected_mailbox(client);
return FALSE;
}
ctx = p_new(cmd->pool, struct imap_select_context, 1);
ctx->cmd = cmd;
ctx->ns = client_find_namespace(cmd, mailbox, &storage_name, &status);
- if (ctx->ns == NULL)
+ if (ctx->ns == NULL) {
+ close_selected_mailbox(client);
return TRUE;
+ }
switch (status) {
case MAILBOX_NAME_EXISTS_MAILBOX:
break;
@@ -382,12 +400,14 @@
case MAILBOX_NAME_INVALID:
case MAILBOX_NAME_NOINFERIORS:
client_fail_mailbox_name_status(cmd, mailbox, NULL, status);
+ close_selected_mailbox(client);
return TRUE;
}
if (imap_arg_get_list(&args[1], &list_args)) {
if (!select_parse_options(ctx, list_args)) {
select_context_free(ctx);
+ close_selected_mailbox(client);
return TRUE;
}
}
@@ -395,16 +415,7 @@
i_assert(client->mailbox_change_lock == NULL);
client->mailbox_change_lock = cmd;
- if (client->mailbox != NULL) {
- client_search_updates_free(client);
- box = client->mailbox;
- client->mailbox = NULL;
-
- mailbox_free(&box);
- /* 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