1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
|
From 45cd8d8fd39d301607b22ec6f4ac800331a30225 Mon Sep 17 00:00:00 2001
From: Timo Sirainen <timo.sirainen@open-xchange.com>
Date: Thu, 23 Apr 2020 16:50:56 +0300
Subject: [PATCH 13/15] lib-mail, global: message_parser_init*() - Convert
flags to settings structure
---
src/doveadm/doveadm-mail-fetch.c | 7 +++--
src/lib-imap/test-imap-bodystructure.c | 10 +++---
src/lib-imap/test-imap-envelope.c | 10 +++---
src/lib-mail/istream-attachment-extractor.c | 8 +++--
src/lib-mail/istream-binary-converter.c | 8 +++--
src/lib-mail/message-parser-from-parts.c | 5 ++-
src/lib-mail/message-parser-private.h | 3 +-
src/lib-mail/message-parser.c | 12 +++-----
src/lib-mail/message-parser.h | 11 ++++---
src/lib-mail/message-search.c | 9 +++---
src/lib-mail/message-snippet.c | 3 +-
src/lib-mail/test-message-decoder.c | 4 ++-
src/lib-mail/test-message-parser.c | 47 +++++++++++++++++------------
src/lib-mail/test-message-part.c | 3 +-
src/lib-storage/index/index-mail-headers.c | 22 ++++++--------
src/plugins/fts/fts-build-mail.c | 7 +++--
16 files changed, 95 insertions(+), 74 deletions(-)
Index: dovecot/src/doveadm/doveadm-mail-fetch.c
===================================================================
--- dovecot.orig/src/doveadm/doveadm-mail-fetch.c
+++ dovecot/src/doveadm/doveadm-mail-fetch.c
@@ -265,6 +265,9 @@ static int fetch_text(struct fetch_cmd_c
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_
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: dovecot/src/lib-imap/test-imap-bodystructure.c
===================================================================
--- dovecot.orig/src/lib-imap/test-imap-bodystructure.c
+++ dovecot/src/lib-imap/test-imap-bodystructure.c
@@ -381,6 +381,11 @@ static const unsigned int normalize_test
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 *messa
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: dovecot/src/lib-imap/test-imap-envelope.c
===================================================================
--- dovecot.orig/src/lib-imap/test-imap-envelope.c
+++ dovecot/src/lib-imap/test-imap-envelope.c
@@ -118,6 +118,11 @@ static const unsigned int parse_tests_co
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 *messa
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: dovecot/src/lib-mail/istream-attachment-extractor.c
===================================================================
--- dovecot.orig/src/lib-mail/istream-attachment-extractor.c
+++ dovecot/src/lib-mail/istream-attachment-extractor.c
@@ -689,6 +689,10 @@ i_stream_create_attachment_extractor(str
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);
@@ -715,9 +719,7 @@ i_stream_create_attachment_extractor(str
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: dovecot/src/lib-mail/istream-binary-converter.c
===================================================================
--- dovecot.orig/src/lib-mail/istream-binary-converter.c
+++ dovecot/src/lib-mail/istream-binary-converter.c
@@ -284,6 +284,10 @@ static void i_stream_binary_converter_cl
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);
@@ -297,9 +301,7 @@ struct istream *i_stream_create_binary_c
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: dovecot/src/lib-mail/message-parser-from-parts.c
===================================================================
--- dovecot.orig/src/lib-mail/message-parser-from-parts.c
+++ dovecot/src/lib-mail/message-parser-from-parts.c
@@ -351,14 +351,13 @@ static int preparsed_parse_next_header_i
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: dovecot/src/lib-mail/message-parser-private.h
===================================================================
--- dovecot.orig/src/lib-mail/message-parser-private.h
+++ dovecot/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);
Index: dovecot/src/lib-mail/message-parser.c
===================================================================
--- dovecot.orig/src/lib-mail/message-parser.c
+++ dovecot/src/lib-mail/message-parser.c
@@ -703,14 +703,13 @@ static int parse_next_header_init(struct
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 *
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: dovecot/src/lib-mail/message-parser.h
===================================================================
--- dovecot.orig/src/lib-mail/message-parser.h
+++ dovecot/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 *n
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 messag
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: dovecot/src/lib-mail/message-search.c
===================================================================
--- dovecot.orig/src/lib-mail/message-search.c
+++ dovecot/src/lib-mail/message-search.c
@@ -196,8 +196,9 @@ message_search_msg_real(struct message_s
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_s
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: dovecot/src/lib-mail/message-snippet.c
===================================================================
--- dovecot.orig/src/lib-mail/message-snippet.c
+++ dovecot/src/lib-mail/message-snippet.c
@@ -99,6 +99,7 @@ int message_snippet_generate(struct istr
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;
@@ -112,7 +113,7 @@ int message_snippet_generate(struct istr
ctx.snippet = snippet;
ctx.chars_left = max_snippet_chars;
- 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: dovecot/src/lib-mail/test-message-parser.c
===================================================================
--- dovecot.orig/src/lib-mail/test-message-parser.c
+++ dovecot/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
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;
@@ -82,8 +87,7 @@ static void test_parsed_parts(struct ist
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)
@@ -113,9 +117,11 @@ static void test_message_parser_small_bl
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);
@@ -131,7 +137,7 @@ static void test_message_parser_small_bl
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)
@@ -149,8 +155,11 @@ static void test_message_parser_small_bl
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)
@@ -192,7 +201,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);
@@ -257,7 +266,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);
@@ -313,7 +322,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);
@@ -351,7 +360,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);
@@ -396,7 +405,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);
@@ -457,7 +466,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);
@@ -518,7 +527,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);
@@ -580,7 +589,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);
@@ -663,7 +672,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);
@@ -723,7 +732,7 @@ static void test_message_parser_no_eoh(v
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');
@@ -779,7 +788,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: dovecot/src/lib-mail/test-message-part.c
===================================================================
--- dovecot.orig/src/lib-mail/test-message-part.c
+++ dovecot/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);
Index: dovecot/src/lib-storage/index/index-mail-headers.c
===================================================================
--- dovecot.orig/src/lib-storage/index/index-mail-headers.c
+++ dovecot/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)
@@ -397,7 +397,7 @@ index_mail_cache_parse_init(struct mail
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;
}
@@ -426,14 +426,12 @@ static void index_mail_init_parser(struc
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);
}
}
@@ -466,7 +464,7 @@ int index_mail_parse_headers(struct inde
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)
@@ -521,7 +519,7 @@ int index_mail_headers_get_envelope(stru
if (mail->data.envelope == NULL && stream != 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: dovecot/src/plugins/fts/fts-build-mail.c
===================================================================
--- dovecot.orig/src/plugins/fts/fts-build-mail.c
+++ dovecot/src/plugins/fts/fts-build-mail.c
@@ -475,6 +475,9 @@ fts_build_mail_real(struct fts_backend_u
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_u
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 (;;) {
|