# HG changeset patch # User Timo Sirainen # Date 1105045939 -7200 # Node ID ccfd78cc07cc7fad7c42a0454d21c3c513aed0fa # Parent 2d4630db33fd70a8dd5ac843184d8a4895141cfe mail->get_header() was pretty broken. This affected SORT/THREAD. diff -r 2d4630db33fd -r ccfd78cc07cc src/lib-storage/index/index-mail-headers.c --- a/src/lib-storage/index/index-mail-headers.c Thu Jan 06 22:50:36 2005 +0200 +++ b/src/lib-storage/index/index-mail-headers.c Thu Jan 06 23:12:19 2005 +0200 @@ -179,6 +179,8 @@ enum mail_cache_decision_type decision; const char *cache_field_name; unsigned int field_idx; + uint8_t *match; + size_t size; int timezone, first_hdr = FALSE; data->parse_line_num++; @@ -260,21 +262,16 @@ } } - if (!data->parse_line.cache) { - uint8_t *match; - size_t size; - - match = buffer_get_modifyable_data(mail->header_match, &size); - if (field_idx >= size || - (match[field_idx] & ~1) != mail->header_match_value) { - /* we don't need to do anything with this header */ - return TRUE; - } - if (match[field_idx] == mail->header_match_value) { - /* first header */ - first_hdr = TRUE; - match[field_idx]++; - } + match = buffer_get_modifyable_data(mail->header_match, &size); + if (field_idx < size && match[field_idx] == mail->header_match_value) { + /* first header */ + first_hdr = TRUE; + match[field_idx]++; + } else if (!data->parse_line.cache && + (field_idx >= size || + (match[field_idx] & ~1) != mail->header_match_value)) { + /* we don't need to do anything with this header */ + return TRUE; } if (!hdr->continued) { @@ -435,7 +432,7 @@ size_t size; offsets = buffer_get_data(mail->header_offsets, &size); - i_assert(field_idx * sizeof(*offsets) >= size && + i_assert(field_idx * sizeof(*offsets) <= size && offsets[field_idx] != 0); data = buffer_get_data(mail->header_data, &size); @@ -485,6 +482,11 @@ index_mail_get_parsed_header(mail, field_idx); } + if (str_len(dest) == 0) { + /* cached as non-existing. */ + return NULL; + } + /* cached. skip "header name: " in dest. */ data = str_data(dest); len = str_len(dest);