Mercurial > dovecot > original-hg > dovecot-1.2
diff src/lib-mail/message-parser.c @ 1253:39b899338c99 HEAD
A few small fixes to MIME and mail address parsers.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 25 Feb 2003 21:10:03 +0200 |
parents | 6a19c941a1fc |
children | 97f8c00b8d4c |
line wrap: on
line diff
--- a/src/lib-mail/message-parser.c Tue Feb 25 00:56:15 2003 +0200 +++ b/src/lib-mail/message-parser.c Tue Feb 25 21:10:03 2003 +0200 @@ -269,9 +269,8 @@ return part; } -/* skip over to next line increasing message size */ static void message_skip_line(struct istream *input, - struct message_size *msg_size) + struct message_size *msg_size, int skip_lf) { const unsigned char *msg; size_t i, size, startpos; @@ -281,20 +280,23 @@ while (i_stream_read_data(input, &msg, &size, startpos) > 0) { for (i = startpos; i < size; i++) { if (msg[i] == '\n') { + if (!skip_lf) { + if (i > 0 && msg[i-1] == '\r') + i--; + startpos = i; + goto __break; + } + if (msg_size != NULL) { if (i == 0 || msg[i-1] != '\r') msg_size->virtual_size++; msg_size->lines++; } - break; + startpos = i+1; + goto __break; } } - if (i < size) { - startpos = i+1; - break; - } - /* leave the last character, it may be \r */ i_stream_skip(input, i - 1); startpos = 1; @@ -304,7 +306,7 @@ msg_size->virtual_size += i - 1; } } - +__break: i_stream_skip(input, startpos); if (msg_size != NULL) { @@ -333,7 +335,7 @@ /* overflow, line is too long. just skip it. */ i_assert(size > 2); - message_skip_line(input, hdr_size); + message_skip_line(input, hdr_size, TRUE); startpos = line_start = 0; colon_pos = UINT_MAX; continue; @@ -389,13 +391,11 @@ end_pos--; name_len = end_pos - line_start + 1; - /* get length of value field. skip - only the initial LWSP after ':'. - some fields may want to keep - the extra spaces.. */ + /* get length of value field. + skip all LWSP after ':'. */ colon_pos++; - if (colon_pos < i && - IS_LWSP(msg[colon_pos])) + while (colon_pos < i && + IS_LWSP(msg[colon_pos])) colon_pos++; value_len = i - colon_pos; if (msg[i-1] == '\r') value_len--; @@ -520,7 +520,8 @@ /* leave the last line to buffer, it may be boundary */ i = line_start; - if (i > 2) i -= 2; /* leave the \r\n too */ + if (i > 0) i--; /* leave the \r\n too */ + if (i > 0) i--; line_start -= i; } @@ -531,6 +532,14 @@ startpos = size - i; } + if (boundary == NULL && line_start+2 <= size && + msg[line_start] == '-' && msg[line_start+1] == '-') { + /* possible boundary without line feed at end */ + boundary = boundary_find(boundaries, + msg + line_start + 2, + size - line_start - 2); + } + if (boundary != NULL) { if (skip_over) { /* leave the pointer right after the boundary */ @@ -559,16 +568,18 @@ static struct message_part * message_parse_body(struct istream *input, struct message_boundary *boundaries, - struct message_size *body_size) + struct message_size *msg_size) { struct message_boundary *boundary; + struct message_size body_size; if (boundaries == NULL) { - message_get_body_size(input, body_size, (uoff_t)-1, NULL); + message_get_body_size(input, &body_size, (uoff_t)-1, NULL); + message_size_add(msg_size, &body_size); return NULL; } else { boundary = message_find_boundary(input, boundaries, - body_size, FALSE); + msg_size, FALSE); return boundary == NULL ? NULL : boundary->part; } } @@ -596,11 +607,11 @@ end_boundary = msg[0] == '-' && msg[1] == '-'; /* skip the rest of the line */ - message_skip_line(input, boundary_size); + message_skip_line(input, boundary_size, !end_boundary); if (end_boundary) { /* skip the footer */ - return message_parse_body(input, boundaries, boundary_size); + return message_parse_body(input, boundary->next, boundary_size); } return boundary == NULL ? NULL : boundary->part;