dovecot-2.2: lib-storage: If mail_search_args_simplify() merges ...

dovecot at dovecot.org dovecot at dovecot.org
Thu Apr 23 16:51:24 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/dcad04c2bab0
changeset: 18461:dcad04c2bab0
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Apr 23 19:49:49 2015 +0300
description:
lib-storage: If mail_search_args_simplify() merges flags, check again if any SUBs can be removed.
The subquery may have been replaced with a single SEARCH_FLAGS parameter.

diffstat:

 src/lib-storage/mail-search-args-simplify.c      |  17 +++++++++++++----
 src/lib-storage/test-mail-search-args-simplify.c |   5 +++--
 2 files changed, 16 insertions(+), 6 deletions(-)

diffs (88 lines):

diff -r 447b82d4ecb1 -r dcad04c2bab0 src/lib-storage/mail-search-args-simplify.c
--- a/src/lib-storage/mail-search-args-simplify.c	Thu Apr 23 19:42:13 2015 +0300
+++ b/src/lib-storage/mail-search-args-simplify.c	Thu Apr 23 19:49:49 2015 +0300
@@ -3,12 +3,13 @@
 #include "lib.h"
 #include "mail-search.h"
 
-static void
+static bool
 mail_search_args_simplify_sub(struct mailbox *box,
 			      struct mail_search_arg *args, bool parent_and)
 {
 	struct mail_search_arg *sub, *prev = NULL;
 	struct mail_search_arg *prev_flags_arg, *prev_not_flags_arg;
+	bool removals;
 
 	prev_flags_arg = prev_not_flags_arg = NULL;
 	while (args != NULL) {
@@ -43,8 +44,9 @@
 		if (args->type == SEARCH_SUB ||
 		    args->type == SEARCH_OR ||
 		    args->type == SEARCH_INTHREAD) {
-			mail_search_args_simplify_sub(box, args->value.subargs,
-						      args->type != SEARCH_OR);
+			if (mail_search_args_simplify_sub(box, args->value.subargs,
+							  args->type != SEARCH_OR))
+				removals = TRUE;
 		}
 
 		/* merge all flags arguments */
@@ -57,6 +59,7 @@
 					args->value.flags;
 				prev->next = args->next;
 				args = args->next;
+				removals = TRUE;
 				continue;
 			}
 		} else if (args->type == SEARCH_FLAGS && args->match_not &&
@@ -68,6 +71,7 @@
 					args->value.flags;
 				prev->next = args->next;
 				args = args->next;
+				removals = TRUE;
 				continue;
 			}
 		}
@@ -75,6 +79,7 @@
 		prev = args;
 		args = args->next;
 	}
+	return removals;
 }
 
 static bool
@@ -145,12 +150,16 @@
 
 void mail_search_args_simplify(struct mail_search_args *args)
 {
+	bool removals;
+
 	args->simplified = TRUE;
 
-	mail_search_args_simplify_sub(args->box, args->args, TRUE);
+	removals = mail_search_args_simplify_sub(args->box, args->args, TRUE);
 	if (mail_search_args_unnest_inthreads(args, &args->args,
 					      FALSE, TRUE)) {
 		/* we may have added some extra SUBs that could be dropped */
 		mail_search_args_simplify_sub(args->box, args->args, TRUE);
 	}
+	if (removals)
+		mail_search_args_simplify_sub(args->box, args->args, TRUE);
 }
diff -r 447b82d4ecb1 -r dcad04c2bab0 src/lib-storage/test-mail-search-args-simplify.c
--- a/src/lib-storage/test-mail-search-args-simplify.c	Thu Apr 23 19:42:13 2015 +0300
+++ b/src/lib-storage/test-mail-search-args-simplify.c	Thu Apr 23 19:49:49 2015 +0300
@@ -29,9 +29,10 @@
 	{ "NOT ( TEXT foo TEXT bar )", "(OR NOT TEXT foo NOT TEXT bar)" },
 
 	{ "ANSWERED FLAGGED SEEN", "(ANSWERED FLAGGED SEEN)" },
+	{ "OR ( ANSWERED FLAGGED SEEN ) DRAFT", "(OR (ANSWERED FLAGGED SEEN) (DRAFT))" },
 	{ "ANSWERED TEXT foo FLAGGED SEEN", "(ANSWERED FLAGGED SEEN) TEXT foo" },
-	{ "NOT ( ANSWERED FLAGGED SEEN )", "(NOT (ANSWERED FLAGGED SEEN))" },
-	{ "OR NOT ANSWERED OR NOT FLAGGED NOT SEEN", "(NOT (ANSWERED FLAGGED SEEN))" }
+	{ "NOT ( ANSWERED FLAGGED SEEN )", "NOT (ANSWERED FLAGGED SEEN)" },
+	{ "OR NOT ANSWERED OR NOT FLAGGED NOT SEEN", "NOT (ANSWERED FLAGGED SEEN)" }
 };
 
 static struct mail_search_args *


More information about the dovecot-cvs mailing list