]> 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)
committerMartti Rannanjärvi <martti.rannanjarvi@open-xchange.com>
Wed, 25 Sep 2019 08:25:20 +0000 (11:25 +0300)
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 324ee6b7c998bc78d9ce81d35f9470a9a67a5913..920a705f24545df65943d428951036ff716932a4 100644 (file)
@@ -2185,6 +2185,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 1d4f88f6488ea03d3bcd9c55353daf4b73cb9368..2fb36acdb91bb4b8039a3d2865293107b1803e57 100644 (file)
@@ -733,6 +733,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. */