message-decoder.c revision 9ae664e94e6eeb5c1f900bb90642052633031832
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2006-2007 Dovecot authors, see the included COPYING file */
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen/* base64 takes max 4 bytes per character, q-p takes max 3. */
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen/* UTF-8 takes max 5 bytes per character. Not sure about others, but I'd think
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen 10 is more than enough for everyone.. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen char translation_buf[MAX_TRANSLATION_BUF_SIZE];
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct message_decoder_context *message_decoder_init(bool dtcase)
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen ctx = i_new(struct message_decoder_context, 1);
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen ctx->buf = buffer_create_dynamic(default_pool, 8192);
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen ctx->buf2 = buffer_create_dynamic(default_pool, 8192);
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainenvoid message_decoder_deinit(struct message_decoder_context **_ctx)
45e62043058738e294f89504c319d852e25943ccTimo Sirainenparse_content_transfer_encoding(struct message_decoder_context *ctx,
d5960ce1c0adda5c9e259bc429123ebc29c60baeTimo Sirainen rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL);
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen (void)rfc822_parse_mime_token(&parser, value);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (i_memcasecmp(str_data(value), "7bit", 4) == 0 ||
6eb30032b4a50c383dea4c9c74342d906de6ad36Timo Sirainen i_memcasecmp(str_data(value), "8bit", 4) == 0)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen if (i_memcasecmp(str_data(value), "base64", 6) == 0)
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen else if (i_memcasecmp(str_data(value), "binary", 6) == 0)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen if (i_memcasecmp(str_data(value), "quoted-printable", 16) == 0)
f537e7efaec891d6b3320ca94331d09ca8c4a4dbTimo Sirainenparse_content_type(struct message_decoder_context *ctx,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL);
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen if (rfc822_parse_content_type(&parser, str) <= 0)
b87a4156eca6dcf6b29c504eb0cb9be2fdb11b63Timo Sirainen while (rfc822_parse_content_param(&parser, &key, &value) > 0) {
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainenstatic bool message_decode_header(struct message_decoder_context *ctx,
return FALSE;
return TRUE;
for (i = 0; i < len; i++) {
return len;
for (i = 0; i < size;) {
goto broken;
i += len;
return input;
while (i < size) {
if (len == 0) {
i += len;
int ret;
case CONTENT_TYPE_UNKNOWN:
return FALSE;
case CONTENT_TYPE_BINARY:
case CONTENT_TYPE_QP:
case CONTENT_TYPE_BASE64:
return FALSE;
if (ret < 0) {
return FALSE;
if (ret == 0) {
return TRUE;
return TRUE;