message-parser.c revision 0a7d137b4cbdabdae6027941e285efb3c8a48c20
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen/* RFC-2046 requires boundaries are max. 70 chars + "--" prefix + "--" suffix.
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen We'll add a bit more just in case. */
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen struct message_header_parser_ctx *hdr_parser_ctx;
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen int (*parse_next_block)(struct message_parser_ctx *ctx,
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenmessage_part_header_callback_t *null_message_part_header_callback = NULL;
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic int parse_next_header_init(struct message_parser_ctx *ctx,
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic int parse_next_body_to_boundary(struct message_parser_ctx *ctx,
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic int parse_next_body_to_eof(struct message_parser_ctx *ctx,
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic int preparsed_parse_next_header_init(struct message_parser_ctx *ctx,
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenboundary_find(struct message_boundary *boundaries,
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen /* As MIME spec says: search from latest one to oldest one so that we
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen don't break if the same boundary is used in nested parts. Also the
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen full message line doesn't have to match the boundary, only the
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen beginning. */
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen memcmp(boundaries->boundary, data, boundaries->len) == 0)
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic void parse_body_add_block(struct message_parser_ctx *ctx,
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen unsigned int missing_cr_count = 0;
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen ctx->part->flags |= MESSAGE_PART_FLAG_HAS_NULS;
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen ctx->part->body_size.physical_size += block->size;
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen ctx->part->body_size.virtual_size += block->size + missing_cr_count;
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic int message_parser_read_more(struct message_parser_ctx *ctx,
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen ret = i_stream_read_data(ctx->input, &block_r->data,
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen /* EOF, but we still have some data.
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen return it. */
2d83aa5eebd1bb710ca2fc21316b89442f027f3dAki Tuomistatic struct message_part *
2d83aa5eebd1bb710ca2fc21316b89442f027f3dAki Tuomimessage_part_append(pool_t pool, struct message_part *parent)
a893aaa999856b1ba6e4541890016767aaa283c7Aki Tuomi /* set child position */
a893aaa999856b1ba6e4541890016767aaa283c7Aki Tuomistatic void parse_next_body_multipart_init(struct message_parser_ctx *ctx)
a893aaa999856b1ba6e4541890016767aaa283c7Aki Tuomi b = p_new(ctx->parser_pool, struct message_boundary, 1);
size_t i;
size_t i;
int ret;
bool full;
return ret;
const unsigned char *data;
int ret;
bool full;
return ret;
if (ret >= 0) {
return ret == 0 ? 0 :
boundary_start = i;
if (boundary_start != 0) {
&boundary);
if (ret >= 0) {
ret = 0;
bool full;
int ret;
return ret;
const char *const *results;
#define MUTEX_FLAGS \
int ret;
return ret;
else T_BEGIN {
} T_END;
MESSAGE_PART_FLAG_MULTIPART_DIGEST) != 0) {
bool full;
int ret;
return ret;
int ret;
return ret;
struct message_parser_ctx *
return ctx;
struct message_parser_ctx *
return ctx;
return ret;
int ret;
if (ret == 0) {
return ret;
void *context)
int ret;
if (ret < 0) {
void *context)
int ret;