]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global: Handle broken Content-Type headers consistently.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 10 Oct 2016 17:38:31 +0000 (20:38 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 19 Oct 2016 12:42:21 +0000 (15:42 +0300)
1) Only the first Content-Type header is used. (Simpler than using the last.)

2) Invalid Content-Types are parsed as far as we can. This is mainly to make
sure they aren't treated as missing Content-Types, which could cause them to
become text/plain.

src/lib-mail/istream-attachment-extractor.c
src/lib-mail/message-decoder.c
src/lib-mail/message-parser.c
src/lib-mail/message-search.c
src/plugins/fts/fts-build-mail.c

index 0f1d8c65a2025562b6a3a002d9d903a813911fc4..27b051ea266c7bbbd5d889a423fd8bcecdc8ae84 100644 (file)
@@ -77,16 +77,16 @@ static void parse_content_type(struct attachment_istream *astream,
        struct rfc822_parser_context parser;
        string_t *content_type;
 
+       if (astream->part.content_type != NULL)
+               return;
+
        rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL);
        rfc822_skip_lwsp(&parser);
 
        T_BEGIN {
                content_type = t_str_new(64);
-               if (rfc822_parse_content_type(&parser, content_type) >= 0) {
-                       i_free(astream->part.content_type);
-                       astream->part.content_type =
-                               i_strdup(str_c(content_type));
-               }
+               (void)rfc822_parse_content_type(&parser, content_type);
+               astream->part.content_type = i_strdup(str_c(content_type));
        } T_END;
 }
 
index 4402f63f05d1a8f0eca49e4df71f9810d10052f5..80c532ee2407baf97717095a48958a94f524a190 100644 (file)
@@ -127,6 +127,7 @@ parse_content_type(struct message_decoder_context *ctx,
        struct rfc822_parser_context parser;
        const char *const *results;
        string_t *str;
+       int ret;
 
        if (ctx->content_type != NULL)
                return;
@@ -134,9 +135,10 @@ parse_content_type(struct message_decoder_context *ctx,
        rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL);
        rfc822_skip_lwsp(&parser);
        str = t_str_new(64);
-       if (rfc822_parse_content_type(&parser, str) < 0)
-               return;
+       ret = rfc822_parse_content_type(&parser, str);
        ctx->content_type = i_strdup(str_c(str));
+       if (ret < 0)
+               return;
 
        rfc2231_parse(&parser, &results);
        for (; *results != NULL; results += 2) {
index 20ad10272565047c44c9f465689aaeef00a99596..1ab18c7d9884dc545c25d7c78666eda54ccf4b28 100644 (file)
@@ -474,6 +474,7 @@ static void parse_content_type(struct message_parser_ctx *ctx,
        struct rfc822_parser_context parser;
        const char *const *results;
        string_t *content_type;
+       int ret;
 
        if (ctx->part_seen_content_type)
                return;
@@ -483,8 +484,7 @@ static void parse_content_type(struct message_parser_ctx *ctx,
        rfc822_skip_lwsp(&parser);
 
        content_type = t_str_new(64);
-       if (rfc822_parse_content_type(&parser, content_type) < 0)
-               return;
+       ret = rfc822_parse_content_type(&parser, content_type);
 
        if (strcasecmp(str_c(content_type), "message/rfc822") == 0)
                ctx->part->flags |= MESSAGE_PART_FLAG_MESSAGE_RFC822;
@@ -499,6 +499,8 @@ static void parse_content_type(struct message_parser_ctx *ctx,
                        ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART_DIGEST;
        }
 
+       if (ret < 0)
+               return;
        if ((ctx->part->flags & MESSAGE_PART_FLAG_MULTIPART) == 0 ||
            ctx->last_boundary != NULL)
                return;
index 001f8848204e33a0877954542a47e5de5d24665c..45c85e4c3db2bf2195fee59267abb1166aa24b72 100644 (file)
@@ -57,11 +57,10 @@ static void parse_content_type(struct message_search_context *ctx,
        rfc822_skip_lwsp(&parser);
 
        content_type = t_str_new(64);
-       if (rfc822_parse_content_type(&parser, content_type) >= 0) {
-               ctx->content_type_text =
-                       strncasecmp(str_c(content_type), "text/", 5) == 0 ||
-                       strncasecmp(str_c(content_type), "message/", 8) == 0;
-       }
+       (void)rfc822_parse_content_type(&parser, content_type);
+       ctx->content_type_text =
+               strncasecmp(str_c(content_type), "text/", 5) == 0 ||
+               strncasecmp(str_c(content_type), "message/", 8) == 0;
 }
 
 static void handle_header(struct message_search_context *ctx,
index abac1d8f59e0dd123085fa324baaf3950c784875..ad989c97a94a7da94ebf0e8c55d601ce76034061 100644 (file)
@@ -45,16 +45,16 @@ static void fts_build_parse_content_type(struct fts_mail_build_context *ctx,
        struct rfc822_parser_context parser;
        string_t *content_type;
 
+       if (ctx->content_type != NULL)
+               return;
+
        rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL);
        rfc822_skip_lwsp(&parser);
 
        T_BEGIN {
                content_type = t_str_new(64);
-               if (rfc822_parse_content_type(&parser, content_type) >= 0) {
-                       i_free(ctx->content_type);
-                       ctx->content_type =
-                               str_lcase(i_strdup(str_c(content_type)));
-               }
+               (void)rfc822_parse_content_type(&parser, content_type);
+               ctx->content_type = str_lcase(i_strdup(str_c(content_type)));
        } T_END;
 }