]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Move search matching into mailbox_vfuncs.search_next_match_mail()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 14 Oct 2021 14:33:30 +0000 (17:33 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 28 Oct 2021 17:50:10 +0000 (17:50 +0000)
13 files changed:
src/lib-storage/fail-mailbox.c
src/lib-storage/index/dbox-multi/mdbox-deleted-storage.c
src/lib-storage/index/dbox-multi/mdbox-storage.c
src/lib-storage/index/dbox-single/sdbox-storage.c
src/lib-storage/index/imapc/imapc-storage.c
src/lib-storage/index/index-search.c
src/lib-storage/index/index-storage.h
src/lib-storage/index/maildir/maildir-storage.c
src/lib-storage/index/mbox/mbox-storage.c
src/lib-storage/index/pop3c/pop3c-storage.c
src/lib-storage/index/raw/raw-storage.c
src/lib-storage/mail-storage-private.h
src/plugins/virtual/virtual-storage.c

index 3c4ea91a668b1627310c842538dc7bbfa4102479..7925c9369279da52e36551ff467ef6873c460011 100644 (file)
@@ -211,6 +211,13 @@ fail_mailbox_search_next_update_seq(struct mail_search_context *ctx ATTR_UNUSED)
        return FALSE;
 }
 
+static int
+fail_mailbox_search_next_match_mail(struct mail_search_context *ctx ATTR_UNUSED,
+                                   struct mail *mail ATTR_UNUSED)
+{
+       return -1;
+}
+
 static struct mail_save_context *
 fail_mailbox_save_alloc(struct mailbox_transaction_context *t)
 {
@@ -293,6 +300,7 @@ struct mailbox fail_mailbox = {
                fail_mailbox_search_deinit,
                fail_mailbox_search_next_nonblock,
                fail_mailbox_search_next_update_seq,
+               fail_mailbox_search_next_match_mail,
                fail_mailbox_save_alloc,
                fail_mailbox_save_begin,
                fail_mailbox_save_continue,
index b3ffe3e5c8c34d4232acb3496e0ff6cfcca0e68e..4fdf1ab2cf3b71c6407a7a6002d571f48bbfcd07 100644 (file)
@@ -294,6 +294,7 @@ struct mailbox mdbox_deleted_mailbox = {
                index_storage_search_deinit,
                index_storage_search_next_nonblock,
                index_storage_search_next_update_seq,
+               index_storage_search_next_match_mail,
                mdbox_deleted_save_alloc,
                mdbox_deleted_save_begin,
                mdbox_deleted_save_continue,
index eff2a27cc4794b21a59732a0e09346d69e48b74e..e7e7f600e500597c1b61e0b6b674abfc09358b6e 100644 (file)
@@ -505,6 +505,7 @@ struct mailbox mdbox_mailbox = {
                index_storage_search_deinit,
                index_storage_search_next_nonblock,
                index_storage_search_next_update_seq,
+               index_storage_search_next_match_mail,
                mdbox_save_alloc,
                mdbox_save_begin,
                dbox_save_continue,
index e43421cb59ed0826aa3e49f232954f4ebb28342e..5a6fcaddec005a6fd297e3e671caf67a03e9cfaa 100644 (file)
@@ -509,6 +509,7 @@ struct mailbox sdbox_mailbox = {
                index_storage_search_deinit,
                index_storage_search_next_nonblock,
                index_storage_search_next_update_seq,
+               index_storage_search_next_match_mail,
                sdbox_save_alloc,
                sdbox_save_begin,
                dbox_save_continue,
index 71d9bb768df59980ac7a27a719f3b2f48c1ab330..49bf78f7e48d243d0965208800ef22fbcaa59d7e 100644 (file)
@@ -1307,6 +1307,7 @@ struct mailbox imapc_mailbox = {
                imapc_search_deinit,
                index_storage_search_next_nonblock,
                imapc_search_next_update_seq,
+               index_storage_search_next_match_mail,
                imapc_save_alloc,
                imapc_save_begin,
                imapc_save_continue,
index 1e1caaefe900b8eebc34d8009f5b02416fb18e34..ab20efaeafa9091c34e85060ebca0db9c92a319a 100644 (file)
@@ -1601,14 +1601,61 @@ static bool search_would_block(struct index_search_context *ctx)
        return ret;
 }
 
+int index_storage_search_next_match_mail(struct mail_search_context *_ctx,
+                                        struct mail *mail)
+{
+       struct index_search_context *ctx =
+               container_of(_ctx, struct index_search_context, mail_ctx);
+       struct index_mail *imail = INDEX_MAIL(mail);
+       int match;
+
+       ctx->cur_mail = mail;
+       /* mail's access_type is SEARCH only while using it to process
+          the search query. afterwards the mail can still be accessed
+          for fetching. */
+       ctx->cur_mail->access_type = MAIL_ACCESS_TYPE_SEARCH;
+       T_BEGIN {
+               match = search_match_next(ctx);
+       } T_END;
+       ctx->cur_mail->access_type = MAIL_ACCESS_TYPE_DEFAULT;
+       ctx->cur_mail = NULL;
+
+       i_assert(imail->data.search_results == NULL);
+       if (match < 0) {
+               /* result isn't known yet, do a prefetch and
+                  finish later */
+               imail->data.search_results =
+                       buffer_create_dynamic(imail->mail.data_pool, 64);
+               mail_search_args_result_serialize(_ctx->args,
+                                                 imail->data.search_results);
+       }
+
+       mail_search_args_reset(_ctx->args->args, FALSE);
+
+       if (match != 0) {
+               /* either matched or result is still unknown.
+                  anyway we're far enough now that we probably want
+                  to update the access_parts. the only problem here is
+                  if searching would want fewer access_parts than the
+                  fetching part, but that's probably not a big problem
+                  usually. */
+               index_mail_update_access_parts_pre(mail);
+               return 1;
+       }
+
+       /* non-match */
+       if (_ctx->args->stop_on_nonmatch)
+               return -1;
+       return 0;
+}
+
 static int search_more_with_mail(struct index_search_context *ctx,
                                 struct mail *mail)
 {
        struct mail_search_context *_ctx = &ctx->mail_ctx;
        struct mailbox *box = _ctx->transaction->box;
-       struct index_mail *imail = INDEX_MAIL(mail);
        unsigned long long cost1, cost2;
-       int match, ret;
+       int ret;
 
        if (search_would_block(ctx)) {
                /* this lookup is useful when a large number of
@@ -1627,55 +1674,17 @@ static int search_more_with_mail(struct index_search_context *ctx,
        while (box->v.search_next_update_seq(_ctx)) {
                mail_set_seq(mail, _ctx->seq);
 
-               ctx->cur_mail = mail;
-               /* mail's access_type is SEARCH only while using it to process
-                  the search query. afterwards the mail can still be accessed
-                  for fetching. */
-               ctx->cur_mail->access_type = MAIL_ACCESS_TYPE_SEARCH;
-               T_BEGIN {
-                       match = search_match_next(ctx);
-               } T_END;
-               ctx->cur_mail->access_type = MAIL_ACCESS_TYPE_DEFAULT;
-               ctx->cur_mail = NULL;
-
-               i_assert(imail->data.search_results == NULL);
-               if (match < 0) {
-                       /* result isn't known yet, do a prefetch and
-                          finish later */
-                       imail->data.search_results =
-                               buffer_create_dynamic(imail->mail.data_pool, 64);
-                       mail_search_args_result_serialize(_ctx->args,
-                               imail->data.search_results);
-               }
-
-               mail_search_args_reset(_ctx->args->args, FALSE);
-
-               if (match != 0) {
-                       /* either matched or result is still unknown.
-                          anyway we're far enough now that we probably want
-                          to update the access_parts. the only problem here is
-                          if searching would want fewer access_parts than the
-                          fetching part, but that's probably not a big problem
-                          usually. */
-                       index_mail_update_access_parts_pre(mail);
-                       ret = 1;
-                       break;
-               }
-
-               /* non-match */
-               if (_ctx->args->stop_on_nonmatch) {
-                       ret = -1;
+               ret = box->v.search_next_match_mail(_ctx, mail);
+               if (ret != 0)
                        break;
-               }
 
                cost2 = search_get_cost(mail->transaction);
                ctx->cost += cost2 - cost1;
                cost1 = cost2;
 
-               if (search_would_block(ctx)) {
-                       ret = 0;
+               if (search_would_block(ctx))
                        break;
-               }
+               ret = -1;
        }
        cost2 = search_get_cost(mail->transaction);
        ctx->cost += cost2 - cost1;
index dd26b3d3723bc8219694e2240667918acf9846d2..43e7d24d6f99a4506dc3fbc76b63c8f6ed153bf3 100644 (file)
@@ -142,6 +142,8 @@ int index_storage_search_deinit(struct mail_search_context *ctx);
 bool index_storage_search_next_nonblock(struct mail_search_context *ctx,
                                        struct mail **mail_r, bool *tryagain_r);
 bool index_storage_search_next_update_seq(struct mail_search_context *ctx);
+int index_storage_search_next_match_mail(struct mail_search_context *ctx,
+                                        struct mail *mail);
 
 struct mailbox_transaction_context *
 index_transaction_begin(struct mailbox *box,
index f9c5a80cdc07429fba89ddd0a5c076ba3daafd67..e65579ff1f8252a86b94ff6702442b8c41f8449c 100644 (file)
@@ -734,6 +734,7 @@ struct mailbox maildir_mailbox = {
                index_storage_search_deinit,
                index_storage_search_next_nonblock,
                index_storage_search_next_update_seq,
+               index_storage_search_next_match_mail,
                maildir_save_alloc,
                maildir_save_begin,
                maildir_save_continue,
index 2e8eae4b70d9121990a006a9cd9df7cdcd879ceb..4b2bb359f9b0f79e51e541f1b8211c09bf0abfa0 100644 (file)
@@ -896,6 +896,7 @@ struct mailbox mbox_mailbox = {
                index_storage_search_deinit,
                index_storage_search_next_nonblock,
                index_storage_search_next_update_seq,
+               index_storage_search_next_match_mail,
                mbox_save_alloc,
                mbox_save_begin,
                mbox_save_continue,
index e6e3d1dcc4fb3f5abe3f9309198e7b5136e9ff97..f7846836e8b1a05c6c4aa9f6d73f99b0d93f5ce5 100644 (file)
@@ -353,6 +353,7 @@ struct mailbox pop3c_mailbox = {
                index_storage_search_deinit,
                index_storage_search_next_nonblock,
                index_storage_search_next_update_seq,
+               index_storage_search_next_match_mail,
                pop3c_save_alloc,
                pop3c_save_begin,
                pop3c_save_continue,
index cb95fdaa2eec271e80135ba25a80508f7b107a81..32883635c54359bab9f840b02032c6eed20f1dd1 100644 (file)
@@ -254,6 +254,7 @@ struct mailbox raw_mailbox = {
                index_storage_search_deinit,
                index_storage_search_next_nonblock,
                index_storage_search_next_update_seq,
+               index_storage_search_next_match_mail,
                NULL,
                NULL,
                NULL,
index 9537a5b6dea60678328a1dd4db39f1c3e3701940..8a419030a042df0b4e6a75b54b5ac7f98de5009b 100644 (file)
@@ -312,6 +312,8 @@ struct mailbox_vfuncs {
                                     struct mail **mail_r, bool *tryagain_r);
        /* Internal search function which updates ctx->seq */
        bool (*search_next_update_seq)(struct mail_search_context *ctx);
+       int (*search_next_match_mail)(struct mail_search_context *ctx,
+                                     struct mail *mail);
 
        struct mail_save_context *
                (*save_alloc)(struct mailbox_transaction_context *t);
index a0779cc186da3a8ab460c3e27c031b558b6e6ece..a57f4f4151cc7fba6f4ff4d6a1165ea2ba5ee65e 100644 (file)
@@ -927,6 +927,7 @@ struct mailbox virtual_mailbox = {
                virtual_search_deinit,
                virtual_search_next_nonblock,
                virtual_search_next_update_seq,
+               index_storage_search_next_match_mail,
                virtual_save_alloc,
                virtual_save_begin,
                virtual_save_continue,