]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: Send * OK [CLOSED] always before tagged SELECT reply.
authorTimo Sirainen <tss@iki.fi>
Sat, 21 Sep 2013 02:28:45 +0000 (05:28 +0300)
committerTimo Sirainen <tss@iki.fi>
Sat, 21 Sep 2013 02:28:45 +0000 (05:28 +0300)
src/imap/cmd-select.c
src/imap/imap-commands-util.c
src/imap/imap-commands-util.h

index 966ed2fa57df4bea0477325011ea9476b52e4b1f..6c7c550f62e946f01933fdaa850b2c7af33d238b 100644 (file)
@@ -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;
 
        /* <mailbox> [(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)) {
index 5f4ef3ebfbc28b566b5dd6811bd7fba146af301b..ebe70680d9923dc6e59c7db4ce7d478b7b104762 100644 (file)
 #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)
index 1aaa09e2ea08c7d01a4089702a1440280b79f2c8..304d0d35c25b0a423ae9b1fca6b9ef1d8da2e0be 100644 (file)
@@ -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. */