From: Timo Sirainen Date: Mon, 10 Oct 2016 17:23:47 +0000 (+0300) Subject: lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE X-Git-Tag: 2.2.26~112 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ad485aeb133ab81cde6fa153c38f64f79320cf5d;p=thirdparty%2Fdovecot%2Fcore.git lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE Mainly because it doesn't match with MESSAGE_PART_FLAG_TEXT in message_part. --- diff --git a/src/lib-imap/imap-bodystructure.c b/src/lib-imap/imap-bodystructure.c index c091356757..14da214e71 100644 --- a/src/lib-imap/imap-bodystructure.c +++ b/src/lib-imap/imap-bodystructure.c @@ -36,13 +36,13 @@ static void parse_content_type(struct message_part_body_data *data, string_t *str; unsigned int i; bool charset_found = FALSE; + int ret; rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); rfc822_skip_lwsp(&parser); str = t_str_new(256); - if (rfc822_parse_content_type(&parser, str) < 0) - return; + ret = rfc822_parse_content_type(&parser, str); /* Save content type and subtype */ value = str_c(str); @@ -56,6 +56,16 @@ static void parse_content_type(struct message_part_body_data *data, str_truncate(str, i); data->content_type = imap_get_string(data->pool, str_c(str)); + if (ret < 0) { + /* Content-Type is broken, but we wanted to get it as well as + we could. Don't try to read the parameters anymore though. + + We don't completely ignore a broken Content-Type, because + then it would be written as text/plain. This would cause a + mismatch with the message_part's MESSAGE_PART_FLAG_TEXT. */ + return; + } + /* parse parameters and save them */ str_truncate(str, 0); rfc2231_parse(&parser, &results);