]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add mailbox_search_mail_detach()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 28 Feb 2019 13:10:59 +0000 (15:10 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 26 Mar 2019 10:58:00 +0000 (10:58 +0000)
This allows keeping the struct mail open even after the mail_search_context
that created it is freed.

src/lib-storage/mail-storage.c
src/lib-storage/mail-storage.h

index 351b5cd9ac940684dfab5bfca1351a4bbc1c473c..5d17615846212aaf83fd0508f2c1d198bdae9cd5 100644 (file)
@@ -2182,6 +2182,24 @@ bool mailbox_search_seen_lost_data(struct mail_search_context *ctx)
        return ctx->seen_lost_data;
 }
 
+void mailbox_search_mail_detach(struct mail_search_context *ctx,
+                               struct mail *mail)
+{
+       struct mail_private *pmail =
+               container_of(mail, struct mail_private, mail);
+       struct mail *const *mailp;
+
+       array_foreach(&ctx->mails, mailp) {
+               if (*mailp == mail) {
+                       pmail->search_mail = FALSE;
+                       array_delete(&ctx->mails,
+                                    array_foreach_idx(&ctx->mails, mailp), 1);
+                       return;
+               }
+       }
+       i_unreached();
+}
+
 int mailbox_search_result_build(struct mailbox_transaction_context *t,
                                struct mail_search_args *args,
                                enum mailbox_search_result_flags flags,
index 278fb71a0efa7c243e93c5427557a64953372086..72f4a6c1ea30c5df7e8b2395fd3252621d34c3bf 100644 (file)
@@ -724,6 +724,10 @@ bool mailbox_search_next_nonblock(struct mail_search_context *ctx,
    determine correctly if those messages should have been returned in this
    search. */
 bool mailbox_search_seen_lost_data(struct mail_search_context *ctx);
+/* Detach the given mail from the search context. This allows the mail to live
+   even after mail_search_context has been freed. */
+void mailbox_search_mail_detach(struct mail_search_context *ctx,
+                               struct mail *mail);
 
 /* Remember the search result for future use. This must be called before the
    first mailbox_search_next*() call. */