]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Headers were sometimes added to dovecot.index.cache with wrong line...
authorTimo Sirainen <tss@iki.fi>
Wed, 24 Sep 2014 21:42:56 +0000 (00:42 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 24 Sep 2014 21:42:56 +0000 (00:42 +0300)
This happened if the header parsing was done multiple times for the same
mail. The end result being that when fetching multiple headers as a stream,
the headers could have been returned in the wrong order. This messed up at
least dsync's header hash comparisons.

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

index 7ce4bfce49a93c07527c8ea709de032a32d2bf76..3bc3fd816179689ba21660a2caecdae5644f5447 100644 (file)
@@ -130,6 +130,7 @@ static void index_mail_parse_header_finish(struct index_mail *mail)
        }
 
        mail->data.dont_cache_field_idx = UINT_MAX;
+       mail->data.header_parser_initialized = FALSE;
 }
 
 static unsigned int
@@ -247,6 +248,9 @@ void index_mail_parse_header_init(struct index_mail *mail,
                array_idx_set(&mail->header_match, field_idx,
                              &mail->header_match_value);
        }
+       mail->data.header_parser_initialized = TRUE;
+       mail->data.parse_line_num = 0;
+       memset(&mail->data.parse_line, 0, sizeof(mail->data.parse_line));
 }
 
 static void index_mail_parse_finish_imap_envelope(struct index_mail *mail)
@@ -276,6 +280,8 @@ void index_mail_parse_header(struct message_part *part,
        unsigned int field_idx, count;
        uint8_t *match;
 
+       i_assert(data->header_parser_initialized);
+
         data->parse_line_num++;
 
        if (data->save_bodystructure_header) {
index 5842c4c5ec61cef9f4b31ec44c7d773e48825489..298a46d1a2bb9e51b6db58b9225f1a753a2853b6 100644 (file)
@@ -126,6 +126,7 @@ struct index_mail_data {
        unsigned int initialized_wrapper_stream:1;
        unsigned int destroy_callback_set:1;
        unsigned int prefetch_sent:1;
+       unsigned int header_parser_initialized:1;
 };
 
 struct index_mail {