]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 10 Oct 2016 17:23:47 +0000 (20:23 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 19 Oct 2016 12:42:12 +0000 (15:42 +0300)
Mainly because it doesn't match with MESSAGE_PART_FLAG_TEXT in message_part.

src/lib-imap/imap-bodystructure.c

index c0913567578f383cd0cbd61e8f449ccdccdbf625..14da214e71761fb9c620b8f9994da843e0a7a1a7 100644 (file)
@@ -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);