changeset 26387:abc556a15a89

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.
author Timo Sirainen <timo.sirainen@open-xchange.com>
date Thu, 28 Feb 2019 15:10:59 +0200
parents b7e38a84822a
children 49c77f88cf94
files src/lib-storage/mail-storage.c src/lib-storage/mail-storage.h
diffstat 2 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/mail-storage.c	Thu Feb 28 15:03:22 2019 +0200
+++ b/src/lib-storage/mail-storage.c	Thu Feb 28 15:10:59 2019 +0200
@@ -2185,6 +2185,24 @@
 	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,
--- a/src/lib-storage/mail-storage.h	Thu Feb 28 15:03:22 2019 +0200
+++ b/src/lib-storage/mail-storage.h	Thu Feb 28 15:10:59 2019 +0200
@@ -733,6 +733,10 @@
    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. */