From: Timo Sirainen Date: Thu, 23 Apr 2020 13:50:56 +0000 (+0300) Subject: lib-mail, global: message_parser_init*() - Convert flags to settings structure X-Git-Tag: 2.3.11.2~47 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21dcfcccec70f867498a40f804f4313246e69fa3;p=thirdparty%2Fdovecot%2Fcore.git lib-mail, global: message_parser_init*() - Convert flags to settings structure --- diff --git a/src/doveadm/doveadm-mail-fetch.c b/src/doveadm/doveadm-mail-fetch.c index 75b69e4242..d8b396a199 100644 --- a/src/doveadm/doveadm-mail-fetch.c +++ b/src/doveadm/doveadm-mail-fetch.c @@ -265,6 +265,9 @@ static int fetch_text(struct fetch_cmd_context *ctx) static int fetch_text_utf8(struct fetch_cmd_context *ctx) { + const struct message_parser_settings parser_set = { + .hdr_flags = MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE, + }; struct istream *input; struct message_parser_ctx *parser; struct message_decoder_context *decoder; @@ -275,9 +278,7 @@ static int fetch_text_utf8(struct fetch_cmd_context *ctx) if (mail_get_stream(ctx->mail, NULL, NULL, &input) < 0) return -1; - parser = message_parser_init(pool_datastack_create(), input, - MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE, - 0); + parser = message_parser_init(pool_datastack_create(), input, &parser_set); decoder = message_decoder_init(NULL, 0); while ((ret = message_parser_parse_next_block(parser, &raw_block)) > 0) { diff --git a/src/lib-imap/test-imap-bodystructure.c b/src/lib-imap/test-imap-bodystructure.c index 6f456a4453..dfc9957488 100644 --- a/src/lib-imap/test-imap-bodystructure.c +++ b/src/lib-imap/test-imap-bodystructure.c @@ -381,6 +381,11 @@ static const unsigned int normalize_tests_count = N_ELEMENTS(normalize_tests); static struct message_part * msg_parse(pool_t pool, const char *message, bool parse_bodystructure) { + const struct message_parser_settings parser_set = { + .hdr_flags = MESSAGE_HEADER_PARSER_FLAG_SKIP_INITIAL_LWSP | + MESSAGE_HEADER_PARSER_FLAG_DROP_CR, + .flags = MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK, + }; struct message_parser_ctx *parser; struct istream *input; struct message_block block; @@ -388,10 +393,7 @@ msg_parse(pool_t pool, const char *message, bool parse_bodystructure) int ret; input = i_stream_create_from_data(message, strlen(message)); - parser = message_parser_init(pool, input, - MESSAGE_HEADER_PARSER_FLAG_SKIP_INITIAL_LWSP | - MESSAGE_HEADER_PARSER_FLAG_DROP_CR, - MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK); + parser = message_parser_init(pool, input, &parser_set); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) { if (parse_bodystructure) { message_part_data_parse_from_header(pool, block.part, diff --git a/src/lib-imap/test-imap-envelope.c b/src/lib-imap/test-imap-envelope.c index 0d0891701b..1f295e58ba 100644 --- a/src/lib-imap/test-imap-envelope.c +++ b/src/lib-imap/test-imap-envelope.c @@ -118,6 +118,11 @@ static const unsigned int parse_tests_count = N_ELEMENTS(parse_tests); static struct message_part_envelope * msg_parse(pool_t pool, const char *message) { + const struct message_parser_settings parser_set = { + .hdr_flags = MESSAGE_HEADER_PARSER_FLAG_SKIP_INITIAL_LWSP | + MESSAGE_HEADER_PARSER_FLAG_DROP_CR, + .flags = MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK, + }; struct message_parser_ctx *parser; struct message_part_envelope *envlp = NULL; struct istream *input; @@ -126,10 +131,7 @@ msg_parse(pool_t pool, const char *message) int ret; input = i_stream_create_from_data(message, strlen(message)); - parser = message_parser_init(pool, input, - MESSAGE_HEADER_PARSER_FLAG_SKIP_INITIAL_LWSP | - MESSAGE_HEADER_PARSER_FLAG_DROP_CR, - MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK); + parser = message_parser_init(pool, input, &parser_set); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) { i_assert(block.part->parent == NULL); message_part_envelope_parse_from_header(pool, &envlp, block.hdr); diff --git a/src/lib-mail/istream-attachment-extractor.c b/src/lib-mail/istream-attachment-extractor.c index e9655a5a67..7d4ac01072 100644 --- a/src/lib-mail/istream-attachment-extractor.c +++ b/src/lib-mail/istream-attachment-extractor.c @@ -696,6 +696,10 @@ i_stream_create_attachment_extractor(struct istream *input, struct istream_attachment_settings *set, void *context) { + const struct message_parser_settings parser_set = { + .flags = MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS | + MESSAGE_PARSER_FLAG_INCLUDE_BOUNDARIES, + }; struct attachment_istream *astream; i_assert(set->min_size > 0); @@ -722,9 +726,7 @@ i_stream_create_attachment_extractor(struct istream *input, astream->istream.istream.seekable = FALSE; astream->pool = pool_alloconly_create("istream attachment", 1024); - astream->parser = message_parser_init(astream->pool, input, 0, - MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS | - MESSAGE_PARSER_FLAG_INCLUDE_BOUNDARIES); + astream->parser = message_parser_init(astream->pool, input, &parser_set); return i_stream_create(&astream->istream, input, i_stream_get_fd(input), 0); } diff --git a/src/lib-mail/istream-binary-converter.c b/src/lib-mail/istream-binary-converter.c index 201a588152..856b854738 100644 --- a/src/lib-mail/istream-binary-converter.c +++ b/src/lib-mail/istream-binary-converter.c @@ -286,6 +286,10 @@ static void i_stream_binary_converter_close(struct iostream_private *stream, struct istream *i_stream_create_binary_converter(struct istream *input) { + const struct message_parser_settings parser_set = { + .flags = MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS | + MESSAGE_PARSER_FLAG_INCLUDE_BOUNDARIES, + }; struct binary_converter_istream *bstream; bstream = i_new(struct binary_converter_istream, 1); @@ -299,9 +303,7 @@ struct istream *i_stream_create_binary_converter(struct istream *input) bstream->istream.istream.seekable = FALSE; bstream->pool = pool_alloconly_create("istream binary converter", 128); - bstream->parser = message_parser_init(bstream->pool, input, 0, - MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS | - MESSAGE_PARSER_FLAG_INCLUDE_BOUNDARIES); + bstream->parser = message_parser_init(bstream->pool, input, &parser_set); return i_stream_create(&bstream->istream, input, i_stream_get_fd(input), 0); } diff --git a/src/lib-mail/message-parser-from-parts.c b/src/lib-mail/message-parser-from-parts.c index b23055ab9b..8e21ec8f18 100644 --- a/src/lib-mail/message-parser-from-parts.c +++ b/src/lib-mail/message-parser-from-parts.c @@ -351,14 +351,13 @@ static int preparsed_parse_next_header_init(struct message_parser_ctx *ctx, struct message_parser_ctx * message_parser_init_from_parts(struct message_part *parts, struct istream *input, - enum message_header_parser_flags hdr_flags, - enum message_parser_flags flags) + const struct message_parser_settings *set) { struct message_parser_ctx *ctx; i_assert(parts != NULL); - ctx = message_parser_init_int(input, hdr_flags, flags); + ctx = message_parser_init_int(input, set); ctx->preparsed = TRUE; ctx->parts = ctx->part = parts; ctx->parse_next_block = preparsed_parse_next_header_init; diff --git a/src/lib-mail/message-parser-private.h b/src/lib-mail/message-parser-private.h index fe106819e2..dbf8464cfb 100644 --- a/src/lib-mail/message-parser-private.h +++ b/src/lib-mail/message-parser-private.h @@ -51,8 +51,7 @@ struct message_parser_ctx { struct message_parser_ctx * message_parser_init_int(struct istream *input, - enum message_header_parser_flags hdr_flags, - enum message_parser_flags flags); + const struct message_parser_settings *set); int message_parser_read_more(struct message_parser_ctx *ctx, struct message_block *block_r, bool *full_r); diff --git a/src/lib-mail/message-parser.c b/src/lib-mail/message-parser.c index c9ff98576b..41b9ed133a 100644 --- a/src/lib-mail/message-parser.c +++ b/src/lib-mail/message-parser.c @@ -703,14 +703,13 @@ static int parse_next_header_init(struct message_parser_ctx *ctx, struct message_parser_ctx * message_parser_init_int(struct istream *input, - enum message_header_parser_flags hdr_flags, - enum message_parser_flags flags) + const struct message_parser_settings *set) { struct message_parser_ctx *ctx; ctx = i_new(struct message_parser_ctx, 1); - ctx->hdr_flags = hdr_flags; - ctx->flags = flags; + ctx->hdr_flags = set->hdr_flags; + ctx->flags = set->flags; ctx->input = input; i_stream_ref(input); return ctx; @@ -718,12 +717,11 @@ message_parser_init_int(struct istream *input, struct message_parser_ctx * message_parser_init(pool_t part_pool, struct istream *input, - enum message_header_parser_flags hdr_flags, - enum message_parser_flags flags) + const struct message_parser_settings *set) { struct message_parser_ctx *ctx; - ctx = message_parser_init_int(input, hdr_flags, flags); + ctx = message_parser_init_int(input, set); ctx->part_pool = part_pool; ctx->parts = ctx->part = p_new(part_pool, struct message_part, 1); ctx->next_part = &ctx->part->children; diff --git a/src/lib-mail/message-parser.h b/src/lib-mail/message-parser.h index 3efd851862..d159b2607d 100644 --- a/src/lib-mail/message-parser.h +++ b/src/lib-mail/message-parser.h @@ -17,6 +17,11 @@ enum message_parser_flags { MESSAGE_PARSER_FLAG_INCLUDE_BOUNDARIES = 0x08 }; +struct message_parser_settings { + enum message_header_parser_flags hdr_flags; + enum message_parser_flags flags; +}; + struct message_parser_ctx; struct message_block { @@ -45,8 +50,7 @@ extern message_part_header_callback_t *null_message_part_header_callback; are allocated from. */ struct message_parser_ctx * message_parser_init(pool_t part_pool, struct istream *input, - enum message_header_parser_flags hdr_flags, - enum message_parser_flags flags); + const struct message_parser_settings *set); /* Deinitialize message parser. The ctx must NOT have been created by message_parser_init_from_parts(). */ void message_parser_deinit(struct message_parser_ctx **ctx, @@ -55,8 +59,7 @@ void message_parser_deinit(struct message_parser_ctx **ctx, struct message_parser_ctx * message_parser_init_from_parts(struct message_part *parts, struct istream *input, - enum message_header_parser_flags hdr_flags, - enum message_parser_flags flags); + const struct message_parser_settings *set); /* Same as message_parser_deinit(), but return an error message describing why the preparsed parts didn't match the message. This can also safely be called even when preparsed parts weren't used - it'll always just return diff --git a/src/lib-mail/message-search.c b/src/lib-mail/message-search.c index 66c043c158..14d1a11470 100644 --- a/src/lib-mail/message-search.c +++ b/src/lib-mail/message-search.c @@ -196,8 +196,9 @@ message_search_msg_real(struct message_search_context *ctx, struct istream *input, struct message_part *parts, const char **error_r) { - const enum message_header_parser_flags hdr_parser_flags = - MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE; + const struct message_parser_settings parser_set = { + .hdr_flags = MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE, + }; struct message_parser_ctx *parser_ctx; struct message_block raw_block; struct message_part *new_parts; @@ -207,10 +208,10 @@ message_search_msg_real(struct message_search_context *ctx, if (parts != NULL) { parser_ctx = message_parser_init_from_parts(parts, - input, hdr_parser_flags, 0); + input, &parser_set); } else { parser_ctx = message_parser_init(pool_datastack_create(), - input, hdr_parser_flags, 0); + input, &parser_set); } while ((ret = message_parser_parse_next_block(parser_ctx, diff --git a/src/lib-mail/message-snippet.c b/src/lib-mail/message-snippet.c index 2100b70554..e6965fd707 100644 --- a/src/lib-mail/message-snippet.c +++ b/src/lib-mail/message-snippet.c @@ -137,6 +137,7 @@ int message_snippet_generate(struct istream *input, unsigned int max_snippet_chars, string_t *snippet) { + const struct message_parser_settings parser_set = { .flags = 0 }; struct message_parser_ctx *parser; struct message_part *parts; struct message_decoder_context *decoder; @@ -151,7 +152,7 @@ int message_snippet_generate(struct istream *input, ctx.snippet.chars_left = max_snippet_chars; ctx.quoted_snippet.snippet = str_new(pool, max_snippet_chars); ctx.quoted_snippet.chars_left = max_snippet_chars - 1; /* -1 for '>' */ - parser = message_parser_init(pool_datastack_create(), input, 0, 0); + parser = message_parser_init(pool_datastack_create(), input, &parser_set); decoder = message_decoder_init(NULL, 0); while ((ret = message_parser_parse_next_block(parser, &raw_block)) > 0) { if (!message_decoder_decode_next_block(decoder, &raw_block, &block)) diff --git a/src/lib-mail/test-message-decoder.c b/src/lib-mail/test-message-decoder.c index e1faca29b4..3007283cad 100644 --- a/src/lib-mail/test-message-decoder.c +++ b/src/lib-mail/test-message-decoder.c @@ -105,6 +105,7 @@ static void test_message_decoder_multipart(void) "\n" "?garbage\n" "--foo--\n"; + const struct message_parser_settings parser_set = { .flags = 0, }; struct message_parser_ctx *parser; struct message_decoder_context *decoder; struct message_part *parts; @@ -116,7 +117,8 @@ static void test_message_decoder_multipart(void) test_begin("message decoder multipart"); istream = test_istream_create(test_message_input); - parser = message_parser_init(pool_datastack_create(), istream, 0, 0); + parser = message_parser_init(pool_datastack_create(), istream, + &parser_set); decoder = message_decoder_init(NULL, 0); test_istream_set_allow_eof(istream, FALSE); diff --git a/src/lib-mail/test-message-parser.c b/src/lib-mail/test-message-parser.c index 6bf1643e88..5e496275fe 100644 --- a/src/lib-mail/test-message-parser.c +++ b/src/lib-mail/test-message-parser.c @@ -39,6 +39,8 @@ static const char test_msg[] = "\n"; #define TEST_MSG_LEN (sizeof(test_msg)-1) +static const struct message_parser_settings set_empty = { .flags = 0 }; + static bool msg_parts_cmp(struct message_part *p1, struct message_part *p2) { while (p1 != NULL || p2 != NULL) { @@ -71,6 +73,9 @@ static bool msg_parts_cmp(struct message_part *p1, struct message_part *p2) static void test_parsed_parts(struct istream *input, struct message_part *parts) { + const struct message_parser_settings parser_set = { + .flags = MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK, + }; struct message_parser_ctx *parser; struct message_block block; struct message_part *parts2; @@ -81,8 +86,7 @@ static void test_parsed_parts(struct istream *input, struct message_part *parts) if (i_stream_get_size(input, TRUE, &input_size) < 0) i_unreached(); - parser = message_parser_init_from_parts(parts, input, 0, - MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK); + parser = message_parser_init_from_parts(parts, input, &parser_set); for (i = 1; i <= input_size*2+1; i++) { test_istream_set_size(input, i/2); if (i > TEST_MSG_LEN*2) @@ -111,9 +115,11 @@ static void test_message_parser_small_blocks(void) output = t_str_new(128); /* full parsing */ - parser = message_parser_init(pool, input, 0, - MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS | - MESSAGE_PARSER_FLAG_INCLUDE_BOUNDARIES); + const struct message_parser_settings full_parser_set = { + .flags = MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS | + MESSAGE_PARSER_FLAG_INCLUDE_BOUNDARIES, + }; + parser = message_parser_init(pool, input, &full_parser_set); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) { if (block.hdr != NULL) message_header_line_write(output, block.hdr); @@ -129,7 +135,7 @@ static void test_message_parser_small_blocks(void) i_stream_seek(input, 0); test_istream_set_allow_eof(input, FALSE); - parser = message_parser_init(pool, input, 0, 0); + parser = message_parser_init(pool, input, &set_empty); for (i = 1; i <= TEST_MSG_LEN*2+1; i++) { test_istream_set_size(input, i/2); if (i > TEST_MSG_LEN*2) @@ -147,8 +153,11 @@ static void test_message_parser_small_blocks(void) test_istream_set_allow_eof(input, FALSE); end_of_headers_idx = (strstr(test_msg, "\n-----") - test_msg); - parser = message_parser_init_from_parts(parts, input, 0, - MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK); + const struct message_parser_settings preparsed_parser_set = { + .flags = MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK, + }; + parser = message_parser_init_from_parts(parts, input, + &preparsed_parser_set); for (i = 1; i <= TEST_MSG_LEN*2+1; i++) { test_istream_set_size(input, i/2); if (i > TEST_MSG_LEN*2) @@ -190,7 +199,7 @@ static const char input_msg[] = pool = pool_alloconly_create("message parser", 10240); input = test_istream_create(input_msg); - parser = message_parser_init(pool, input, 0, 0); + parser = message_parser_init(pool, input, &set_empty); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ; test_assert(ret < 0); message_parser_deinit(&parser, &parts); @@ -255,7 +264,7 @@ static const char input_msg[] = pool = pool_alloconly_create("message parser", 10240); input = test_istream_create(input_msg); - parser = message_parser_init(pool, input, 0, 0); + parser = message_parser_init(pool, input, &set_empty); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ; test_assert(ret < 0); message_parser_deinit(&parser, &parts); @@ -311,7 +320,7 @@ static const char input_msg[] = pool = pool_alloconly_create("message parser", 10240); input = test_istream_create(input_msg); - parser = message_parser_init(pool, input, 0, 0); + parser = message_parser_init(pool, input, &set_empty); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ; test_assert(ret < 0); message_parser_deinit(&parser, &parts); @@ -349,7 +358,7 @@ static const char input_msg[] = pool = pool_alloconly_create("message parser", 10240); input = test_istream_create(input_msg); - parser = message_parser_init(pool, input, 0, 0); + parser = message_parser_init(pool, input, &set_empty); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ; test_assert(ret < 0); message_parser_deinit(&parser, &parts); @@ -394,7 +403,7 @@ static const char input_msg[] = pool = pool_alloconly_create("message parser", 10240); input = test_istream_create(input_msg); - parser = message_parser_init(pool, input, 0, 0); + parser = message_parser_init(pool, input, &set_empty); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ; test_assert(ret < 0); message_parser_deinit(&parser, &parts); @@ -455,7 +464,7 @@ static const char input_msg[] = pool = pool_alloconly_create("message parser", 10240); input = test_istream_create(input_msg); - parser = message_parser_init(pool, input, 0, 0); + parser = message_parser_init(pool, input, &set_empty); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ; test_assert(ret < 0); message_parser_deinit(&parser, &parts); @@ -516,7 +525,7 @@ static const char input_msg[] = pool = pool_alloconly_create("message parser", 10240); input = test_istream_create(input_msg); - parser = message_parser_init(pool, input, 0, 0); + parser = message_parser_init(pool, input, &set_empty); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ; test_assert(ret < 0); message_parser_deinit(&parser, &parts); @@ -578,7 +587,7 @@ static const char input_msg[] = pool = pool_alloconly_create("message parser", 10240); input = test_istream_create(input_msg); - parser = message_parser_init(pool, input, 0, 0); + parser = message_parser_init(pool, input, &set_empty); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ; test_assert(ret < 0); message_parser_deinit(&parser, &parts); @@ -661,7 +670,7 @@ static const char input_msg[] = pool = pool_alloconly_create("message parser", 10240); input = test_istream_create(input_msg); - parser = message_parser_init(pool, input, 0, 0); + parser = message_parser_init(pool, input, &set_empty); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ; test_assert(ret < 0); message_parser_deinit(&parser, &parts); @@ -721,7 +730,7 @@ static void test_message_parser_no_eoh(void) pool = pool_alloconly_create("message parser", 10240); input = test_istream_create(input_msg); - parser = message_parser_init(pool, input, 0, 0); + parser = message_parser_init(pool, input, &set_empty); test_assert(message_parser_parse_next_block(parser, &block) > 0 && block.hdr != NULL && strcmp(block.hdr->name, "a") == 0 && block.hdr->value_len == 1 && block.hdr->value[0] == 'b'); @@ -777,7 +786,7 @@ static const char input_msg[] = pool = pool_alloconly_create("message parser", 10240); input = test_istream_create(input_msg); - parser = message_parser_init(pool, input, 0, 0); + parser = message_parser_init(pool, input, &set_empty); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ; test_assert(ret < 0); message_parser_deinit(&parser, &parts); diff --git a/src/lib-mail/test-message-part.c b/src/lib-mail/test-message-part.c index 6cad8ffbd3..4a51a39f99 100644 --- a/src/lib-mail/test-message-part.c +++ b/src/lib-mail/test-message-part.c @@ -65,6 +65,7 @@ static const char test_msg[] = static void test_message_part_idx(void) { + const struct message_parser_settings set = { .flags = 0 }; struct message_parser_ctx *parser; struct istream *input; struct message_part *parts, *part, *prev_part; @@ -77,7 +78,7 @@ static void test_message_part_idx(void) pool = pool_alloconly_create("message parser", 10240); input = i_stream_create_from_data(test_msg, TEST_MSG_LEN); - parser = message_parser_init(pool, input, 0, 0); + parser = message_parser_init(pool, input, &set); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) { part_idx = message_part_to_idx(block.part); test_assert(part_idx >= prev_idx); diff --git a/src/lib-storage/index/index-mail-headers.c b/src/lib-storage/index/index-mail-headers.c index 54a5883177..df21b9129e 100644 --- a/src/lib-storage/index/index-mail-headers.c +++ b/src/lib-storage/index/index-mail-headers.c @@ -16,11 +16,11 @@ #include "index-storage.h" #include "index-mail.h" -static const enum message_header_parser_flags hdr_parser_flags = - MESSAGE_HEADER_PARSER_FLAG_SKIP_INITIAL_LWSP | - MESSAGE_HEADER_PARSER_FLAG_DROP_CR; -static const enum message_parser_flags msg_parser_flags = - MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK; +static const struct message_parser_settings msg_parser_set = { + .hdr_flags = MESSAGE_HEADER_PARSER_FLAG_SKIP_INITIAL_LWSP | + MESSAGE_HEADER_PARSER_FLAG_DROP_CR, + .flags = MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK, +}; static int header_line_cmp(const struct index_mail_line *l1, const struct index_mail_line *l2) @@ -399,7 +399,7 @@ index_mail_cache_parse_init(struct mail *_mail, struct istream *input) mail->data.parser_input = input; mail->data.parser_ctx = message_parser_init(mail->mail.data_pool, input, - hdr_parser_flags, msg_parser_flags); + &msg_parser_set); i_stream_unref(&input); return input2; } @@ -428,14 +428,12 @@ static void index_mail_init_parser(struct index_mail *mail) data->parser_input = data->stream; data->parser_ctx = message_parser_init(mail->mail.data_pool, data->stream, - hdr_parser_flags, - msg_parser_flags); + &msg_parser_set); } else { data->parser_ctx = message_parser_init_from_parts(data->parts, data->stream, - hdr_parser_flags, - msg_parser_flags); + &msg_parser_set); } } @@ -468,7 +466,7 @@ int index_mail_parse_headers(struct index_mail *mail, i_assert(!data->save_bodystructure_body || data->parser_ctx != NULL); message_parse_header(data->stream, &data->hdr_size, - hdr_parser_flags, + msg_parser_set.hdr_flags, index_mail_parse_header_cb, mail); } if (index_mail_stream_check_failure(mail) < 0) @@ -526,7 +524,7 @@ int index_mail_headers_get_envelope(struct index_mail *mail) if (mail->data.envelope == NULL) { /* we got the headers from cache - parse them to get the envelope */ - message_parse_header(stream, NULL, hdr_parser_flags, + message_parse_header(stream, NULL, msg_parser_set.hdr_flags, imap_envelope_parse_callback, mail); if (stream->stream_errno != 0) { index_mail_stream_log_failure_for(mail, stream); diff --git a/src/plugins/fts/fts-build-mail.c b/src/plugins/fts/fts-build-mail.c index 3cb4ea657f..e088e7397b 100644 --- a/src/plugins/fts/fts-build-mail.c +++ b/src/plugins/fts/fts-build-mail.c @@ -475,6 +475,9 @@ fts_build_mail_real(struct fts_backend_update_context *update_ctx, const char **retriable_err_msg_r, bool *may_need_retry_r) { + const struct message_parser_settings parser_set = { + .hdr_flags = MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE, + }; struct fts_mail_build_context ctx; struct istream *input; struct message_parser_ctx *parser; @@ -503,9 +506,7 @@ fts_build_mail_real(struct fts_backend_update_context *update_ctx, ctx.pending_input = buffer_create_dynamic(default_pool, 128); prev_part = NULL; - parser = message_parser_init(pool_datastack_create(), input, - MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE, - 0); + parser = message_parser_init(pool_datastack_create(), input, &parser_set); decoder = message_decoder_init(update_ctx->normalizer, 0); for (;;) {