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) {
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);
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. */
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));
+}