message-decoder.c revision 5cbefc6537aefbf1491416c433de00fc3e649a13
/* Copyright (c) 2006-2009 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "buffer.h"
#include "base64.h"
#include "str.h"
#include "unichar.h"
#include "charset-utf8.h"
#include "quoted-printable.h"
#include "rfc822-parser.h"
#include "rfc2231-parser.h"
#include "message-parser.h"
#include "message-header-decode.h"
#include "message-decoder.h"
enum content_type {
CONTENT_TYPE_UNKNOWN = 0,
};
/* base64 takes max 4 bytes per character, q-p takes max 3. */
#define MAX_ENCODING_BUF_SIZE 3
/* UTF-8 takes max 5 bytes per character. Not sure about others, but I'd think
10 is more than enough for everyone.. */
#define MAX_TRANSLATION_BUF_SIZE 10
struct message_decoder_context {
enum message_decoder_flags flags;
struct message_part *prev_part;
struct message_header_line hdr;
char *charset_trans_charset;
struct charset_translation *charset_trans;
unsigned int translation_size;
unsigned int encoding_size;
char *content_charset;
enum content_type content_type;
unsigned int charset_utf8:1;
unsigned int binary_input:1;
};
struct message_decoder_context *
{
struct message_decoder_context *ctx;
return ctx;
}
{
}
static void
struct message_header_line *hdr)
{
struct rfc822_parser_context parser;
(void)rfc822_skip_lwsp(&parser);
case 4:
break;
case 6:
break;
case 16:
break;
}
}
static void
struct message_header_line *hdr)
{
struct rfc822_parser_context parser;
const char *const *results;
return;
(void)rfc822_skip_lwsp(&parser);
return;
break;
}
}
}
struct message_header_line *hdr,
struct message_block *output)
{
return FALSE;
}
T_BEGIN {
} T_END;
if (dtcase) {
}
if (dtcase) {
}
return TRUE;
}
{
unsigned int data_wanted, skip;
/* @UNSAFE: move the previously untranslated bytes to trans_buf
and see if we have now enough data to get the next character
translated */
if (data_wanted > *size)
data_wanted = *size;
ctx->translation_size = 0;
}
static void
struct message_part *part)
{
enum charset_flags flags;
if (ctx->charset_utf8)
return;
/* already have the correct translation selected */
return;
}
MESSAGE_PART_FLAG_MESSAGE_RFC822)) == 0;
if (ctx->binary_input)
return;
}
struct message_block *input,
struct message_block *output)
{
int ret;
if (ctx->encoding_size != 0) {
/* @UNSAFE */
}
switch (ctx->content_type) {
case CONTENT_TYPE_UNKNOWN:
/* just skip this body */
return FALSE;
case CONTENT_TYPE_BINARY:
break;
case CONTENT_TYPE_QP:
if (ctx->encoding_size != 0) {
}
break;
case CONTENT_TYPE_BASE64:
if (ctx->encoding_size != 0) {
/* corrupted base64 data, don't bother with
the rest of it */
return FALSE;
}
}
if (ret < 0) {
/* corrupted base64 data, don't bother with
the rest of it */
return FALSE;
}
if (ret == 0) {
/* end of base64 input */
}
break;
}
/* @UNSAFE */
ctx->encoding_size);
} else {
ctx->encoding_size = 0;
}
if (ctx->binary_input) {
} else if (ctx->charset_utf8) {
} else {
}
/* unknown charset */
} else {
}
} else {
if (ctx->translation_size != 0)
sizeof(ctx->translation_buf));
}
}
return TRUE;
}
struct message_block *input,
struct message_block *output)
{
/* MIME part changed. */
}
else {
return TRUE;
}
}
{
ctx->encoding_size = 0;
}