message-decoder.c revision 055f4599bba1874fa1148a8fa488517fa077619c
/* Copyright (C) 2006 Timo Sirainen */
#include "lib.h"
#include "buffer.h"
#include "base64.h"
#include "str.h"
#include "charset-utf8.h"
#include "quoted-printable.h"
#include "rfc822-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 {
struct message_part *prev_part;
struct message_header_line hdr;
struct charset_translation *charset_trans;
unsigned int translation_size;
unsigned int encoding_size;
char *content_charset;
enum content_type content_type;
unsigned int ucase:1;
unsigned int charset_utf8:1;
};
{
struct message_decoder_context *ctx;
return ctx;
}
{
}
static void
struct message_header_line *hdr)
{
struct rfc822_parser_context parser;
t_push();
(void)rfc822_skip_lwsp(&parser);
case 4:
break;
case 6:
break;
case 16:
break;
}
t_pop();
}
static void
struct message_header_line *hdr)
{
struct rfc822_parser_context parser;
return;
(void)rfc822_skip_lwsp(&parser);
t_push();
t_pop();
return;
}
break;
}
}
t_pop();
}
struct message_header_line *hdr,
struct message_block *output)
{
return FALSE;
}
}
}
return TRUE;
}
{
/* @UNSAFE */
ctx->translation_size = 0;
}
struct message_block *input,
struct message_block *output)
{
bool unknown_charset;
int ret;
ctx->charset_trans =
}
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->charset_utf8) {
} else {
}
} else {
if (ctx->translation_size != 0)
sizeof(ctx->translation_buf));
}
}
return TRUE;
}
struct message_block *input,
struct message_block *output)
{
/* MIME part changed. */
ctx->encoding_size = 0;
}
else
}