]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Don't cache Date: header if we don't really want it.
authorTimo Sirainen <tss@iki.fi>
Mon, 23 Mar 2009 21:40:32 +0000 (17:40 -0400)
committerTimo Sirainen <tss@iki.fi>
Mon, 23 Mar 2009 21:40:32 +0000 (17:40 -0400)
--HG--
branch : HEAD

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

index cbf39a6c5aa41b734711775bf3461cac03f9545b..d74aa78e8560aa772f77c91a52cf6aa85cf56f6d 100644 (file)
@@ -142,16 +142,20 @@ static void index_mail_parse_header_finish(struct index_mail *mail)
                        index_mail_cache_add_idx(mail, match_idx, NULL, 0);
                }
        }
+
+       mail->data.dont_cache_field_idx = -1UL;
 }
 
 static unsigned int
-get_header_field_idx(struct index_mailbox *ibox, const char *field)
+get_header_field_idx(struct index_mailbox *ibox, const char *field,
+                    enum mail_cache_decision_type decision)
 {
        struct mail_cache_field header_field = {
                NULL, 0, MAIL_CACHE_FIELD_HEADER, 0,
-               MAIL_CACHE_DECISION_TEMP
+               MAIL_CACHE_DECISION_NO
        };
 
+       header_field.decision = decision;
        T_BEGIN {
                header_field.name = t_strconcat("hdr.", field, NULL);
                mail_cache_register_fields(ibox->cache, &header_field, 1);
@@ -196,7 +200,8 @@ void index_mail_parse_header_init(struct index_mail *mail,
 {
        struct index_header_lookup_ctx *headers =
                (struct index_header_lookup_ctx *)_headers;
-       unsigned int i;
+       const uint8_t *match;
+       unsigned int i, field_idx, match_count;
 
        mail->header_seq = mail->data.seq;
        if (mail->header_data == NULL) {
@@ -235,17 +240,28 @@ void index_mail_parse_header_init(struct index_mail *mail,
                }
        }
 
-       if ((mail->data.cache_fetch_fields & MAIL_FETCH_DATE) != 0 ||
-           mail->data.save_sent_date) {
-               array_idx_set(&mail->header_match,
-                             get_header_field_idx(mail->ibox, "Date"),
-                             &mail->header_match_value);
-       }
-
        /* register also all the other headers that exist in cache file */
        T_BEGIN {
                index_mail_parse_header_register_all_wanted(mail);
        } T_END;
+
+       /* if we want sent date, it doesn't mean that we also want to cache
+          Date: header. if we have Date field's index set at this point we
+          know that we want it. otherwise add it and remember that we don't
+          want it cached. */
+       field_idx = get_header_field_idx(mail->ibox, "Date",
+                                        MAIL_CACHE_DECISION_NO);
+       match = array_get(&mail->header_match, &match_count);
+       if (field_idx < match_count &&
+           match[field_idx] == mail->header_match_value) {
+               /* cache Date: header */
+       } else if ((mail->data.cache_fetch_fields & MAIL_FETCH_DATE) != 0 ||
+                  mail->data.save_sent_date) {
+               /* parse Date: header, but don't cache it. */
+               mail->data.dont_cache_field_idx = field_idx;
+               array_idx_set(&mail->header_match, field_idx,
+                             &mail->header_match_value);
+       }
 }
 
 static void index_mail_parse_finish_imap_envelope(struct index_mail *mail)
@@ -591,7 +607,8 @@ index_mail_get_raw_headers(struct index_mail *mail, const char *field,
 
        i_assert(field != NULL);
 
-       field_idx = get_header_field_idx(mail->ibox, field);
+       field_idx = get_header_field_idx(mail->ibox, field,
+                                        MAIL_CACHE_DECISION_TEMP);
 
        dest = str_new(mail->data_pool, 128);
        if (mail_cache_lookup_headers(mail->trans->cache_view, dest,
index 1c0487ffd71f827f3bca7afaf5ab79d5cf635412..dfc6855f3b7b5bd7876f3d8537984f0a30ea0f49 100644 (file)
@@ -428,7 +428,8 @@ void index_mail_cache_add_idx(struct index_mail *mail, unsigned int field_idx,
                        return;
        }
 
-       if (!mail->data.no_caching) {
+       if (!mail->data.no_caching &&
+           mail->data.dont_cache_field_idx != field_idx) {
                mail_cache_add(mail->trans->cache_trans, mail->data.seq,
                               field_idx, data, data_size);
        }
@@ -1138,6 +1139,7 @@ static void index_mail_reset(struct index_mail *mail)
        data->save_date = (time_t)-1;
        data->received_date = (time_t)-1;
        data->sent_date.time = (uint32_t)-1;
+       data->dont_cache_field_idx = -1UL;
 
        mail->mail.mail.seq = 0;
        mail->mail.mail.uid = 0;
index d63cc9d8ce21954d1320548dee9d635855ac5490..896e9a95dcaad27d6f54ba5dc33a8442f7a020df 100644 (file)
@@ -86,6 +86,7 @@ struct index_mail_data {
        enum index_mail_access_part access_part;
        /* dont_cache_fields overrides cache_fields */
        enum mail_fetch_field cache_fetch_fields, dont_cache_fetch_fields;
+       unsigned int dont_cache_field_idx;
 
        struct istream *stream, *filter_stream;
        struct message_size hdr_size, body_size;