]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail, global: message_parser_init*() - Convert flags to settings structure
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 23 Apr 2020 13:50:56 +0000 (16:50 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 27 May 2020 05:28:17 +0000 (08:28 +0300)
16 files changed:
src/doveadm/doveadm-mail-fetch.c
src/lib-imap/test-imap-bodystructure.c
src/lib-imap/test-imap-envelope.c
src/lib-mail/istream-attachment-extractor.c
src/lib-mail/istream-binary-converter.c
src/lib-mail/message-parser-from-parts.c
src/lib-mail/message-parser-private.h
src/lib-mail/message-parser.c
src/lib-mail/message-parser.h
src/lib-mail/message-search.c
src/lib-mail/message-snippet.c
src/lib-mail/test-message-decoder.c
src/lib-mail/test-message-parser.c
src/lib-mail/test-message-part.c
src/lib-storage/index/index-mail-headers.c
src/plugins/fts/fts-build-mail.c

index 75b69e42426e180f5f2338ea50435535832362e8..d8b396a199bfed4cd851d4bb0fc40f210a5507b4 100644 (file)
@@ -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) {
index 6f456a44530b67f068bcfac9b4e8ed05a0df868a..dfc9957488582983143d84c9f630aae905220671 100644 (file)
@@ -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,
index 0d0891701b2a18ca3f71967f32aa1090bff26f70..1f295e58bab39f95f6fbe38a8cabd578ca4d1dbe 100644 (file)
@@ -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);
index e9655a5a6725e5c424d73e7f2ff26f202c119225..7d4ac010724f90c144b6c28e408fa13eb9dbbe56 100644 (file)
@@ -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);
 }
index 201a58815295421c39c03f78addd19bc1f8f9da0..856b8547387c70b76d660d6be83ad5c29a4df770 100644 (file)
@@ -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);
 }
index b23055ab9b9b02aab0a8eeaa0b7383fe4e2eff88..8e21ec8f181d46aa3ba31d32a9cc296d6ae7b505 100644 (file)
@@ -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;
index fe106819e2e6d44c352683b43ebcbeaa9b01afcc..dbf8464cfba09a0f1fe84a9db39767ed59f4f2df 100644 (file)
@@ -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);
 
index c9ff98576b1a503292186e85376e1c408b509d84..41b9ed133a964c130c3382ca4ab23904c31fa111 100644 (file)
@@ -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;
index 3efd8518629996c14aab1a391305161aaf734cf4..d159b2607db5436017980274554e704a17c1a2a5 100644 (file)
@@ -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
index 66c043c158c0fed49622e0a2f829f4c0bbf91bea..14d1a11470889dfc924f56ad148e7f11352224b5 100644 (file)
@@ -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,
index 2100b70554f09b303fd4d2452a011761d09682bb..e6965fd707f47f53758adceed34c672c0939d185 100644 (file)
@@ -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))
index e1faca29b4fe740678fe7af1bafebae5d94c6592..3007283cad06f684ce0c006e25b96edcc06a52b6 100644 (file)
@@ -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);
index 6bf1643e88440e1382b11f36b9e44f465305de14..5e496275fecee1ee2d10b4882a050ac92778ba3a 100644 (file)
@@ -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);
index 6cad8ffbd301683a7ab44ed7888777d6abcd4a3d..4a51a39f99fc357eb3457580f0c1d8a0a21c7ef8 100644 (file)
@@ -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);
index 54a58831777cfdc02815a572351cc227892e53a0..df21b9129ec27c9b5feea2a74c2c385dbcecbf56 100644 (file)
 #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);
index 3cb4ea657f3ba064669904702f463f86d71b58a8..e088e7397b7713267a5194b923c559034075d39a 100644 (file)
@@ -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 (;;) {