]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message-parser was counting body_size wrong for truncated MIME headers...
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 8 Jan 2016 11:24:32 +0000 (13:24 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 8 Jan 2016 11:24:32 +0000 (13:24 +0200)
src/lib-mail/message-parser.c
src/lib-mail/test-message-parser.c

index e5ad128cdfaa582051e3148d3865a0dbc23c7195..15fcbe28181548e086dc9bd3fe1904f7263e8bfb 100644 (file)
@@ -541,13 +541,16 @@ static int parse_next_header(struct message_parser_ctx *ctx,
                   [CR]LF belongs to the MIME boundary though. */
                if (ctx->prev_hdr_newline_size > 0) {
                        i_assert(ctx->part->header_size.lines > 0);
+                       /* remove the newline size from the MIME header */
                        ctx->part->header_size.lines--;
                        ctx->part->header_size.physical_size -=
                                ctx->prev_hdr_newline_size;
-                       ctx->part->header_size.virtual_size -=
+                       ctx->part->header_size.virtual_size -= 2;
+                       /* add the newline size to the parent's body */
+                       ctx->part->parent->body_size.lines++;
+                       ctx->part->parent->body_size.physical_size +=
                                ctx->prev_hdr_newline_size;
-                       if (ctx->prev_hdr_newline_size == 1)
-                               ctx->part->header_size.virtual_size--;
+                       ctx->part->parent->body_size.virtual_size += 2;
                }
                hdr = NULL;
        }
index a862427e94f4e2741446450a91ccc0d35fb8593a..75a0712315c720671e461bf0b8000dcbff2f8312 100644 (file)
@@ -158,6 +158,9 @@ static const char input_msg[] =
        test_assert(message_parser_deinit(&parser, &parts) == 0);
 
        test_assert((parts->flags & MESSAGE_PART_FLAG_MULTIPART) != 0);
+       test_assert(parts->body_size.lines == 8);
+       test_assert(parts->body_size.physical_size == 112);
+       test_assert(parts->body_size.virtual_size == 112+7);
        test_assert(parts->children->header_size.physical_size == 0);
        test_assert(parts->children->body_size.physical_size == 0);
        test_assert(parts->children->body_size.lines == 0);