From: Timo Sirainen Date: Sat, 21 Sep 2013 02:28:45 +0000 (+0300) Subject: imap: Send * OK [CLOSED] always before tagged SELECT reply. X-Git-Tag: 2.2.6~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a471e03f0b63c3af7115c507edc34530f7351d3c;p=thirdparty%2Fdovecot%2Fcore.git imap: Send * OK [CLOSED] always before tagged SELECT reply. --- diff --git a/src/imap/cmd-select.c b/src/imap/cmd-select.c index 966ed2fa57..6c7c550f62 100644 --- a/src/imap/cmd-select.c +++ b/src/imap/cmd-select.c @@ -394,7 +394,7 @@ bool cmd_select_full(struct client_command_context *cmd, bool readonly) struct client *client = cmd->client; struct imap_select_context *ctx; const struct imap_arg *args, *list_args; - const char *mailbox; + const char *mailbox, *error; int ret; /* [(optional parameters)] */ @@ -402,19 +402,20 @@ bool cmd_select_full(struct client_command_context *cmd, bool readonly) return FALSE; if (!imap_arg_get_astring(args, &mailbox)) { - client_send_command_error(cmd, "Invalid arguments."); close_selected_mailbox(client); + client_send_command_error(cmd, "Invalid arguments."); return FALSE; } ctx = p_new(cmd->pool, struct imap_select_context, 1); ctx->cmd = cmd; - ctx->ns = client_find_namespace(cmd, &mailbox); - (void)gettimeofday(&ctx->start_time, NULL); + ctx->ns = client_find_namespace_full(cmd->client, &mailbox, &error); if (ctx->ns == NULL) { close_selected_mailbox(client); + client_send_tagline(cmd, error); return TRUE; } + (void)gettimeofday(&ctx->start_time, NULL); if (imap_arg_get_list(&args[1], &list_args)) { if (!select_parse_options(ctx, list_args)) { diff --git a/src/imap/imap-commands-util.c b/src/imap/imap-commands-util.c index 5f4ef3ebfb..ebe70680d9 100644 --- a/src/imap/imap-commands-util.c +++ b/src/imap/imap-commands-util.c @@ -15,15 +15,16 @@ #include "imap-commands-util.h" struct mail_namespace * -client_find_namespace(struct client_command_context *cmd, const char **mailbox) +client_find_namespace_full(struct client *client, + const char **mailbox, const char **error_r) { - struct mail_namespace *namespaces = cmd->client->user->namespaces; + struct mail_namespace *namespaces = client->user->namespaces; struct mail_namespace *ns; string_t *utf8_name; utf8_name = t_str_new(64); if (imap_utf7_to_utf8(*mailbox, utf8_name) < 0) { - client_send_tagline(cmd, "NO Mailbox name is not valid mUTF-7"); + *error_r = "NO Mailbox name is not valid mUTF-7"; return NULL; } @@ -32,14 +33,14 @@ client_find_namespace(struct client_command_context *cmd, const char **mailbox) ns->prefix_len == 0) { /* this matched only the autocreated prefix="" namespace. give a nice human-readable error message */ - client_send_tagline(cmd, t_strdup_printf( + *error_r = t_strdup_printf( "NO Client tried to access nonexistent namespace. " "(Mailbox name should probably be prefixed with: %s)", - mail_namespace_find_inbox(namespaces)->prefix)); + mail_namespace_find_inbox(namespaces)->prefix); return NULL; } - if ((cmd->client->set->parsed_workarounds & + if ((client->set->parsed_workarounds & WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 && str_len(utf8_name) > 0 && str_c(utf8_name)[str_len(utf8_name)-1] == mail_namespace_get_sep(ns)) { @@ -51,6 +52,18 @@ client_find_namespace(struct client_command_context *cmd, const char **mailbox) return ns; } +struct mail_namespace * +client_find_namespace(struct client_command_context *cmd, const char **mailbox) +{ + struct mail_namespace *ns; + const char *error; + + ns = client_find_namespace_full(cmd->client, mailbox, &error); + if (ns == NULL) + client_send_tagline(cmd, error); + return ns; +} + bool client_verify_open_mailbox(struct client_command_context *cmd) { if (cmd->client->mailbox != NULL) diff --git a/src/imap/imap-commands-util.h b/src/imap/imap-commands-util.h index 1aaa09e2ea..304d0d35c2 100644 --- a/src/imap/imap-commands-util.h +++ b/src/imap/imap-commands-util.h @@ -13,6 +13,9 @@ struct mailbox_keywords; or mailbox name is invalid, sends a tagged NO reply to client. */ struct mail_namespace * client_find_namespace(struct client_command_context *cmd, const char **mailbox); +struct mail_namespace * +client_find_namespace_full(struct client *client, + const char **mailbox, const char **error_r); /* Returns TRUE if mailbox is selected. If not, sends "No mailbox selected" error message to client. */