From: Timo Sirainen Date: Fri, 23 Jul 2004 18:36:10 +0000 (+0300) Subject: Fixed a crash with fetch (rfc822.size body). Also fixed it so it doesn't X-Git-Tag: 1.1.alpha1~3749 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a58e4aec412a30352d9d45e63726cac044aa6aa5;p=thirdparty%2Fdovecot%2Fcore.git Fixed a crash with fetch (rfc822.size body). Also fixed it so it doesn't anymore parse the message body twice. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/index-mail.c b/src/lib-storage/index/index-mail.c index fcc5363f59..8228623b38 100644 --- a/src/lib-storage/index/index-mail.c +++ b/src/lib-storage/index/index-mail.c @@ -307,6 +307,8 @@ static void index_mail_parse_body(struct index_mail *mail, int need_parts) message_parser_parse_body(data->parser_ctx, parse_bodystructure_part_header, NULL, mail->pool); + data->save_bodystructure_body = FALSE; + data->parsed_bodystructure = TRUE; } else { message_parser_parse_body(data->parser_ctx, NULL, NULL, NULL); } @@ -406,21 +408,28 @@ static void index_mail_parse_bodystructure(struct index_mail *mail, string_t *str; int bodystructure_cached = FALSE; - if (data->save_bodystructure_header || !data->save_bodystructure_body) { - /* we haven't parsed the header yet */ - data->save_bodystructure_header = TRUE; - data->save_bodystructure_body = TRUE; - if (!index_mail_parse_headers(mail, NULL)) - return; - } + if (!data->parsed_bodystructure) { + if (data->save_bodystructure_header || + !data->save_bodystructure_body) { + /* we haven't parsed the header yet */ + data->save_bodystructure_header = TRUE; + data->save_bodystructure_body = TRUE; + if (!index_mail_parse_headers(mail, NULL)) + return; + } - if (data->parts != NULL) { - i_assert(data->parts->next == NULL); - message_parse_from_parts(data->parts->children, data->stream, - parse_bodystructure_part_header, - mail->pool); - } else { - index_mail_parse_body(mail, FALSE); + if (data->parts != NULL) { + i_assert(data->parts->next == NULL); + i_stream_seek(data->stream, + data->hdr_size.physical_size); + message_parse_from_parts(data->parts->children, + data->stream, + parse_bodystructure_part_header, + mail->pool); + data->parsed_bodystructure = TRUE; + } else { + index_mail_parse_body(mail, FALSE); + } } dec = mail_cache_field_get_decision(mail->ibox->cache, diff --git a/src/lib-storage/index/index-mail.h b/src/lib-storage/index/index-mail.h index c67207f288..c902de50e0 100644 --- a/src/lib-storage/index/index-mail.h +++ b/src/lib-storage/index/index-mail.h @@ -77,6 +77,7 @@ struct index_mail_data { unsigned int save_sent_date:1; unsigned int save_bodystructure_header:1; unsigned int save_bodystructure_body:1; + unsigned int parsed_bodystructure:1; unsigned int hdr_size_set:1; unsigned int body_size_set:1; unsigned int open_mail:1;