From: Timo Sirainen Date: Thu, 23 Apr 2015 18:00:43 +0000 (+0300) Subject: lib-storage: mail_search_args_simplify() handles now SEARCH_SMALLER/LARGER X-Git-Tag: 2.2.17.rc1~157 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5e8a76a128d4e92f0641135183c164fd5c5ce5e;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: mail_search_args_simplify() handles now SEARCH_SMALLER/LARGER --- diff --git a/src/lib-storage/mail-search-args-simplify.c b/src/lib-storage/mail-search-args-simplify.c index c14ab32756..89a5929ea2 100644 --- a/src/lib-storage/mail-search-args-simplify.c +++ b/src/lib-storage/mail-search-args-simplify.c @@ -159,12 +159,69 @@ static bool mail_search_args_merge_time(struct mail_search_simplify_ctx *ctx, 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 @@ mail_search_args_simplify_sub(struct mailbox *box, } /* try to merge arguments */ - bool merged; - switch (args->type) { case SEARCH_FLAGS: merged = mail_search_args_merge_flags(&ctx, args); @@ -225,6 +280,10 @@ mail_search_args_simplify_sub(struct mailbox *box, 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 --git a/src/lib-storage/test-mail-search-args-simplify.c b/src/lib-storage/test-mail-search-args-simplify.c index f76010d538..9613a1e51b 100644 --- a/src/lib-storage/test-mail-search-args-simplify.c +++ b/src/lib-storage/test-mail-search-args-simplify.c @@ -68,6 +68,18 @@ struct { { "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 *