diff src/imap/cmd-sort.c @ 8005:67eb95aa7293 HEAD

SORT: Return BAD if sort program ends with REVERSE.
author Timo Sirainen <tss@iki.fi>
date Sun, 13 Jul 2008 19:08:13 +0300
parents 8e206e25a142
children 0a3b5ddb0869
line wrap: on
line diff
--- a/src/imap/cmd-sort.c	Sun Jul 13 18:04:19 2008 +0300
+++ b/src/imap/cmd-sort.c	Sun Jul 13 19:08:13 2008 +0300
@@ -30,7 +30,7 @@
 {
 	enum mail_sort_type mask = 0;
 	unsigned int i, pos;
-	bool reverse;
+	bool reverse, last_reverse;
 
 	if (args->type == IMAP_ARG_EOL) {
 		/* empyty list */
@@ -38,12 +38,13 @@
 		return -1;
 	}
 
-	pos = 0; reverse = FALSE;
+	pos = 0; reverse = last_reverse = FALSE;
 	for (; args->type == IMAP_ARG_ATOM || args->type == IMAP_ARG_STRING;
 	     args++) {
 		const char *arg = IMAP_ARG_STR(args);
 
-		if (strcasecmp(arg, "reverse") == 0) {
+		last_reverse = strcasecmp(arg, "reverse") == 0;
+		if (last_reverse) {
 			reverse = !reverse;
 			continue;
 		}
@@ -70,7 +71,10 @@
 			(reverse ? MAIL_SORT_FLAG_REVERSE : 0);
 		reverse = FALSE;
 	}
-
+	if (last_reverse) {
+		client_send_command_error(cmd, "Sort list ends with REVERSE.");
+		return -1;
+	}
 	program[pos++] = MAIL_SORT_END;
 
 	if (args->type != IMAP_ARG_EOL) {