message-decoder.c revision e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3
/* Copyright (C) 2006 Timo Sirainen */
#include "lib.h"
#include "buffer.h"
#include "strescape.h"
#include "base64.h"
#include "charset-utf8.h"
#include "quoted-printable.h"
#include "message-parser.h"
#include "message-content-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 bool
{
struct charset_translation *t;
bool unknown_charset;
/* ASCII / UTF-8 */
} else {
}
return TRUE;
}
if (unknown_charset) {
/* let's just ignore this part */
return TRUE;
}
/* ignore any errors */
charset_to_utf8_end(&t);
return TRUE;
}
void *context)
{
switch (value_len) {
case 4:
break;
case 6:
break;
case 16:
break;
}
}
static void
bool value_quoted, void *context)
{
}
}
struct message_header_line *hdr,
struct message_block *output)
{
return FALSE;
}
}
ctx);
}
}
}
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
}