Skip to content

Commit

Permalink
lib-mail: message_header_parser_next() updates istream position immed…
Browse files Browse the repository at this point in the history
…iately now.

Earlier it updated the position only on the next call or at deinit. This was
because some earlier code kept pointers to the stream data and stored them
to the returned struct message_header_line, but we don't do this anymore.

This allows more easily accessing the same istream for other purposes during
the header parsing.
  • Loading branch information
sirainen committed Dec 15, 2015
1 parent 2a8253e commit a556e29
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/lib-mail/message-header-parser.c
Expand Up @@ -15,7 +15,6 @@ struct message_header_parser_ctx {

string_t *name;
buffer_t *value_buf;
size_t skip;

enum message_header_parser_flags flags;
unsigned int skip_line:1;
Expand Down Expand Up @@ -44,7 +43,6 @@ void message_parse_header_deinit(struct message_header_parser_ctx **_ctx)
{
struct message_header_parser_ctx *ctx = *_ctx;

i_stream_skip(ctx->input, ctx->skip);
buffer_free(&ctx->value_buf);
str_free(&ctx->name);
i_free(ctx);
Expand All @@ -57,7 +55,7 @@ int message_parse_header_next(struct message_header_parser_ctx *ctx,
{
struct message_header_line *line = &ctx->line;
const unsigned char *msg;
size_t i, size, startpos, colon_pos, parse_size;
size_t i, size, startpos, colon_pos, parse_size, skip = 0;
int ret;
bool continued, continues, last_no_newline, last_crlf;
bool no_newline, crlf_newline;
Expand All @@ -66,11 +64,6 @@ int message_parse_header_next(struct message_header_parser_ctx *ctx,
if (line->eoh)
return -1;

if (ctx->skip > 0) {
i_stream_skip(ctx->input, ctx->skip);
ctx->skip = 0;
}

if (line->continues)
colon_pos = 0;
else {
Expand Down Expand Up @@ -100,10 +93,11 @@ int message_parse_header_next(struct message_header_parser_ctx *ctx,
if (startpos > 0) {
/* header ended unexpectedly. */
no_newline = TRUE;
ctx->skip = startpos;
skip = startpos;
break;
}
/* error / EOF with no bytes */
i_assert(skip == 0);
return -1;
}

Expand All @@ -117,17 +111,18 @@ int message_parse_header_next(struct message_header_parser_ctx *ctx,
if (ctx->hdr_size != NULL)
ctx->hdr_size->lines++;
if (msg[0] == '\r') {
ctx->skip = 2;
skip = 2;
crlf_newline = TRUE;
} else {
ctx->skip = 1;
skip = 1;
if (ctx->hdr_size != NULL)
ctx->hdr_size->virtual_size++;
}
break;
}
if (ret == 0 && !ctx->input->eof) {
/* stream is nonblocking - need more data */
i_assert(skip == 0);
return 0;
}
i_assert(size > 0);
Expand Down Expand Up @@ -161,7 +156,7 @@ int message_parse_header_next(struct message_header_parser_ctx *ctx,
continues = TRUE;
}
no_newline = TRUE;
ctx->skip = size;
skip = size;
break;
}

Expand Down Expand Up @@ -236,7 +231,7 @@ int message_parse_header_next(struct message_header_parser_ctx *ctx,
crlf_newline = TRUE;
}

ctx->skip = i+1;
skip = i+1;
break;
}

Expand Down Expand Up @@ -367,9 +362,10 @@ int message_parse_header_next(struct message_header_parser_ctx *ctx,
line->use_full_value = FALSE;

if (ctx->hdr_size != NULL) {
ctx->hdr_size->physical_size += ctx->skip;
ctx->hdr_size->virtual_size += ctx->skip;
ctx->hdr_size->physical_size += skip;
ctx->hdr_size->virtual_size += skip;
}
i_stream_skip(ctx->input, skip);

*hdr_r = line;
return 1;
Expand Down

0 comments on commit a556e29

Please sign in to comment.