Skip to content

Commit

Permalink
imapc: Fix prefetching specific headers
Browse files Browse the repository at this point in the history
FETCH BODY[HEADER.FIELDS ...] shouldn't be used if imapc_features doesn't
include fetch-headers. Also neither this nor BODY[HEADER] should be sent
if we already have header/body stream.
  • Loading branch information
sirainen authored and villesavolainen committed Jun 16, 2017
1 parent 51937e0 commit f288c57
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/lib-storage/index/imapc/imapc-mail-fetch.c
Expand Up @@ -214,6 +214,9 @@ imapc_mail_send_fetch(struct mail *_mail, enum mail_fetch_field fields,
uint32_t seq;
unsigned int i;

i_assert(headers == NULL ||
IMAPC_BOX_HAS_FEATURE(mbox, IMAPC_FEATURE_FETCH_HEADERS));

if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
mail_set_aborted(_mail);
return -1;
Expand Down Expand Up @@ -374,19 +377,25 @@ bool imapc_mail_prefetch(struct mail *_mail)
struct imapc_mailbox *mbox = (struct imapc_mailbox *)_mail->box;
struct index_mail_data *data = &mail->imail.data;
enum mail_fetch_field fields;
const char *const *headers = NULL;

if (mbox->prev_mail_cache.uid == _mail->uid)
imapc_mail_cache_get(mail, &mbox->prev_mail_cache);
/* try to get as much from cache as possible */
imapc_mail_update_access_parts(&mail->imail);

fields = imapc_mail_get_wanted_fetch_fields(mail);
if (fields != 0 ||
(data->wanted_headers != NULL &&
!imapc_mail_has_headers_in_cache(&mail->imail, data->wanted_headers))) T_BEGIN {
if (imapc_mail_send_fetch(_mail, fields,
data->wanted_headers == NULL ? NULL :
data->wanted_headers->name) > 0)
if (data->wanted_headers != NULL && data->stream == NULL &&
(fields & MAIL_FETCH_STREAM_HEADER) == 0 &&
!imapc_mail_has_headers_in_cache(&mail->imail, data->wanted_headers)) {
/* fetch specific headers */
if (IMAPC_BOX_HAS_FEATURE(mbox, IMAPC_FEATURE_FETCH_HEADERS))
headers = data->wanted_headers->name;
else
fields |= MAIL_FETCH_STREAM_HEADER;
}
if (fields != 0 || headers != NULL) T_BEGIN {
if (imapc_mail_send_fetch(_mail, fields, headers) > 0)
mail->imail.data.prefetch_sent = TRUE;
} T_END;
return !mail->imail.data.prefetch_sent;
Expand Down

0 comments on commit f288c57

Please sign in to comment.