From: Timo Sirainen Date: Wed, 28 Apr 2010 15:09:43 +0000 (+0300) Subject: lib-storage: Added MAILBOX_GLOB search arg. Query builders now use it instead of... X-Git-Tag: 2.0.beta5~77 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=59e50e3e6c514cd95c85bfa0a07b24e93de1bda6;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Added MAILBOX_GLOB search arg. Query builders now use it instead of MAILBOX. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/index-search.c b/src/lib-storage/index/index-search.c index 5c63ea55b1..7f90b4c038 100644 --- a/src/lib-storage/index/index-search.c +++ b/src/lib-storage/index/index-search.c @@ -7,6 +7,7 @@ #include "utc-offset.h" #include "str.h" #include "time-util.h" +#include "imap-match.h" #include "message-address.h" #include "message-date.h" #include "message-search.h" @@ -285,6 +286,11 @@ static int search_arg_match_cached(struct index_search_context *ctx, if (strcasecmp(str, "INBOX") == 0) return strcasecmp(arg->value.str, "INBOX") == 0; return strcmp(str, arg->value.str) == 0; + case SEARCH_MAILBOX_GLOB: + if (mail_get_special(ctx->mail, MAIL_FETCH_MAILBOX_NAME, + &str) < 0) + return -1; + return imap_match(arg->value.mailbox_glob, str) == IMAP_MATCH_YES; default: return -1; } @@ -1176,6 +1182,7 @@ static bool search_arg_is_static(struct mail_search_arg *arg) case SEARCH_TEXT_FAST: case SEARCH_GUID: case SEARCH_MAILBOX: + case SEARCH_MAILBOX_GLOB: return TRUE; } return FALSE; diff --git a/src/lib-storage/mail-search-register-human.c b/src/lib-storage/mail-search-register-human.c index 444d867f8c..ffcce6ea9c 100644 --- a/src/lib-storage/mail-search-register-human.c +++ b/src/lib-storage/mail-search-register-human.c @@ -128,7 +128,7 @@ human_search_guid(struct mail_search_build_context *ctx) static struct mail_search_arg * human_search_mailbox(struct mail_search_build_context *ctx) { - return mail_search_build_str(ctx, SEARCH_MAILBOX); + return mail_search_build_str(ctx, SEARCH_MAILBOX_GLOB); } static const struct mail_search_register_arg human_register_args[] = { diff --git a/src/lib-storage/mail-search-register-imap.c b/src/lib-storage/mail-search-register-imap.c index 49a5f78af7..ddb03da2d8 100644 --- a/src/lib-storage/mail-search-register-imap.c +++ b/src/lib-storage/mail-search-register-imap.c @@ -426,7 +426,7 @@ imap_search_inthread(struct mail_search_build_context *ctx) } CALLBACK_STR(x_guid, SEARCH_GUID); -CALLBACK_STR(x_mailbox, SEARCH_MAILBOX); +CALLBACK_STR(x_mailbox, SEARCH_MAILBOX_GLOB); const struct mail_search_register_arg imap_register_args[] = { /* argument set operations */ diff --git a/src/lib-storage/mail-search.c b/src/lib-storage/mail-search.c index c93976be57..ab2b2d99f4 100644 --- a/src/lib-storage/mail-search.c +++ b/src/lib-storage/mail-search.c @@ -2,9 +2,10 @@ #include "lib.h" #include "array.h" -#include "buffer.h" +#include "imap-match.h" #include "mail-index.h" #include "mail-storage.h" +#include "mail-namespace.h" #include "mail-search-build.h" #include "mail-search.h" @@ -92,6 +93,15 @@ mail_search_args_init_sub(struct mail_search_args *args, keywords); break; + case SEARCH_MAILBOX_GLOB: { + struct mail_namespace *ns = + mailbox_get_namespace(args->box); + + arg->value.mailbox_glob = + imap_match_init(default_pool, arg->value.str, + TRUE, ns->sep); + break; + } case SEARCH_INTHREAD: thread_args = arg->value.search_args; if (thread_args == NULL) { @@ -150,6 +160,12 @@ static void mail_search_args_deinit_sub(struct mail_search_args *args, break; mailbox_keywords_unref(args->box, &arg->value.keywords); break; + case SEARCH_MAILBOX_GLOB: + if (arg->value.mailbox_glob == NULL) + break; + + imap_match_deinit(&arg->value.mailbox_glob); + break; case SEARCH_INTHREAD: i_assert(arg->value.search_args->refcount > 0); if (args->refcount == 0 && @@ -296,9 +312,9 @@ mail_search_arg_dup_one(pool_t pool, const struct mail_search_arg *arg) case SEARCH_TEXT_FAST: case SEARCH_GUID: case SEARCH_MAILBOX: + case SEARCH_MAILBOX_GLOB: new_arg->value.str = p_strdup(pool, arg->value.str); break; - case SEARCH_MODSEQ: new_arg->value.modseq = p_new(pool, struct mail_search_modseq, 1); @@ -770,6 +786,7 @@ static bool mail_search_arg_one_equals(const struct mail_search_arg *arg1, case SEARCH_TEXT_FAST: case SEARCH_GUID: case SEARCH_MAILBOX: + case SEARCH_MAILBOX_GLOB: /* don't bother doing case-insensitive comparison. it must not be done for guid/mailbox, and for others we should support full i18n case-insensitivity (or the active comparator diff --git a/src/lib-storage/mail-search.h b/src/lib-storage/mail-search.h index 5f489e4d3b..a7a6960cbc 100644 --- a/src/lib-storage/mail-search.h +++ b/src/lib-storage/mail-search.h @@ -42,7 +42,8 @@ enum mail_search_arg_type { SEARCH_MODSEQ, SEARCH_INTHREAD, SEARCH_GUID, - SEARCH_MAILBOX + SEARCH_MAILBOX, + SEARCH_MAILBOX_GLOB }; enum mail_search_date_type { @@ -86,6 +87,7 @@ struct mail_search_arg { struct mail_search_modseq *modseq; struct mail_search_args *search_args; struct mail_search_result *search_result; + struct imap_match_glob *mailbox_glob; } value; void *context; @@ -166,7 +168,8 @@ const char *const * mail_search_args_analyze(struct mail_search_arg *args, bool *have_headers, bool *have_body); -/* Simplify/optimize search arguments */ +/* Simplify/optimize search arguments. Afterwards all OR/SUB args are + guaranteed to have not=FALSE. */ void mail_search_args_simplify(struct mail_search_args *args); #endif