Skip to content

Commit

Permalink
lib-storage: When cached mime.parts is detected to be inconsistent, l…
Browse files Browse the repository at this point in the history
…og it as hex-encoded.
  • Loading branch information
sirainen committed Feb 28, 2016
1 parent 4611418 commit 489301e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
4 changes: 1 addition & 3 deletions src/lib-storage/index/index-mail-headers.c
Expand Up @@ -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;
}
}
Expand Down
28 changes: 20 additions & 8 deletions src/lib-storage/index/index-mail.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/lib-storage/index/index-mail.h
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions src/lib-storage/index/index-search.c
Expand Up @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions src/plugins/fts/fts-build-mail.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 489301e

Please sign in to comment.