]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add mail_storage.nonbody_access_fields
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 24 Apr 2017 10:27:43 +0000 (13:27 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 24 Apr 2017 11:15:38 +0000 (14:15 +0300)
This avoids index_mail_update_access_parts_pre() from opening the mail
stream unnecessarily for fields that can be looked up via other methods
by the storage.

src/lib-storage/index/index-mail.c
src/lib-storage/mail-storage-private.h

index b6c86b47cac6dd85cbaae91b43b53ce8566cc6f5..836567687d468821d88761aea3b5c97b79fa451e 100644 (file)
@@ -1733,6 +1733,7 @@ void index_mail_update_access_parts_pre(struct mail *_mail)
 {
        struct index_mail *mail = (struct index_mail *)_mail;
        struct index_mail_data *data = &mail->data;
+       struct mail_storage *storage = _mail->box->storage;
        const struct mail_cache_field *cache_fields = mail->ibox->cache_fields;
        struct mail_cache_view *cache_view = _mail->transaction->cache_view;
 
@@ -1763,6 +1764,7 @@ void index_mail_update_access_parts_pre(struct mail *_mail)
        /* see if wanted_fields can tell us if we need to read/parse
           header/body */
        if ((data->wanted_fields & MAIL_FETCH_MESSAGE_PARTS) != 0 &&
+           (storage->nonbody_access_fields & MAIL_FETCH_MESSAGE_PARTS) == 0 &&
            data->parts == NULL) {
                const unsigned int cache_field =
                        cache_fields[MAIL_CACHE_MESSAGE_PARTS].idx;
@@ -1775,11 +1777,13 @@ void index_mail_update_access_parts_pre(struct mail *_mail)
        }
 
        if ((data->wanted_fields & MAIL_FETCH_IMAP_ENVELOPE) != 0 &&
+           (storage->nonbody_access_fields & MAIL_FETCH_IMAP_ENVELOPE) == 0 &&
            data->envelope == NULL)
                check_envelope(mail);
 
        if ((data->wanted_fields & MAIL_FETCH_IMAP_BODY) != 0 &&
            (data->cache_flags & MAIL_CACHE_FLAG_TEXT_PLAIN_7BIT_ASCII) == 0 &&
+           (storage->nonbody_access_fields & MAIL_FETCH_IMAP_BODY) == 0 &&
            data->body == NULL) {
                /* we need either imap.body or imap.bodystructure */
                const unsigned int cache_field1 =
@@ -1799,6 +1803,7 @@ void index_mail_update_access_parts_pre(struct mail *_mail)
 
        if ((data->wanted_fields & MAIL_FETCH_IMAP_BODYSTRUCTURE) != 0 &&
            (data->cache_flags & MAIL_CACHE_FLAG_TEXT_PLAIN_7BIT_ASCII) == 0 &&
+           (storage->nonbody_access_fields & MAIL_FETCH_IMAP_BODYSTRUCTURE) == 0 &&
            data->bodystructure == NULL) {
                const unsigned int cache_field =
                        cache_fields[MAIL_CACHE_IMAP_BODYSTRUCTURE].idx;
@@ -1812,6 +1817,7 @@ void index_mail_update_access_parts_pre(struct mail *_mail)
        }
 
        if ((data->wanted_fields & MAIL_FETCH_DATE) != 0 &&
+           (storage->nonbody_access_fields & MAIL_FETCH_DATE) == 0 &&
            data->sent_date.time == (uint32_t)-1) {
                const unsigned int cache_field =
                        cache_fields[MAIL_CACHE_SENT_DATE].idx;
@@ -1822,7 +1828,8 @@ void index_mail_update_access_parts_pre(struct mail *_mail)
                        data->save_sent_date = TRUE;
                }
        }
-       if ((data->wanted_fields & MAIL_FETCH_BODY_SNIPPET) != 0) {
+       if ((data->wanted_fields & MAIL_FETCH_BODY_SNIPPET) != 0 &&
+           (storage->nonbody_access_fields & MAIL_FETCH_BODY_SNIPPET) == 0) {
                const unsigned int cache_field =
                        cache_fields[MAIL_CACHE_BODY_SNIPPET].idx;
 
index d886f44597ca5ffa79653e018759d6196f625554..8903c5de9db861200b9a04bc07d0a347346e039b 100644 (file)
@@ -110,6 +110,11 @@ struct mail_storage_error {
 struct mail_storage {
        const char *name;
        enum mail_storage_class_flags class_flags;
+       /* Fields that the storage backend can get by other means than parsing
+          the message header/body. For example the imapc backend can lookup
+          MAIL_FETCH_IMAP_BODYSTRUCTURE from the remote server. Adding fields
+          here avoids adding them to index_mail_data.access_part. */
+       enum mail_fetch_field nonbody_access_fields;
 
         struct mail_storage_vfuncs v, *vlast;