dovecot-2.2: imap: Send * OK [CLOSED] always before tagged SELEC...

dovecot at dovecot.org dovecot at dovecot.org
Sat Sep 21 05:28:55 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/c019b298e0f6
changeset: 16799:c019b298e0f6
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Sep 21 05:28:45 2013 +0300
description:
imap: Send * OK [CLOSED] always before tagged SELECT reply.

diffstat:

 src/imap/cmd-select.c         |   9 +++++----
 src/imap/imap-commands-util.c |  25 +++++++++++++++++++------
 src/imap/imap-commands-util.h |   3 +++
 3 files changed, 27 insertions(+), 10 deletions(-)

diffs (109 lines):

diff -r 2323c451150f -r c019b298e0f6 src/imap/cmd-select.c
--- a/src/imap/cmd-select.c	Sat Sep 21 05:05:22 2013 +0300
+++ b/src/imap/cmd-select.c	Sat Sep 21 05:28:45 2013 +0300
@@ -394,7 +394,7 @@
 	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 @@
 		return FALSE;
 
 	if (!imap_arg_get_astring(args, &mailbox)) {
+		close_selected_mailbox(client);
 		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);
-	(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 -r 2323c451150f -r c019b298e0f6 src/imap/imap-commands-util.c
--- a/src/imap/imap-commands-util.c	Sat Sep 21 05:05:22 2013 +0300
+++ b/src/imap/imap-commands-util.c	Sat Sep 21 05:28:45 2013 +0300
@@ -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 @@
 	    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 @@
 	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 -r 2323c451150f -r c019b298e0f6 src/imap/imap-commands-util.h
--- a/src/imap/imap-commands-util.h	Sat Sep 21 05:05:22 2013 +0300
+++ b/src/imap/imap-commands-util.h	Sat Sep 21 05:28:45 2013 +0300
@@ -13,6 +13,9 @@
    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. */


More information about the dovecot-cvs mailing list