dovecot: Parse LIST-EXTENDED parameters more correctly.

dovecot at dovecot.org dovecot at dovecot.org
Fri Jun 29 17:39:52 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/1d91d36e14a4
changeset: 5832:1d91d36e14a4
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jun 29 17:39:45 2007 +0300
description:
Parse LIST-EXTENDED parameters more correctly.

diffstat:

1 file changed, 48 insertions(+), 36 deletions(-)
src/imap/cmd-list.c |   84 +++++++++++++++++++++++++++++----------------------

diffs (122 lines):

diff -r f22a7228dab8 -r 1d91d36e14a4 src/imap/cmd-list.c
--- a/src/imap/cmd-list.c	Fri Jun 29 16:35:29 2007 +0300
+++ b/src/imap/cmd-list.c	Fri Jun 29 17:39:45 2007 +0300
@@ -105,6 +105,11 @@ parse_select_flags(struct client_command
 				MAILBOX_LIST_ITER_RETURN_SUBSCRIBED;
 		} else if (strcasecmp(atom, "RECURSIVEMATCH") == 0)
 			*list_flags |= MAILBOX_LIST_ITER_SELECT_RECURSIVEMATCH;
+		else {
+			/* skip also optional list value */
+			if (args[1].type == IMAP_ARG_LIST)
+				args++;
+		}
 		args++;
 	}
 
@@ -136,6 +141,11 @@ parse_return_flags(struct client_command
 			*list_flags |= MAILBOX_LIST_ITER_RETURN_SUBSCRIBED;
 		else if (strcasecmp(atom, "CHILDREN") == 0)
 			*list_flags |= MAILBOX_LIST_ITER_RETURN_CHILDREN;
+		else {
+			/* skip also optional list value */
+			if (args[1].type == IMAP_ARG_LIST)
+				args++;
+		}
 		args++;
 	}
 	return TRUE;
@@ -695,7 +705,7 @@ bool _cmd_list_full(struct client_comman
 {
 	struct client *client = cmd->client;
 	struct imap_arg *args;
-	enum mailbox_list_flags list_flags;
+	enum mailbox_list_flags list_flags = 0;
         struct cmd_list_context *ctx;
 	const char *ref, *mask;
 	bool used_listext = FALSE;
@@ -704,48 +714,50 @@ bool _cmd_list_full(struct client_comman
 	   [RETURN (<return options>)] */
 	if (!client_read_args(cmd, 0, 0, &args))
 		return FALSE;
+
+	if (args[0].type == IMAP_ARG_LIST && !lsub) {
+		/* LIST-EXTENDED selection options */
+		used_listext = TRUE;
+		if (!parse_select_flags(cmd, IMAP_ARG_LIST(&args[0])->args,
+					&list_flags))
+			return TRUE;
+		args++;
+	}
+
+	ref = imap_arg_string(&args[0]);
+	if (ref == NULL) {
+		/* broken */
+		mask = NULL;
+	} else if (args[1].type == IMAP_ARG_LIST) {
+		/* FIXME: pattern list */
+		mask = NULL;
+		args += 2;
+	} else {
+		mask = imap_arg_string(&args[1]);
+		args += 2;
+	}
+
+	if (args[0].type == IMAP_ARG_ATOM && args[1].type == IMAP_ARG_LIST &&
+	    strcasecmp(imap_arg_string(&args[0]), "RETURN") == 0) {
+		/* LIST-EXTENDED return options */
+		used_listext = TRUE;
+		if (!parse_return_flags(cmd, IMAP_ARG_LIST(&args[1])->args,
+					&list_flags))
+			return TRUE;
+		args += 2;
+	}
 
 	if (lsub) {
 		/* LSUB - we don't care about flags */
 		list_flags = MAILBOX_LIST_ITER_SELECT_SUBSCRIBED |
 			MAILBOX_LIST_ITER_SELECT_RECURSIVEMATCH |
 			MAILBOX_LIST_ITER_RETURN_NO_FLAGS;
-	} else if (args[0].type != IMAP_ARG_LIST) {
-		/* LIST - allow children flags, but don't require them */
+	} else if (!used_listext) {
+		/* non-extended LIST - return children flags always */
 		list_flags = MAILBOX_LIST_ITER_RETURN_CHILDREN;
-	} else {
-		/* LIST-EXTENDED extension */
-		used_listext = TRUE;
-
-		if (!parse_select_flags(cmd, IMAP_ARG_LIST(&args[0])->args,
-					&list_flags))
-			return TRUE;
-		args++;
-
-		if (args[0].type == IMAP_ARG_EOL ||
-		    args[1].type == IMAP_ARG_EOL) {
-			client_send_command_error(cmd, "Invalid arguments.");
-			return TRUE;
-		}
-
-		if (args[2].type == IMAP_ARG_ATOM &&
-		    strcasecmp(imap_arg_string(&args[2]), "RETURN") == 0 &&
-		    args[3].type == IMAP_ARG_LIST &&
-		    args[4].type == IMAP_ARG_EOL) {
-			if (!parse_return_flags(cmd,
-						IMAP_ARG_LIST(&args[3])->args,
-						&list_flags))
-				return TRUE;
-		} else if (args[2].type != IMAP_ARG_EOL) {
-			client_send_command_error(cmd, "Invalid arguments.");
-			return TRUE;
-		}
-	}
-
-	ref = imap_arg_string(&args[0]);
-	mask = ref == NULL ? NULL : imap_arg_string(&args[1]);
-
-	if (ref == NULL || (mask == NULL && args[1].type != IMAP_ARG_LIST)) {
+	}
+
+	if (ref == NULL || args[0].type != IMAP_ARG_EOL) {
 		client_send_command_error(cmd, "Invalid arguments.");
 		return TRUE;
 	}


More information about the dovecot-cvs mailing list