dovecot-1.2: imap: Don't send NONEXISTENT resp code to non-delet...

dovecot at dovecot.org dovecot at dovecot.org
Mon Nov 23 22:04:23 EET 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/3efdbaab2960
changeset: 9492:3efdbaab2960
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Nov 23 15:04:17 2009 -0500
description:
imap: Don't send NONEXISTENT resp code to non-delete operations.

diffstat:

3 files changed, 21 insertions(+), 11 deletions(-)
src/imap/commands-util.c |   19 ++++++++++++-------
src/imap/commands.c      |    6 +++---
src/imap/commands.h      |    7 ++++++-

diffs (109 lines):

diff -r 76294bdecd5a -r 3efdbaab2960 src/imap/commands-util.c
--- a/src/imap/commands-util.c	Mon Nov 23 14:48:49 2009 -0500
+++ b/src/imap/commands-util.c	Mon Nov 23 15:04:17 2009 -0500
@@ -129,23 +129,26 @@ bool client_verify_mailbox_name(struct c
 		break;
 
 	case MAILBOX_NAME_VALID:
+		resp_code = "";
 		switch (mode) {
 		case CLIENT_VERIFY_MAILBOX_NAME:
 		case CLIENT_VERIFY_MAILBOX_SHOULD_NOT_EXIST:
 			return TRUE;
 		case CLIENT_VERIFY_MAILBOX_SHOULD_EXIST:
-			resp_code = IMAP_RESP_CODE_NONEXISTENT;
+			if ((cmd->cmd_flags & COMMAND_FLAG_USE_NONEXISTENT) != 0)
+				resp_code = IMAP_RESP_CODE_NONEXISTENT;
 			break;
 		case CLIENT_VERIFY_MAILBOX_SHOULD_EXIST_TRYCREATE:
 			resp_code = "TRYCREATE";
 			break;
 		default:
-			resp_code = NULL;
 			i_unreached();
 		}
 
+		if (*resp_code != '\0')
+			resp_code = t_strconcat("[", resp_code, "] ", NULL);
 		client_send_tagline(cmd, t_strconcat(
-			"NO [", resp_code, "] Mailbox doesn't exist: ",
+			"NO ", resp_code, "Mailbox doesn't exist: ",
 			str_sanitize(orig_mailbox, MAILBOX_MAX_NAME_LEN),
 			NULL));
 		break;
@@ -180,7 +183,8 @@ bool client_verify_open_mailbox(struct c
 }
 
 static const char *
-get_error_string(const char *error_string, enum mail_error error)
+get_error_string(struct client_command_context *cmd,
+		 const char *error_string, enum mail_error error)
 {
 	const char *resp_code = NULL;
 
@@ -201,7 +205,8 @@ get_error_string(const char *error_strin
 		resp_code = IMAP_RESP_CODE_OVERQUOTA;
 		break;
 	case MAIL_ERROR_NOTFOUND:
-		resp_code = IMAP_RESP_CODE_NONEXISTENT;
+		if ((cmd->cmd_flags & COMMAND_FLAG_USE_NONEXISTENT) != 0)
+			resp_code = IMAP_RESP_CODE_NONEXISTENT;
 		break;
 	case MAIL_ERROR_EXISTS:
 		resp_code = IMAP_RESP_CODE_ALREADYEXISTS;
@@ -226,7 +231,7 @@ void client_send_list_error(struct clien
 	enum mail_error error;
 
 	error_string = mailbox_list_get_last_error(list, &error);
-	client_send_tagline(cmd, get_error_string(error_string, error));
+	client_send_tagline(cmd, get_error_string(cmd, error_string, error));
 }
 
 void client_send_storage_error(struct client_command_context *cmd,
@@ -244,7 +249,7 @@ void client_send_storage_error(struct cl
 	}
 
 	error_string = mail_storage_get_last_error(storage, &error);
-	client_send_tagline(cmd, get_error_string(error_string, error));
+	client_send_tagline(cmd, get_error_string(cmd, error_string, error));
 }
 
 void client_send_untagged_storage_error(struct client *client,
diff -r 76294bdecd5a -r 3efdbaab2960 src/imap/commands.c
--- a/src/imap/commands.c	Mon Nov 23 14:48:49 2009 -0500
+++ b/src/imap/commands.c	Mon Nov 23 15:04:17 2009 -0500
@@ -15,14 +15,14 @@ static const struct command imap4rev1_co
 	{ "APPEND",		cmd_append,      COMMAND_FLAG_BREAKS_SEQS },
 	{ "EXAMINE",		cmd_examine,     COMMAND_FLAG_BREAKS_MAILBOX },
 	{ "CREATE",		cmd_create,      0 },
-	{ "DELETE",		cmd_delete,      0 },
-	{ "RENAME",		cmd_rename,      0 },
+	{ "DELETE",		cmd_delete,      COMMAND_FLAG_USE_NONEXISTENT },
+	{ "RENAME",		cmd_rename,      COMMAND_FLAG_USE_NONEXISTENT },
 	{ "LIST",		cmd_list,        0 },
 	{ "LSUB",		cmd_lsub,        0 },
 	{ "SELECT",		cmd_select,      COMMAND_FLAG_BREAKS_MAILBOX },
 	{ "STATUS",		cmd_status,      0 },
 	{ "SUBSCRIBE",		cmd_subscribe,   0 },
-	{ "UNSUBSCRIBE",	cmd_unsubscribe, 0 },
+	{ "UNSUBSCRIBE",	cmd_unsubscribe, COMMAND_FLAG_USE_NONEXISTENT },
 
 	{ "CHECK",		cmd_check,       COMMAND_FLAG_BREAKS_SEQS },
 	{ "CLOSE",		cmd_close,       COMMAND_FLAG_BREAKS_MAILBOX },
diff -r 76294bdecd5a -r 3efdbaab2960 src/imap/commands.h
--- a/src/imap/commands.h	Mon Nov 23 14:48:49 2009 -0500
+++ b/src/imap/commands.h	Mon Nov 23 15:04:17 2009 -0500
@@ -23,7 +23,12 @@ enum command_flags {
 					  COMMAND_FLAG_USES_SEQS,
 
 	/* Command requires mailbox syncing before it can do its job. */
-	COMMAND_FLAG_REQUIRES_SYNC	= 0x08
+	COMMAND_FLAG_REQUIRES_SYNC	= 0x08,
+	/* Command allows replying with [NONEXISTENT] imap resp code.
+	   Dovecot internally returns it for all kinds of commands,
+	   but unfortunately RFC 5530 specifies it only for "delete something"
+	   operations. */
+	COMMAND_FLAG_USE_NONEXISTENT	= 0x10
 };
 
 struct command {


More information about the dovecot-cvs mailing list