From: Timo Sirainen Date: Thu, 28 Feb 2019 13:10:59 +0000 (+0200) Subject: lib-storage: Add mailbox_search_mail_detach() X-Git-Tag: 2.3.8~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bc48c0722853d53b6952fa136c14aeef934046eb;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Add mailbox_search_mail_detach() This allows keeping the struct mail open even after the mail_search_context that created it is freed. --- diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 324ee6b7c9..920a705f24 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -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, diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index 1d4f88f648..2fb36acdb9 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -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. */