]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Added MAILBOX_GLOB search arg. Query builders now use it instead of...
authorTimo Sirainen <tss@iki.fi>
Wed, 28 Apr 2010 15:09:43 +0000 (18:09 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 28 Apr 2010 15:09:43 +0000 (18:09 +0300)
--HG--
branch : HEAD

src/lib-storage/index/index-search.c
src/lib-storage/mail-search-register-human.c
src/lib-storage/mail-search-register-imap.c
src/lib-storage/mail-search.c
src/lib-storage/mail-search.h

index 5c63ea55b15ccc08ac2f97b6045bf09fe1145d34..7f90b4c038f8def1c7a9297c5758184bc9a4d909 100644 (file)
@@ -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;
index 444d867f8c6e6291efcb9c8fc7739e76da6aa731..ffcce6ea9c5945b4814061734455dc87df38016d 100644 (file)
@@ -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[] = {
index 49a5f78af78494c2d919de95ad37ded6cc07dcff..ddb03da2d86b83a12d90014aa5ccd662c9a69d92 100644 (file)
@@ -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 */
index c93976be572397a7d9918a040b398b9b9b1ac323..ab2b2d99f4fcb6739481f5d401e42b1bb813c6f6 100644 (file)
@@ -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
index 5f489e4d3b7186f271ee402d3ef8871e1895b0d3..a7a6960cbcee49bcd8ad4dd762e67d90f5bc3ad4 100644 (file)
@@ -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