]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Fixed header parsing when there were multiple same header names.
authorTimo Sirainen <tss@iki.fi>
Thu, 9 Oct 2014 13:41:23 +0000 (16:41 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 9 Oct 2014 13:41:23 +0000 (16:41 +0300)
For example if a mail had:

Name1: a
Name1: b
Name2: c

If the Name1: was initially added to cache and Name2: not, but later on both
were attempted to be added to cache, the Name2: lookup would have been added
with "b" instead of "c" value.

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

index 3bc3fd816179689ba21660a2caecdae5644f5447..986949bfd36106847a3cc8cbe12b9f75bf1e565e 100644 (file)
@@ -71,6 +71,7 @@ static void index_mail_parse_header_finish(struct index_mail *mail)
 
                if (match_idx < match_count) {
                        /* save index to first header line */
+                       i_assert(match_idx == lines[i].field_idx);
                        j = i + 1;
                        array_idx_set(&mail->header_match_lines, match_idx, &j);
                        match_idx++;
@@ -78,8 +79,12 @@ static void index_mail_parse_header_finish(struct index_mail *mail)
 
                if (!mail_cache_field_can_add(_mail->transaction->cache_trans,
                                              _mail->seq, lines[i].field_idx)) {
-                       /* header is already cached */
-                       j = i + 1;
+                       /* header is already cached. skip over all the
+                          header lines. */
+                       for (j = i+1; j < count; j++) {
+                               if (lines[j].field_idx != lines[i].field_idx)
+                                       break;
+                       }
                        continue;
                }