From 489301ee88b2174e3171875e979e667de2c4a174 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 28 Feb 2016 22:23:03 +0200 Subject: [PATCH] lib-storage: When cached mime.parts is detected to be inconsistent, log it as hex-encoded. --- src/lib-storage/index/index-mail-headers.c | 4 +--- src/lib-storage/index/index-mail.c | 28 +++++++++++++++------- src/lib-storage/index/index-mail.h | 1 + src/lib-storage/index/index-search.c | 4 +--- src/plugins/fts/fts-build-mail.c | 8 +++---- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/lib-storage/index/index-mail-headers.c b/src/lib-storage/index/index-mail-headers.c index c20298884e..5636e18406 100644 --- a/src/lib-storage/index/index-mail-headers.c +++ b/src/lib-storage/index/index-mail-headers.c @@ -406,9 +406,7 @@ static void index_mail_init_parser(struct index_mail *mail) if (data->parser_ctx != NULL) { data->parser_input = NULL; if (message_parser_deinit_from_parts(&data->parser_ctx, &parts, &error) < 0) { - mail_set_cache_corrupted_reason(&mail->mail.mail, - MAIL_FETCH_MESSAGE_PARTS, t_strdup_printf( - "Cached MIME parts don't match message during parsing: %s", error)); + index_mail_set_message_parts_corrupted(&mail->mail.mail, error); data->parts = NULL; } } diff --git a/src/lib-storage/index/index-mail.c b/src/lib-storage/index/index-mail.c index 0b057f8c92..dceb2c949b 100644 --- a/src/lib-storage/index/index-mail.c +++ b/src/lib-storage/index/index-mail.c @@ -5,6 +5,7 @@ #include "buffer.h" #include "ioloop.h" #include "istream.h" +#include "hex-binary.h" #include "str.h" #include "message-date.h" #include "message-part-serialize.h" @@ -145,6 +146,22 @@ static bool get_cached_parts(struct index_mail *mail) return TRUE; } +void index_mail_set_message_parts_corrupted(struct mail *mail, const char *error) +{ + buffer_t *part_buf; + const char *parts_str; + + if (get_serialized_parts((struct index_mail *)mail, &part_buf) <= 0) + parts_str = ""; + else + parts_str = binary_to_hex(part_buf->data, part_buf->used); + + mail_set_cache_corrupted_reason(mail, + MAIL_FETCH_MESSAGE_PARTS, t_strdup_printf( + "Cached MIME parts don't match message during parsing: %s (parts=%s)", + error, parts_str)); +} + static bool index_mail_get_fixed_field(struct index_mail *mail, enum index_cache_field field, void *data, size_t data_size) @@ -984,9 +1001,7 @@ index_mail_parse_body_finish(struct index_mail *mail, if (ret <= 0) { if (ret == 0) { i_assert(error != NULL); - mail_set_cache_corrupted_reason(&mail->mail.mail, - MAIL_FETCH_MESSAGE_PARTS, t_strdup_printf( - "Cached MIME parts don't match message during parsing: %s", error)); + index_mail_set_message_parts_corrupted(&mail->mail.mail, error); } mail->data.parts = NULL; mail->data.parsed_bodystructure = FALSE; @@ -1475,11 +1490,8 @@ static void index_mail_close_streams_full(struct index_mail *mail, bool closing) const char *error; if (data->parser_ctx != NULL) { - if (message_parser_deinit_from_parts(&data->parser_ctx, &parts, &error) < 0) { - mail_set_cache_corrupted_reason(&mail->mail.mail, - MAIL_FETCH_MESSAGE_PARTS, t_strdup_printf( - "Cached MIME parts don't match message during parsing: %s", error)); - } + if (message_parser_deinit_from_parts(&data->parser_ctx, &parts, &error) < 0) + index_mail_set_message_parts_corrupted(&mail->mail.mail, error); mail->data.parser_input = NULL; if (mail->data.save_bodystructure_body) mail->data.save_bodystructure_header = TRUE; diff --git a/src/lib-storage/index/index-mail.h b/src/lib-storage/index/index-mail.h index df2c6b1858..392420f652 100644 --- a/src/lib-storage/index/index-mail.h +++ b/src/lib-storage/index/index-mail.h @@ -178,6 +178,7 @@ void index_mail_update_access_parts_post(struct mail *_mail); void index_mail_close(struct mail *mail); void index_mail_close_streams(struct index_mail *mail); void index_mail_free(struct mail *mail); +void index_mail_set_message_parts_corrupted(struct mail *mail, const char *error); bool index_mail_want_parse_headers(struct index_mail *mail); void index_mail_parse_header_init(struct index_mail *mail, diff --git a/src/lib-storage/index/index-search.c b/src/lib-storage/index/index-search.c index 561e0bcd25..d874da6c78 100644 --- a/src/lib-storage/index/index-search.c +++ b/src/lib-storage/index/index-search.c @@ -649,9 +649,7 @@ static void search_body(struct mail_search_arg *arg, ret = message_search_msg(msg_search_ctx, ctx->input, ctx->part, &error); if (ret < 0 && ctx->input->stream_errno == 0) { /* try again without cached parts */ - mail_set_cache_corrupted_reason(ctx->index_ctx->cur_mail, - MAIL_FETCH_MESSAGE_PARTS, t_strdup_printf( - "Cached MIME parts don't match message during parsing in SEARCH: %s", error)); + index_mail_set_message_parts_corrupted(ctx->index_ctx->cur_mail, error); i_stream_seek(ctx->input, 0); ret = message_search_msg(msg_search_ctx, ctx->input, NULL, &error); diff --git a/src/plugins/fts/fts-build-mail.c b/src/plugins/fts/fts-build-mail.c index 251a57045c..2a334afa17 100644 --- a/src/plugins/fts/fts-build-mail.c +++ b/src/plugins/fts/fts-build-mail.c @@ -9,6 +9,7 @@ #include "message-parser.h" #include "message-decoder.h" #include "mail-storage.h" +#include "index-mail.h" #include "fts-parser.h" #include "fts-user.h" #include "fts-language.h" @@ -572,11 +573,8 @@ fts_build_mail_real(struct fts_backend_update_context *update_ctx, block.data = NULL; block.size = 0; ret = fts_build_body_block(&ctx, &block, TRUE); } - if (message_parser_deinit_from_parts(&parser, &parts, &error) < 0) { - mail_set_cache_corrupted_reason(mail, - MAIL_FETCH_MESSAGE_PARTS, t_strdup_printf( - "Cached MIME parts don't match message during parsing in FTS index building: %s", error)); - } + if (message_parser_deinit_from_parts(&parser, &parts, &error) < 0) + index_mail_set_message_parts_corrupted(mail, error); message_decoder_deinit(&decoder); i_free(ctx.content_type); i_free(ctx.content_disposition);