]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Move code to a new mailbox_header_lookup_merge()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 27 Apr 2018 10:49:53 +0000 (13:49 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 May 2019 06:43:19 +0000 (06:43 +0000)
src/lib-storage/index/index-mail.c
src/lib-storage/mail-storage.h
src/lib-storage/mailbox-header.c

index 31806030c26c4df992b77e86cd439801392d6079..be7ad87c0a741a6a567470eba240573e2be83b95 100644 (file)
@@ -2074,8 +2074,6 @@ void index_mail_add_temp_wanted_fields(struct mail *_mail,
        struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        struct mailbox_header_lookup_ctx *new_wanted_headers;
-       ARRAY_TYPE(const_string) names;
-       unsigned int i;
 
        data->wanted_fields |= fields;
        if (headers == NULL) {
@@ -2085,18 +2083,9 @@ void index_mail_add_temp_wanted_fields(struct mail *_mail,
                mailbox_header_lookup_ref(headers);
        } else {
                /* merge headers */
-               t_array_init(&names, 32);
-               for (i = 0; i < data->wanted_headers->count; i++)
-                       array_push_back(&names,
-                                       &data->wanted_headers->name[i]);
-               for (i = 0; i < headers->count; i++)
-                       array_push_back(&names, &headers->name[i]);
-               array_append_zero(&names);
-               new_wanted_headers =
-                       mailbox_header_lookup_init(_mail->box,
-                                                  array_front(&names));
-               if (data->wanted_headers != NULL)
-                       mailbox_header_lookup_unref(&data->wanted_headers);
+               new_wanted_headers = mailbox_header_lookup_merge(data->wanted_headers,
+                                                                headers);
+               mailbox_header_lookup_unref(&data->wanted_headers);
                data->wanted_headers = new_wanted_headers;
        }
        index_mail_update_access_parts_pre(_mail);
index bb8b2843383c1cf2f484d3e65e8122eab71907b8..157eba9348e398b6d6a4a77bb7fc2ca586693567 100644 (file)
@@ -702,6 +702,10 @@ struct mailbox_header_lookup_ctx *
 mailbox_header_lookup_init(struct mailbox *box, const char *const headers[]);
 void mailbox_header_lookup_ref(struct mailbox_header_lookup_ctx *ctx);
 void mailbox_header_lookup_unref(struct mailbox_header_lookup_ctx **ctx);
+/* Merge two header lookups. */
+struct mailbox_header_lookup_ctx *
+mailbox_header_lookup_merge(const struct mailbox_header_lookup_ctx *hdr1,
+                           const struct mailbox_header_lookup_ctx *hdr2);
 
 /* Initialize new search request. If sort_program is non-NULL, the messages are
    returned in the requested order, otherwise from first to last. */
index 2d6c12354459a8e9ad78a5e419bc1d512a68cc57..312e7ddd67ea2b8463eb42b6552de6eb022ff3a0 100644 (file)
@@ -93,3 +93,21 @@ void mailbox_header_lookup_unref(struct mailbox_header_lookup_ctx **_ctx)
 
        pool_unref(&ctx->pool);
 }
+
+struct mailbox_header_lookup_ctx *
+mailbox_header_lookup_merge(const struct mailbox_header_lookup_ctx *hdr1,
+                           const struct mailbox_header_lookup_ctx *hdr2)
+{
+       ARRAY_TYPE(const_string) names;
+       unsigned int i;
+
+       i_assert(hdr1->box == hdr2->box);
+
+       t_array_init(&names, 32);
+       for (i = 0; i < hdr1->count; i++)
+               array_push_back(&names, &hdr1->name[i]);
+       for (i = 0; i < hdr2->count; i++)
+               array_push_back(&names, &hdr2->name[i]);
+       array_append_zero(&names);
+       return mailbox_header_lookup_init(hdr1->box, array_front(&names));
+}