From 22af18076f84b75b3fc0ecbeedee22e45bf53a60 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 27 Apr 2018 13:49:53 +0300 Subject: [PATCH] lib-storage: Move code to a new mailbox_header_lookup_merge() --- src/lib-storage/index/index-mail.c | 17 +++-------------- src/lib-storage/mail-storage.h | 4 ++++ src/lib-storage/mailbox-header.c | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/lib-storage/index/index-mail.c b/src/lib-storage/index/index-mail.c index 31806030c2..be7ad87c0a 100644 --- a/src/lib-storage/index/index-mail.c +++ b/src/lib-storage/index/index-mail.c @@ -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); diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index bb8b284338..157eba9348 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -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. */ diff --git a/src/lib-storage/mailbox-header.c b/src/lib-storage/mailbox-header.c index 2d6c123544..312e7ddd67 100644 --- a/src/lib-storage/mailbox-header.c +++ b/src/lib-storage/mailbox-header.c @@ -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)); +} -- 2.47.3