Mercurial > dovecot > core-2.2
diff src/lib-mail/message-decoder.c @ 6916:0b8a78914db7 HEAD
Message decoding wasn't reset properly between messages when searching.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 03 Dec 2007 16:09:21 +0200 |
parents | 671c2eb25f3d |
children | 414c9d631a81 |
line wrap: on
line diff
--- a/src/lib-mail/message-decoder.c Mon Dec 03 15:41:01 2007 +0200 +++ b/src/lib-mail/message-decoder.c Mon Dec 03 16:09:21 2007 +0200 @@ -32,6 +32,7 @@ struct message_header_line hdr; buffer_t *buf, *buf2; + char *charset_trans_charset; struct charset_translation *charset_trans; char translation_buf[MAX_TRANSLATION_BUF_SIZE]; unsigned int translation_size; @@ -68,6 +69,7 @@ buffer_free(&ctx->buf); buffer_free(&ctx->buf2); + i_free(ctx->charset_trans_charset); i_free(ctx->content_charset); i_free(ctx); } @@ -268,24 +270,40 @@ return tmpbuf->data; } +static void message_decode_body_init_charset(struct message_decoder_context *ctx) +{ + enum charset_flags flags; + + if (ctx->charset_utf8) + return; + + if (ctx->charset_trans != NULL && + strcasecmp(ctx->content_charset, ctx->charset_trans_charset) == 0) { + /* already have the correct translation selected */ + return; + } + + if (ctx->charset_trans != NULL) + charset_to_utf8_end(&ctx->charset_trans); + i_free(ctx->charset_trans_charset); + + flags = ctx->dtcase ? CHARSET_FLAG_DECOMP_TITLECASE : 0; + ctx->charset_trans_charset = i_strdup(ctx->content_charset != NULL ? + ctx->content_charset : "UTF-8"); + if (charset_to_utf8_begin(ctx->charset_trans_charset, + flags, &ctx->charset_trans) < 0) + ctx->charset_trans = NULL; +} + static bool message_decode_body(struct message_decoder_context *ctx, struct message_block *input, struct message_block *output) { unsigned char new_buf[MAX_ENCODING_BUF_SIZE+1]; - enum charset_flags flags; const unsigned char *data = NULL; size_t pos, size = 0, skip = 0; int ret; - if (ctx->charset_trans == NULL && !ctx->charset_utf8) { - flags = ctx->dtcase ? CHARSET_FLAG_DECOMP_TITLECASE : 0; - if (charset_to_utf8_begin(ctx->content_charset != NULL ? - ctx->content_charset : "UTF-8", - flags, &ctx->charset_trans) < 0) - ctx->charset_trans = NULL; - } - if (ctx->encoding_size != 0) { /* @UNSAFE */ memcpy(new_buf, ctx->encoding_buf, ctx->encoding_size); @@ -404,10 +422,7 @@ { if (input->part != ctx->prev_part) { /* MIME part changed. */ - i_free_and_null(ctx->content_charset); - ctx->content_type = CONTENT_TYPE_BINARY; - ctx->charset_utf8 = TRUE; - ctx->encoding_size = 0; + message_decoder_decode_reset(ctx); } output->part = input->part; @@ -415,6 +430,18 @@ if (input->hdr != NULL) return message_decode_header(ctx, input->hdr, output); - else + else if (input->size != 0) return message_decode_body(ctx, input, output); + else { + message_decode_body_init_charset(ctx); + return TRUE; + } } + +void message_decoder_decode_reset(struct message_decoder_context *ctx) +{ + i_free_and_null(ctx->content_charset); + ctx->content_type = CONTENT_TYPE_BINARY; + ctx->charset_utf8 = TRUE; + ctx->encoding_size = 0; +}