message-parser.c revision 983a75ef88be63d8b596e165b015bd85bf90b354
5a580c3a38ced62d4bcc95b8ac7c4f2935b5d294Timo Sirainen/* Copyright (C) 2002-2006 Timo Sirainen */
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen/* RFC-2046 requires boundaries are max. 70 chars + "--" prefix + "--" suffix.
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen We'll add a bit more just in case. */
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen struct message_header_parser_ctx *hdr_parser_ctx;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen int (*parse_next_block)(struct message_parser_ctx *ctx,
4efba37e4f27b93832f6147c3a353d6d22c855c7Timo Sirainenmessage_part_header_callback_t *null_message_part_header_callback = NULL;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainenstatic int parse_next_header_init(struct message_parser_ctx *ctx,
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainenstatic int parse_next_body_to_boundary(struct message_parser_ctx *ctx,
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainenstatic int parse_next_body_to_eof(struct message_parser_ctx *ctx,
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainenstatic int preparsed_parse_next_header_init(struct message_parser_ctx *ctx,
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainenboundary_find(struct message_boundary *boundaries,
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen /* As MIME spec says: search from latest one to oldest one so that we
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen don't break if the same boundary is used in nested parts. Also the
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen full message line doesn't have to match the boundary, only the
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen beginning. */
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen memcmp(boundaries->boundary, data, boundaries->len) == 0)
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainenstatic void parse_body_add_block(struct message_parser_ctx *ctx,
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen unsigned int missing_cr_count = 0;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen ctx->part->flags |= MESSAGE_PART_FLAG_HAS_NULS;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen ctx->part->body_size.physical_size += block->size;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen ctx->part->body_size.virtual_size += block->size + missing_cr_count;
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainenstatic int message_parser_read_more(struct message_parser_ctx *ctx,
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen ret = i_stream_read_data(ctx->input, &block_r->data,
static struct message_part *
return part;
struct message_boundary *b;
size_t i;
size_t i;
int ret;
return ret;
const unsigned char *data;
int ret;
return ret;
if (ret >= 0) {
if (ret == 0)
boundary_start = i;
if (boundary_start != 0) {
&boundary);
if (ret >= 0) {
if (eof)
ret = 0;
if (ret >= 0) {
int ret;
return ret;
#define MUTEX_FLAGS \
int ret;
return ret;
t_push();
t_pop();
MESSAGE_PART_FLAG_MULTIPART_DIGEST) != 0) {
int ret;
if (ret <= 0)
return ret;
int ret;
return ret;
struct message_parser_ctx *
return ctx;
struct message_parser_ctx *
return ctx;
return parts;
int ret;
if (ret <= 0) {
if (ret == 0) {
if (ret < 0) {
return ret;
void *context)
int ret;
if (ret < 0) {
void *context)
int ret;
if (use_crlf) {
if (!use_crlf)