[dovecot-cvs] dovecot/src/lib-mail message-parser.c,1.77,1.78
tss at dovecot.org
tss at dovecot.org
Tue Feb 6 12:55:24 UTC 2007
- Previous message: [dovecot-cvs] dovecot/src/imap cmd-append.c,1.80.2.1,1.80.2.2
- Next message: [dovecot-cvs] dovecot/src/imap client.c, 1.75, 1.76 client.h, 1.40, 1.41 cmd-append.c, 1.87, 1.88 cmd-idle.c, 1.35, 1.36 cmd-search.c, 1.30, 1.31
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /var/lib/cvs/dovecot/src/lib-mail
In directory talvi:/tmp/cvs-serv23821
Modified Files:
message-parser.c
Log Message:
Fixes.
Index: message-parser.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/message-parser.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- message-parser.c 14 Jan 2007 02:48:15 -0000 1.77
+++ message-parser.c 6 Feb 2007 12:55:22 -0000 1.78
@@ -75,6 +75,8 @@
const unsigned char *data = block->data;
size_t i;
+ i_assert(ctx->skip == 0);
+
block->hdr = NULL;
for (i = 0; i < block->size; i++) {
@@ -107,8 +109,10 @@
if (i_stream_read_data(ctx->input, &block_r->data,
&block_r->size, ctx->want_count) == -1)
return -1;
- if (block_r->size == 0)
+ if (block_r->size == 0) {
+ i_assert(!ctx->input->blocking);
return 0;
+ }
ctx->want_count = 1;
return 1;
@@ -158,7 +162,7 @@
static int
boundary_line_find(struct message_parser_ctx *ctx,
- const unsigned char *data, size_t size, bool eof,
+ const unsigned char *data, size_t size, bool full,
struct message_boundary **boundary_r)
{
size_t i;
@@ -166,7 +170,9 @@
*boundary_r = NULL;
if (size < 2) {
- if (eof)
+ i_assert(!full);
+
+ if (ctx->input->eof)
return -1;
ctx->want_count = 2;
return 0;
@@ -182,7 +188,8 @@
if (data[i] == '\n')
break;
}
- if (i == size && i < BOUNDARY_END_MAX_LEN && !eof) {
+ if (i == size && i < BOUNDARY_END_MAX_LEN &&
+ !ctx->input->eof && !full) {
/* no LF found */
ctx->want_count = BOUNDARY_END_MAX_LEN;
return 0;
@@ -282,19 +289,20 @@
const unsigned char *data;
size_t i, boundary_start;
int ret;
- bool eof;
+ bool eof, full;
if ((ret = message_parser_read_more(ctx, block_r)) == 0 ||
block_r->size == 0)
return ret;
eof = ret == -1;
+ full = ret == -2;
data = block_r->data;
if (ctx->last_chr == '\n') {
/* handle boundary in first line of message. alternatively
it's an empty line. */
ret = boundary_line_find(ctx, block_r->data,
- block_r->size, eof, &boundary);
+ block_r->size, full, &boundary);
if (ret >= 0) {
if (ret == 0)
return 0;
@@ -303,7 +311,7 @@
}
}
- for (i = boundary_start = 0;; i++) {
+ for (i = boundary_start = 0; i < block_r->size; i++) {
for (; i < block_r->size; i++) {
if (data[i] == '\n') {
boundary_start = i;
@@ -312,32 +320,35 @@
break;
}
}
+ if (boundary_start != 0)
+ full = FALSE;
ret = boundary_line_find(ctx, block_r->data + i + 1,
- block_r->size - (i + 1), eof,
+ block_r->size - (i + 1), full,
&boundary);
- if (ret >= 0 || eof)
- break;
- if (i == block_r->size) {
- ret = 0;
+ if (ret >= 0) {
+ /* found / need more data */
break;
}
}
- if (!eof || ret > 0) {
+ if (i == block_r->size) {
+ /* the boundary wasn't found from this data block,
+ we'll need more data. */
+ ret = eof ? -1 : 0;
+ }
+ i_assert(!(ret == 0 && full));
+
+ if (ret >= 0) {
/* leave CR+LF + last line to buffer */
block_r->size = boundary_start;
}
- if (block_r->size != 0) {
- parse_body_add_block(ctx, block_r);
- return 1;
+ if (ret <= 0) {
+ if (block_r->size != 0)
+ parse_body_add_block(ctx, block_r);
+ return ret;
}
- if (ret == 0)
- return 0;
- if (eof && ret <= 0)
- return -1;
- i_assert(ret > 0);
return parse_part_finish(ctx, boundary, block_r);
}
@@ -540,18 +551,21 @@
bool eof = FALSE;
while ((ret = ctx->parse_next_block(ctx, block_r)) == 0) {
- if ((ret = i_stream_read(ctx->input)) == 0)
- break;
- if (ret < 0) {
- if (ret == -2)
- ret = 0;
- if (eof)
- break;
- eof = TRUE;
- } else {
- eof = FALSE;
+ ret = message_parser_read_more(ctx, block_r);
+ if (ret <= 0) {
+ i_assert(ret != -2);
+
+ if (ret == 0) {
+ i_assert(!ctx->input->blocking);
+ return 0;
+ }
+ if (ret < 0) {
+ i_assert(!eof);
+ eof = TRUE;
+ }
}
}
+
block_r->part = ctx->part;
if (ret < 0) {
- Previous message: [dovecot-cvs] dovecot/src/imap cmd-append.c,1.80.2.1,1.80.2.2
- Next message: [dovecot-cvs] dovecot/src/imap client.c, 1.75, 1.76 client.h, 1.40, 1.41 cmd-append.c, 1.87, 1.88 cmd-idle.c, 1.35, 1.36 cmd-search.c, 1.30, 1.31
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the dovecot-cvs
mailing list