dovecot-2.2: lib-storage: mail_search_args_simplify() handles no...

dovecot at dovecot.org dovecot at dovecot.org
Thu Apr 23 18:02:19 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/b2c20d9ff296
changeset: 18464:b2c20d9ff296
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Apr 23 21:00:43 2015 +0300
description:
lib-storage: mail_search_args_simplify() handles now SEARCH_SMALLER/LARGER

diffstat:

 src/lib-storage/mail-search-args-simplify.c      |  63 +++++++++++++++++++++++-
 src/lib-storage/test-mail-search-args-simplify.c |  12 ++++
 2 files changed, 73 insertions(+), 2 deletions(-)

diffs (115 lines):

diff -r f2756661f594 -r b2c20d9ff296 src/lib-storage/mail-search-args-simplify.c
--- a/src/lib-storage/mail-search-args-simplify.c	Thu Apr 23 20:50:23 2015 +0300
+++ b/src/lib-storage/mail-search-args-simplify.c	Thu Apr 23 21:00:43 2015 +0300
@@ -159,12 +159,69 @@
 	return FALSE;
 }
 
+static bool mail_search_args_merge_size(struct mail_search_simplify_ctx *ctx,
+					struct mail_search_arg *args)
+{
+	struct mail_search_arg mask;
+	struct mail_search_arg **prev_argp, *prev_arg;
+
+	mail_search_arg_get_base_mask(args, &mask);
+	prev_argp = mail_search_args_simplify_get_prev_argp(ctx, &mask);
+
+	if (*prev_argp == NULL) {
+		*prev_argp = args;
+		return FALSE;
+	}
+
+	prev_arg = *prev_argp;
+	switch (args->type) {
+	case SEARCH_SMALLER:
+		if (ctx->parent_and) {
+			if (prev_arg->value.size < args->value.size) {
+				/* prev_arg < 5 AND arg < 10 */
+			} else {
+				/* prev_arg < 10 AND arg < 5 */
+				prev_arg->value.size = args->value.size;
+			}
+		} else {
+			if (prev_arg->value.size < args->value.size) {
+				/* prev_arg < 5 OR arg < 10 */
+				prev_arg->value.size = args->value.size;
+			} else {
+				/* prev_arg < 10 OR arg < 5 */
+			}
+		}
+		return TRUE;
+	case SEARCH_LARGER:
+		if (ctx->parent_and) {
+			if (prev_arg->value.size < args->value.size) {
+				/* prev_arg >= 5 AND arg >= 10 */
+				prev_arg->value.size = args->value.size;
+			} else {
+				/* prev_arg >= 10 AND arg >= 5 */
+			}
+		} else {
+			if (prev_arg->value.size < args->value.size) {
+				/* prev_arg >= 5 OR arg >= 10 */
+			} else {
+				/* prev_arg >= 10 OR arg >= 5 */
+				prev_arg->value.size = args->value.size;
+			}
+		}
+		return TRUE;
+	default:
+		break;
+	}
+	return FALSE;
+}
+
 static bool
 mail_search_args_simplify_sub(struct mailbox *box,
 			      struct mail_search_arg *args, bool parent_and)
 {
 	struct mail_search_simplify_ctx ctx;
 	struct mail_search_arg *sub, *prev_arg = NULL;
+	bool merged;
 
 	memset(&ctx, 0, sizeof(ctx));
 	ctx.parent_and = parent_and;
@@ -210,8 +267,6 @@
 		}
 
 		/* try to merge arguments */
-		bool merged;
-
 		switch (args->type) {
 		case SEARCH_FLAGS:
 			merged = mail_search_args_merge_flags(&ctx, args);
@@ -225,6 +280,10 @@
 		case SEARCH_SINCE:
 			merged = mail_search_args_merge_time(&ctx, args);
 			break;
+		case SEARCH_SMALLER:
+		case SEARCH_LARGER:
+			merged = mail_search_args_merge_size(&ctx, args);
+			break;
 		default:
 			merged = FALSE;
 			break;
diff -r f2756661f594 -r b2c20d9ff296 src/lib-storage/test-mail-search-args-simplify.c
--- a/src/lib-storage/test-mail-search-args-simplify.c	Thu Apr 23 20:50:23 2015 +0300
+++ b/src/lib-storage/test-mail-search-args-simplify.c	Thu Apr 23 21:00:43 2015 +0300
@@ -68,6 +68,18 @@
 	{ "SINCE 03-Aug-2014 NOT SINCE 01-Aug-2014 SINCE 02-Aug-2014", "SINCE \"03-Aug-2014\" NOT SINCE \"01-Aug-2014\"" },
 	{ "SENTSINCE 03-Aug-2014 SENTSINCE 01-Aug-2014 SENTSINCE 02-Aug-2014", "SENTSINCE \"03-Aug-2014\"" },
 	{ "SENTSINCE 03-Aug-2014 SINCE 01-Aug-2014 SENTSINCE 02-Aug-2014", "SENTSINCE \"03-Aug-2014\" SINCE \"01-Aug-2014\"" },
+
+	{ "SMALLER 1 SMALLER 2", "SMALLER 1" },
+	{ "OR SMALLER 1 SMALLER 2", "SMALLER 2" },
+	{ "OR SMALLER 1 OR SMALLER 3 SMALLER 2", "SMALLER 3" },
+	{ "SMALLER 3 NOT SMALLER 1 SMALLER 2", "SMALLER 2 NOT SMALLER 1" },
+	{ "SMALLER 3 LARGER 5", "SMALLER 3 LARGER 5" }, /* this could be replaced with e.g. NOT ALL */
+	{ "OR SMALLER 3 LARGER 5", "(OR SMALLER 3 LARGER 5)" },
+
+	{ "LARGER 3 LARGER 1 LARGER 2", "LARGER 3" },
+	{ "OR LARGER 1 LARGER 2", "LARGER 1" },
+	{ "OR LARGER 1 OR LARGER 3 LARGER 2", "LARGER 1" },
+	{ "LARGER 3 NOT LARGER 1 LARGER 2", "LARGER 3 NOT LARGER 1" }
 };
 
 static struct mail_search_args *


More information about the dovecot-cvs mailing list