Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-mail/message-parser.c @ 9658:8ba4253adc9b HEAD tip
*-login: SSL connections didn't get closed when the client got destroyed.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 08 May 2014 16:41:29 +0300 |
parents | a56eb5db0d87 |
children |
rev | line source |
---|---|
9532
00cd9aacd03c
Updated copyright notices to include year 2010.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
1 /* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */ |
0 | 2 |
3 #include "lib.h" | |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
4 #include "str.h" |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
579
diff
changeset
|
5 #include "istream.h" |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
6 #include "rfc822-parser.h" |
7950
3412c43d6707
Merge RFC 2231 header continuations in BODY/BODYSTRUCTURE replies. Also use
Timo Sirainen <tss@iki.fi>
parents:
7938
diff
changeset
|
7 #include "rfc2231-parser.h" |
0 | 8 #include "message-parser.h" |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
9 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
10 /* RFC-2046 requires boundaries are max. 70 chars + "--" prefix + "--" suffix. |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
11 We'll add a bit more just in case. */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
12 #define BOUNDARY_END_MAX_LEN (70 + 2 + 2 + 10) |
0 | 13 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
14 struct message_boundary { |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
15 struct message_boundary *next; |
0 | 16 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
17 struct message_part *part; |
0 | 18 const char *boundary; |
184 | 19 size_t len; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
20 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
21 unsigned int epilogue_found:1; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
22 }; |
0 | 23 |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
24 struct message_parser_ctx { |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
25 pool_t parser_pool, part_pool; |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
26 struct istream *input; |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
27 struct message_part *parts, *part; |
0 | 28 |
5522
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
29 enum message_header_parser_flags hdr_flags; |
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
30 enum message_parser_flags flags; |
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
31 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
32 const char *last_boundary; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
33 struct message_boundary *boundaries; |
0 | 34 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
35 size_t skip; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
36 char last_chr; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
37 unsigned int want_count; |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
38 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
39 struct message_header_parser_ctx *hdr_parser_ctx; |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
40 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
41 int (*parse_next_block)(struct message_parser_ctx *ctx, |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
42 struct message_block *block_r); |
1534
676995d7c0ca
IMAP protocol doesn't allow server to send NULs to client. Send ascii #128
Timo Sirainen <tss@iki.fi>
parents:
1532
diff
changeset
|
43 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
44 unsigned int part_seen_content_type:1; |
7243
289765861d66
Changed message_parser_deinit() to return -1 if the parser was using
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
45 unsigned int broken:1; |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
46 unsigned int eof:1; |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
47 }; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
48 |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4673
diff
changeset
|
49 message_part_header_callback_t *null_message_part_header_callback = NULL; |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4673
diff
changeset
|
50 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
51 static int parse_next_header_init(struct message_parser_ctx *ctx, |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
52 struct message_block *block_r); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
53 static int parse_next_body_to_boundary(struct message_parser_ctx *ctx, |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
54 struct message_block *block_r); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
55 static int parse_next_body_to_eof(struct message_parser_ctx *ctx, |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
56 struct message_block *block_r); |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
57 static int preparsed_parse_next_header_init(struct message_parser_ctx *ctx, |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
58 struct message_block *block_r); |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
59 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
60 static struct message_boundary * |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
61 boundary_find(struct message_boundary *boundaries, |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
62 const unsigned char *data, size_t len) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
63 { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
64 /* As MIME spec says: search from latest one to oldest one so that we |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
65 don't break if the same boundary is used in nested parts. Also the |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
66 full message line doesn't have to match the boundary, only the |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
67 beginning. */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
68 while (boundaries != NULL) { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
69 if (boundaries->len <= len && |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
70 memcmp(boundaries->boundary, data, boundaries->len) == 0) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
71 return boundaries; |
0 | 72 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
73 boundaries = boundaries->next; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
74 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
75 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
76 return NULL; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
77 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
78 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
79 static void parse_body_add_block(struct message_parser_ctx *ctx, |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
80 struct message_block *block) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
81 { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
82 unsigned int missing_cr_count = 0; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
83 const unsigned char *data = block->data; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
84 size_t i; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
85 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
86 block->hdr = NULL; |
0 | 87 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
88 for (i = 0; i < block->size; i++) { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
89 if (data[i] <= '\n') { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
90 if (data[i] == '\n') { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
91 ctx->part->body_size.lines++; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
92 if ((i > 0 && data[i-1] != '\r') || |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
93 (i == 0 && ctx->last_chr != '\r')) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
94 missing_cr_count++; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
95 } else if (data[i] == '\0') |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
96 ctx->part->flags |= MESSAGE_PART_FLAG_HAS_NULS; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
97 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
98 } |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
99 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
100 ctx->part->body_size.physical_size += block->size; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
101 ctx->part->body_size.virtual_size += block->size + missing_cr_count; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
102 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
103 ctx->last_chr = data[i-1]; |
5244 | 104 ctx->skip += block->size; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
105 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
106 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
107 static int message_parser_read_more(struct message_parser_ctx *ctx, |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
108 struct message_block *block_r, bool *full_r) |
0 | 109 { |
5112 | 110 int ret; |
111 | |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
112 if (ctx->skip > 0) { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
113 i_stream_skip(ctx->input, ctx->skip); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
114 ctx->skip = 0; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
115 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
116 |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
117 *full_r = FALSE; |
5112 | 118 ret = i_stream_read_data(ctx->input, &block_r->data, |
119 &block_r->size, ctx->want_count); | |
6586
d6b2343238f9
Handle lines longer than 8192 bytes without going to infinite loop.
Timo Sirainen <tss@iki.fi>
parents:
6529
diff
changeset
|
120 if (ret <= 0) { |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
121 switch (ret) { |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
122 case 0: |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
123 if (!ctx->input->eof) { |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
124 i_assert(!ctx->input->blocking); |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
125 return 0; |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
126 } |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
127 break; |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
128 case -1: |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
129 i_assert(ctx->input->eof || |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
130 ctx->input->stream_errno != 0); |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
131 ctx->eof = TRUE; |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
132 if (block_r->size != 0) { |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
133 /* EOF, but we still have some data. |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
134 return it. */ |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
135 return 1; |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
136 } |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
137 return -1; |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
138 case -2: |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
139 *full_r = TRUE; |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
140 break; |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
141 default: |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
142 i_unreached(); |
5112 | 143 } |
5109 | 144 } |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
145 |
9655
a56eb5db0d87
message parser: Fixed infinite loop when parsing a specific message.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
146 if (!*full_r) { |
a56eb5db0d87
message parser: Fixed infinite loop when parsing a specific message.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
147 /* reset number of wanted characters if we actually got them */ |
a56eb5db0d87
message parser: Fixed infinite loop when parsing a specific message.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
148 ctx->want_count = 1; |
a56eb5db0d87
message parser: Fixed infinite loop when parsing a specific message.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
149 } |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
150 return 1; |
0 | 151 } |
152 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
153 static struct message_part * |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
154 message_part_append(pool_t pool, struct message_part *parent) |
0 | 155 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
156 struct message_part *part, **list; |
0 | 157 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
158 part = p_new(pool, struct message_part, 1); |
0 | 159 part->parent = parent; |
160 | |
212
4327b1266604
message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
161 /* set child position */ |
4327b1266604
message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
162 part->physical_pos = |
4327b1266604
message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
163 parent->physical_pos + |
4327b1266604
message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
164 parent->body_size.physical_size + |
4327b1266604
message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
165 parent->header_size.physical_size; |
4327b1266604
message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
166 |
0 | 167 list = &part->parent->children; |
168 while (*list != NULL) | |
169 list = &(*list)->next; | |
170 | |
171 *list = part; | |
172 return part; | |
173 } | |
174 | |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
175 static void parse_next_body_multipart_init(struct message_parser_ctx *ctx) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
176 { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
177 struct message_boundary *b; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
178 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
179 b = p_new(ctx->parser_pool, struct message_boundary, 1); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
180 b->part = ctx->part; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
181 b->boundary = ctx->last_boundary; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
182 b->len = strlen(b->boundary); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
183 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
184 b->next = ctx->boundaries; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
185 ctx->boundaries = b; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
186 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
187 ctx->last_boundary = NULL; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
188 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
189 |
7214
2d58b1c2dfd0
The header ending a message/rfc822 doesn't belong to its child MIME part.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
190 static int parse_next_body_message_rfc822_init(struct message_parser_ctx *ctx, |
2d58b1c2dfd0
The header ending a message/rfc822 doesn't belong to its child MIME part.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
191 struct message_block *block_r) |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
192 { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
193 ctx->part = message_part_append(ctx->part_pool, ctx->part); |
7214
2d58b1c2dfd0
The header ending a message/rfc822 doesn't belong to its child MIME part.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
194 return parse_next_header_init(ctx, block_r); |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
195 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
196 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
197 static int |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
198 boundary_line_find(struct message_parser_ctx *ctx, |
5109 | 199 const unsigned char *data, size_t size, bool full, |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
200 struct message_boundary **boundary_r) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
201 { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
202 size_t i; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
203 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
204 *boundary_r = NULL; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
205 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
206 if (size < 2) { |
5109 | 207 i_assert(!full); |
208 | |
209 if (ctx->input->eof) | |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
210 return -1; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
211 ctx->want_count = 2; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
212 return 0; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
213 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
214 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
215 if (data[0] != '-' || data[1] != '-') { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
216 /* not a boundary, just skip this line */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
217 return -1; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
218 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
219 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
220 /* need to find the end of line */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
221 for (i = 2; i < size; i++) { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
222 if (data[i] == '\n') |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
223 break; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
224 } |
5109 | 225 if (i == size && i < BOUNDARY_END_MAX_LEN && |
226 !ctx->input->eof && !full) { | |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
227 /* no LF found */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
228 ctx->want_count = BOUNDARY_END_MAX_LEN; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
229 return 0; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
230 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
231 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
232 data += 2; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
233 size -= 2; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
234 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
235 *boundary_r = boundary_find(ctx->boundaries, data, size); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
236 if (*boundary_r == NULL) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
237 return -1; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
238 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
239 (*boundary_r)->epilogue_found = |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
240 size >= (*boundary_r)->len + 2 && |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
241 memcmp(data + (*boundary_r)->len, "--", 2) == 0; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
242 return 1; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
243 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
244 |
6900
950ce0b5edb5
Message parser wasn't returning body blocks correctly, causing problems with
Timo Sirainen <tss@iki.fi>
parents:
6729
diff
changeset
|
245 static int parse_next_mime_header_init(struct message_parser_ctx *ctx, |
950ce0b5edb5
Message parser wasn't returning body blocks correctly, causing problems with
Timo Sirainen <tss@iki.fi>
parents:
6729
diff
changeset
|
246 struct message_block *block_r) |
950ce0b5edb5
Message parser wasn't returning body blocks correctly, causing problems with
Timo Sirainen <tss@iki.fi>
parents:
6729
diff
changeset
|
247 { |
950ce0b5edb5
Message parser wasn't returning body blocks correctly, causing problems with
Timo Sirainen <tss@iki.fi>
parents:
6729
diff
changeset
|
248 ctx->part = message_part_append(ctx->part_pool, ctx->part); |
950ce0b5edb5
Message parser wasn't returning body blocks correctly, causing problems with
Timo Sirainen <tss@iki.fi>
parents:
6729
diff
changeset
|
249 ctx->part->flags |= MESSAGE_PART_FLAG_IS_MIME; |
950ce0b5edb5
Message parser wasn't returning body blocks correctly, causing problems with
Timo Sirainen <tss@iki.fi>
parents:
6729
diff
changeset
|
250 |
950ce0b5edb5
Message parser wasn't returning body blocks correctly, causing problems with
Timo Sirainen <tss@iki.fi>
parents:
6729
diff
changeset
|
251 return parse_next_header_init(ctx, block_r); |
950ce0b5edb5
Message parser wasn't returning body blocks correctly, causing problems with
Timo Sirainen <tss@iki.fi>
parents:
6729
diff
changeset
|
252 } |
950ce0b5edb5
Message parser wasn't returning body blocks correctly, causing problems with
Timo Sirainen <tss@iki.fi>
parents:
6729
diff
changeset
|
253 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
254 static int parse_next_body_skip_boundary_line(struct message_parser_ctx *ctx, |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
255 struct message_block *block_r) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
256 { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
257 size_t i; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
258 int ret; |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
259 bool full; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
260 |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
261 if ((ret = message_parser_read_more(ctx, block_r, &full)) <= 0) |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
262 return ret; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
263 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
264 for (i = 0; i < block_r->size; i++) { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
265 if (block_r->data[i] == '\n') |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
266 break; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
267 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
268 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
269 if (i == block_r->size) { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
270 parse_body_add_block(ctx, block_r); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
271 return 1; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
272 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
273 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
274 /* found the LF */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
275 block_r->size = i + 1; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
276 parse_body_add_block(ctx, block_r); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
277 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
278 /* a new MIME part begins */ |
6900
950ce0b5edb5
Message parser wasn't returning body blocks correctly, causing problems with
Timo Sirainen <tss@iki.fi>
parents:
6729
diff
changeset
|
279 ctx->parse_next_block = parse_next_mime_header_init; |
950ce0b5edb5
Message parser wasn't returning body blocks correctly, causing problems with
Timo Sirainen <tss@iki.fi>
parents:
6729
diff
changeset
|
280 return 1; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
281 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
282 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
283 static int parse_part_finish(struct message_parser_ctx *ctx, |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
284 struct message_boundary *boundary, |
5305
43d3955ce03f
Fixes to counting MIME part sizes
Timo Sirainen <tss@iki.fi>
parents:
5244
diff
changeset
|
285 struct message_block *block_r, bool first_line) |
0 | 286 { |
5111 | 287 struct message_part *part; |
288 | |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
289 /* get back to parent MIME part, summing the child MIME part sizes |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
290 into parent's body sizes */ |
5111 | 291 for (part = ctx->part; part != boundary->part; part = part->parent) { |
292 message_size_add(&part->parent->body_size, &part->body_size); | |
293 message_size_add(&part->parent->body_size, &part->header_size); | |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
294 } |
5111 | 295 ctx->part = part; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
296 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
297 if (boundary->epilogue_found) { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
298 /* this boundary isn't needed anymore */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
299 ctx->boundaries = boundary->next; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
300 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
301 if (ctx->boundaries != NULL) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
302 ctx->parse_next_block = parse_next_body_to_boundary; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
303 else |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
304 ctx->parse_next_block = parse_next_body_to_eof; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
305 return ctx->parse_next_block(ctx, block_r); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
306 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
307 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
308 /* forget about the boundaries we possibly skipped */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
309 ctx->boundaries = boundary; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
310 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
311 /* the boundary itself should already be in buffer. add that. */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
312 block_r->data = i_stream_get_data(ctx->input, &block_r->size); |
5305
43d3955ce03f
Fixes to counting MIME part sizes
Timo Sirainen <tss@iki.fi>
parents:
5244
diff
changeset
|
313 i_assert(block_r->size >= ctx->skip + 2 + boundary->len + |
43d3955ce03f
Fixes to counting MIME part sizes
Timo Sirainen <tss@iki.fi>
parents:
5244
diff
changeset
|
314 (first_line ? 0 : 1)); |
43d3955ce03f
Fixes to counting MIME part sizes
Timo Sirainen <tss@iki.fi>
parents:
5244
diff
changeset
|
315 block_r->data += ctx->skip; |
43d3955ce03f
Fixes to counting MIME part sizes
Timo Sirainen <tss@iki.fi>
parents:
5244
diff
changeset
|
316 /* [\n]--<boundary> */ |
43d3955ce03f
Fixes to counting MIME part sizes
Timo Sirainen <tss@iki.fi>
parents:
5244
diff
changeset
|
317 block_r->size = (first_line ? 0 : 1) + 2 + boundary->len; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
318 parse_body_add_block(ctx, block_r); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
319 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
320 ctx->parse_next_block = parse_next_body_skip_boundary_line; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
321 return 1; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
322 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
323 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
324 static int parse_next_body_to_boundary(struct message_parser_ctx *ctx, |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
325 struct message_block *block_r) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
326 { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
327 struct message_boundary *boundary = NULL; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
328 const unsigned char *data; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
329 size_t i, boundary_start; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
330 int ret; |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
331 bool full; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
332 |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
333 if ((ret = message_parser_read_more(ctx, block_r, &full)) <= 0) |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
334 return ret; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
335 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
336 data = block_r->data; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
337 if (ctx->last_chr == '\n') { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
338 /* handle boundary in first line of message. alternatively |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
339 it's an empty line. */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
340 ret = boundary_line_find(ctx, block_r->data, |
5109 | 341 block_r->size, full, &boundary); |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
342 if (ret >= 0) { |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
343 return ret == 0 ? 0 : |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
344 parse_part_finish(ctx, boundary, block_r, TRUE); |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
345 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
346 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
347 |
8103
360ade35792f
Fixed infinite looping when parsing some (not all) broken multipart mails
Timo Sirainen <tss@iki.fi>
parents:
7950
diff
changeset
|
348 i_assert(block_r->size > 0); |
5109 | 349 for (i = boundary_start = 0; i < block_r->size; i++) { |
5411 | 350 /* skip to beginning of the next line. the first line was |
351 handled already. */ | |
5440 | 352 size_t next_line_idx = block_r->size; |
353 | |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
354 for (; i < block_r->size; i++) { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
355 if (data[i] == '\n') { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
356 boundary_start = i; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
357 if (i > 0 && data[i-1] == '\r') |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
358 boundary_start--; |
5440 | 359 next_line_idx = i + 1; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
360 break; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
361 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
362 } |
5411 | 363 if (boundary_start != 0) { |
364 /* we can skip the first lines. input buffer can't be | |
365 full anymore. */ | |
5109 | 366 full = FALSE; |
6586
d6b2343238f9
Handle lines longer than 8192 bytes without going to infinite loop.
Timo Sirainen <tss@iki.fi>
parents:
6529
diff
changeset
|
367 } else if (next_line_idx == block_r->size) { |
d6b2343238f9
Handle lines longer than 8192 bytes without going to infinite loop.
Timo Sirainen <tss@iki.fi>
parents:
6529
diff
changeset
|
368 /* no linefeeds in this block. we can just skip it. */ |
d6b2343238f9
Handle lines longer than 8192 bytes without going to infinite loop.
Timo Sirainen <tss@iki.fi>
parents:
6529
diff
changeset
|
369 boundary_start = block_r->size; |
d6b2343238f9
Handle lines longer than 8192 bytes without going to infinite loop.
Timo Sirainen <tss@iki.fi>
parents:
6529
diff
changeset
|
370 full = FALSE; |
5411 | 371 } |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
372 |
5440 | 373 ret = boundary_line_find(ctx, block_r->data + next_line_idx, |
374 block_r->size - next_line_idx, full, | |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
375 &boundary); |
5109 | 376 if (ret >= 0) { |
377 /* found / need more data */ | |
5112 | 378 if (ret == 0 && boundary_start == 0) |
5440 | 379 ctx->want_count += next_line_idx; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
380 break; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
381 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
382 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
383 |
5111 | 384 if (i >= block_r->size) { |
5109 | 385 /* the boundary wasn't found from this data block, |
386 we'll need more data. */ | |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
387 ret = 0; |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
388 ctx->want_count = (block_r->size - boundary_start) + 1; |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
389 } else { |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
390 /* found / need more data */ |
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
391 i_assert(ret >= 0); |
5109 | 392 } |
393 i_assert(!(ret == 0 && full)); | |
394 | |
8237
5adb665bfc0c
Earlier changes broke message parsing near EOF.
Timo Sirainen <tss@iki.fi>
parents:
8128
diff
changeset
|
395 if (ret > 0 || (ret == 0 && !ctx->eof)) { |
5adb665bfc0c
Earlier changes broke message parsing near EOF.
Timo Sirainen <tss@iki.fi>
parents:
8128
diff
changeset
|
396 /* a) we found the boundary |
5adb665bfc0c
Earlier changes broke message parsing near EOF.
Timo Sirainen <tss@iki.fi>
parents:
8128
diff
changeset
|
397 b) we need more data and haven't reached EOF yet |
5adb665bfc0c
Earlier changes broke message parsing near EOF.
Timo Sirainen <tss@iki.fi>
parents:
8128
diff
changeset
|
398 so leave CR+LF + last line to buffer */ |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
399 block_r->size = boundary_start; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
400 } |
6904
275d22eb25ba
Another fix to returning body blocks.
Timo Sirainen <tss@iki.fi>
parents:
6900
diff
changeset
|
401 if (block_r->size != 0) { |
5244 | 402 parse_body_add_block(ctx, block_r); |
6904
275d22eb25ba
Another fix to returning body blocks.
Timo Sirainen <tss@iki.fi>
parents:
6900
diff
changeset
|
403 return 1; |
275d22eb25ba
Another fix to returning body blocks.
Timo Sirainen <tss@iki.fi>
parents:
6900
diff
changeset
|
404 } |
275d22eb25ba
Another fix to returning body blocks.
Timo Sirainen <tss@iki.fi>
parents:
6900
diff
changeset
|
405 return ret <= 0 ? ret : |
5305
43d3955ce03f
Fixes to counting MIME part sizes
Timo Sirainen <tss@iki.fi>
parents:
5244
diff
changeset
|
406 parse_part_finish(ctx, boundary, block_r, FALSE); |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
407 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
408 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
409 static int parse_next_body_to_eof(struct message_parser_ctx *ctx, |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
410 struct message_block *block_r) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
411 { |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
412 bool full; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
413 int ret; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
414 |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
415 if ((ret = message_parser_read_more(ctx, block_r, &full)) <= 0) |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
416 return ret; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
417 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
418 parse_body_add_block(ctx, block_r); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
419 return 1; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
420 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
421 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
422 static void parse_content_type(struct message_parser_ctx *ctx, |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
423 struct message_header_line *hdr) |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
424 { |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
425 struct rfc822_parser_context parser; |
7950
3412c43d6707
Merge RFC 2231 header continuations in BODY/BODYSTRUCTURE replies. Also use
Timo Sirainen <tss@iki.fi>
parents:
7938
diff
changeset
|
426 const char *const *results; |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
427 string_t *content_type; |
0 | 428 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
429 if (ctx->part_seen_content_type) |
0 | 430 return; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
431 ctx->part_seen_content_type = TRUE; |
0 | 432 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
433 rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
434 (void)rfc822_skip_lwsp(&parser); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
435 |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
436 content_type = t_str_new(64); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
437 if (rfc822_parse_content_type(&parser, content_type) < 0) |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
438 return; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
439 |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
440 if (strcasecmp(str_c(content_type), "message/rfc822") == 0) |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
441 ctx->part->flags |= MESSAGE_PART_FLAG_MESSAGE_RFC822; |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
442 else if (strncasecmp(str_c(content_type), "text", 4) == 0 && |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
443 (str_len(content_type) == 4 || |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
444 str_data(content_type)[4] == '/')) |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
445 ctx->part->flags |= MESSAGE_PART_FLAG_TEXT; |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
446 else if (strncasecmp(str_c(content_type), "multipart/", 10) == 0) { |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
447 ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART; |
0 | 448 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
449 if (strcasecmp(str_c(content_type)+10, "digest") == 0) |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
450 ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART_DIGEST; |
0 | 451 } |
452 | |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
453 if ((ctx->part->flags & MESSAGE_PART_FLAG_MULTIPART) == 0 || |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
454 ctx->last_boundary != NULL) |
0 | 455 return; |
456 | |
7950
3412c43d6707
Merge RFC 2231 header continuations in BODY/BODYSTRUCTURE replies. Also use
Timo Sirainen <tss@iki.fi>
parents:
7938
diff
changeset
|
457 (void)rfc2231_parse(&parser, &results); |
3412c43d6707
Merge RFC 2231 header continuations in BODY/BODYSTRUCTURE replies. Also use
Timo Sirainen <tss@iki.fi>
parents:
7938
diff
changeset
|
458 for (; *results != NULL; results += 2) { |
3412c43d6707
Merge RFC 2231 header continuations in BODY/BODYSTRUCTURE replies. Also use
Timo Sirainen <tss@iki.fi>
parents:
7938
diff
changeset
|
459 if (strcasecmp(results[0], "boundary") == 0) { |
3412c43d6707
Merge RFC 2231 header continuations in BODY/BODYSTRUCTURE replies. Also use
Timo Sirainen <tss@iki.fi>
parents:
7938
diff
changeset
|
460 ctx->last_boundary = |
3412c43d6707
Merge RFC 2231 header continuations in BODY/BODYSTRUCTURE replies. Also use
Timo Sirainen <tss@iki.fi>
parents:
7938
diff
changeset
|
461 p_strdup(ctx->parser_pool, results[1]); |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
462 break; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
463 } |
0 | 464 } |
465 } | |
466 | |
874 | 467 #define MUTEX_FLAGS \ |
468 (MESSAGE_PART_FLAG_MESSAGE_RFC822 | MESSAGE_PART_FLAG_MULTIPART) | |
469 | |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
470 static int parse_next_header(struct message_parser_ctx *ctx, |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
471 struct message_block *block_r) |
0 | 472 { |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
473 struct message_part *part = ctx->part; |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
474 struct message_header_line *hdr; |
6654 | 475 size_t size; |
2430
7c1dc4a7db3a
message_parse_header_next() can now return "need more data" with nonblocking
Timo Sirainen <tss@iki.fi>
parents:
2404
diff
changeset
|
476 int ret; |
0 | 477 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
478 if (ctx->skip > 0) { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
479 i_stream_skip(ctx->input, ctx->skip); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
480 ctx->skip = 0; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
481 } |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
482 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
483 ret = message_parse_header_next(ctx->hdr_parser_ctx, &hdr); |
6654 | 484 if (ret == 0 || (ret < 0 && ctx->input->stream_errno != 0)) { |
485 (void)i_stream_get_data(ctx->input, &size); | |
486 ctx->want_count = size + 1; | |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
487 return ret; |
6654 | 488 } |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
489 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
490 if (hdr != NULL) { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
491 if (hdr->eoh) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
492 ; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
493 else if (strcasecmp(hdr->name, "Mime-Version") == 0) { |
1618
149ade487f48
Ignore Content-* headers if there's no MIME-Version header. Note that this
Timo Sirainen <tss@iki.fi>
parents:
1543
diff
changeset
|
494 /* it's MIME. Content-* headers are valid */ |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
495 part->flags |= MESSAGE_PART_FLAG_IS_MIME; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
496 } else if (strcasecmp(hdr->name, "Content-Type") == 0) { |
6156
e18086698ebf
By default assume MIME message if Content-Type: exists even if Mime-Version:
Timo Sirainen <tss@iki.fi>
parents:
6117
diff
changeset
|
497 if ((ctx->flags & |
e18086698ebf
By default assume MIME message if Content-Type: exists even if Mime-Version:
Timo Sirainen <tss@iki.fi>
parents:
6117
diff
changeset
|
498 MESSAGE_PARSER_FLAG_MIME_VERSION_STRICT) == 0) |
e18086698ebf
By default assume MIME message if Content-Type: exists even if Mime-Version:
Timo Sirainen <tss@iki.fi>
parents:
6117
diff
changeset
|
499 part->flags |= MESSAGE_PART_FLAG_IS_MIME; |
e18086698ebf
By default assume MIME message if Content-Type: exists even if Mime-Version:
Timo Sirainen <tss@iki.fi>
parents:
6117
diff
changeset
|
500 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
501 if (hdr->continues) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
502 hdr->use_full_value = TRUE; |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7214
diff
changeset
|
503 else T_BEGIN { |
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7214
diff
changeset
|
504 parse_content_type(ctx, hdr); |
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7214
diff
changeset
|
505 } T_END; |
1618
149ade487f48
Ignore Content-* headers if there's no MIME-Version header. Note that this
Timo Sirainen <tss@iki.fi>
parents:
1543
diff
changeset
|
506 } |
149ade487f48
Ignore Content-* headers if there's no MIME-Version header. Note that this
Timo Sirainen <tss@iki.fi>
parents:
1543
diff
changeset
|
507 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
508 block_r->hdr = hdr; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
509 block_r->size = 0; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
510 return 1; |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
511 } |
1618
149ade487f48
Ignore Content-* headers if there's no MIME-Version header. Note that this
Timo Sirainen <tss@iki.fi>
parents:
1543
diff
changeset
|
512 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
513 /* end of headers */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
514 if ((part->flags & MESSAGE_PART_FLAG_MULTIPART) != 0 && |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
515 ctx->last_boundary == NULL) { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
516 /* multipart type but no message boundary */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
517 part->flags = 0; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
518 } |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
519 if ((part->flags & MESSAGE_PART_FLAG_IS_MIME) == 0) { |
1618
149ade487f48
Ignore Content-* headers if there's no MIME-Version header. Note that this
Timo Sirainen <tss@iki.fi>
parents:
1543
diff
changeset
|
520 /* It's not MIME. Reset everything we found from |
149ade487f48
Ignore Content-* headers if there's no MIME-Version header. Note that this
Timo Sirainen <tss@iki.fi>
parents:
1543
diff
changeset
|
521 Content-Type. */ |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
522 part->flags = 0; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
523 ctx->last_boundary = NULL; |
1618
149ade487f48
Ignore Content-* headers if there's no MIME-Version header. Note that this
Timo Sirainen <tss@iki.fi>
parents:
1543
diff
changeset
|
524 } |
874 | 525 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
526 if (!ctx->part_seen_content_type || |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
527 (part->flags & MESSAGE_PART_FLAG_IS_MIME) == 0) { |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
528 if (part->parent != NULL && |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
529 (part->parent->flags & |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
530 MESSAGE_PART_FLAG_MULTIPART_DIGEST) != 0) { |
0 | 531 /* when there's no content-type specified and we're |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
532 below multipart/digest, assume message/rfc822 |
0 | 533 content-type */ |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
534 part->flags |= MESSAGE_PART_FLAG_MESSAGE_RFC822; |
0 | 535 } else { |
536 /* otherwise we default to text/plain */ | |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
537 part->flags |= MESSAGE_PART_FLAG_TEXT; |
0 | 538 } |
539 } | |
540 | |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
541 if (message_parse_header_has_nuls(ctx->hdr_parser_ctx)) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
542 part->flags |= MESSAGE_PART_FLAG_HAS_NULS; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
543 message_parse_header_deinit(&ctx->hdr_parser_ctx); |
0 | 544 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
545 i_assert((part->flags & MUTEX_FLAGS) != MUTEX_FLAGS); |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
546 |
5244 | 547 ctx->last_chr = '\n'; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
548 if (ctx->last_boundary != NULL) { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
549 parse_next_body_multipart_init(ctx); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
550 ctx->parse_next_block = parse_next_body_to_boundary; |
7214
2d58b1c2dfd0
The header ending a message/rfc822 doesn't belong to its child MIME part.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
551 } else if (part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) |
2d58b1c2dfd0
The header ending a message/rfc822 doesn't belong to its child MIME part.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
552 ctx->parse_next_block = parse_next_body_message_rfc822_init; |
2d58b1c2dfd0
The header ending a message/rfc822 doesn't belong to its child MIME part.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
553 else if (ctx->boundaries != NULL) |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
554 ctx->parse_next_block = parse_next_body_to_boundary; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
555 else |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
556 ctx->parse_next_block = parse_next_body_to_eof; |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
557 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
558 ctx->want_count = 1; |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
559 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
560 /* return empty block as end of headers */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
561 block_r->hdr = NULL; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
562 block_r->size = 0; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
563 return 1; |
0 | 564 } |
565 | |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
566 static int parse_next_header_init(struct message_parser_ctx *ctx, |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
567 struct message_block *block_r) |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
568 { |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
569 i_assert(ctx->hdr_parser_ctx == NULL); |
1253
39b899338c99
A few small fixes to MIME and mail address parsers.
Timo Sirainen <tss@iki.fi>
parents:
1061
diff
changeset
|
570 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
571 ctx->hdr_parser_ctx = |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
572 message_parse_header_init(ctx->input, &ctx->part->header_size, |
5522
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
573 ctx->hdr_flags); |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
574 ctx->part_seen_content_type = FALSE; |
0 | 575 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
576 ctx->parse_next_block = parse_next_header; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
577 return parse_next_header(ctx, block_r); |
0 | 578 } |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
579 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6156
diff
changeset
|
580 static int preparsed_parse_eof(struct message_parser_ctx *ctx ATTR_UNUSED, |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6156
diff
changeset
|
581 struct message_block *block_r ATTR_UNUSED) |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
582 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
583 return -1; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
584 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
585 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
586 static void preparsed_skip_to_next(struct message_parser_ctx *ctx) |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
587 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
588 ctx->parse_next_block = preparsed_parse_next_header_init; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
589 while (ctx->part != NULL) { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
590 if (ctx->part->next != NULL) { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
591 ctx->part = ctx->part->next; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
592 break; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
593 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
594 ctx->part = ctx->part->parent; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
595 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
596 if (ctx->part == NULL) |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
597 ctx->parse_next_block = preparsed_parse_eof; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
598 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
599 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
600 static int preparsed_parse_body_finish(struct message_parser_ctx *ctx, |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
601 struct message_block *block_r) |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
602 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
603 i_stream_skip(ctx->input, ctx->skip); |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
604 ctx->skip = 0; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
605 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
606 preparsed_skip_to_next(ctx); |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
607 return ctx->parse_next_block(ctx, block_r); |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
608 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
609 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
610 static int preparsed_parse_body_more(struct message_parser_ctx *ctx, |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
611 struct message_block *block_r) |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
612 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
613 uoff_t end_offset = ctx->part->physical_pos + |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
614 ctx->part->header_size.physical_size + |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
615 ctx->part->body_size.physical_size; |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
616 bool full; |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
617 int ret; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
618 |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
619 if ((ret = message_parser_read_more(ctx, block_r, &full)) <= 0) |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
620 return ret; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
621 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
622 if (ctx->input->v_offset + block_r->size >= end_offset) { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
623 block_r->size = end_offset - ctx->input->v_offset; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
624 ctx->parse_next_block = preparsed_parse_body_finish; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
625 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
626 ctx->skip = block_r->size; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
627 return 1; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
628 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
629 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
630 static int preparsed_parse_body_init(struct message_parser_ctx *ctx, |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
631 struct message_block *block_r) |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
632 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
633 uoff_t offset = ctx->part->physical_pos + |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
634 ctx->part->header_size.physical_size; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
635 |
7597
f27e6f583817
If cached message part showed header's size to be smaller than in reality,
Timo Sirainen <tss@iki.fi>
parents:
7272
diff
changeset
|
636 if (offset < ctx->input->v_offset) { |
f27e6f583817
If cached message part showed header's size to be smaller than in reality,
Timo Sirainen <tss@iki.fi>
parents:
7272
diff
changeset
|
637 /* header was actually larger than the cached size suggested */ |
f27e6f583817
If cached message part showed header's size to be smaller than in reality,
Timo Sirainen <tss@iki.fi>
parents:
7272
diff
changeset
|
638 ctx->broken = TRUE; |
f27e6f583817
If cached message part showed header's size to be smaller than in reality,
Timo Sirainen <tss@iki.fi>
parents:
7272
diff
changeset
|
639 return -1; |
f27e6f583817
If cached message part showed header's size to be smaller than in reality,
Timo Sirainen <tss@iki.fi>
parents:
7272
diff
changeset
|
640 } |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
641 i_stream_skip(ctx->input, offset - ctx->input->v_offset); |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
642 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
643 ctx->parse_next_block = preparsed_parse_body_more; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
644 return preparsed_parse_body_more(ctx, block_r); |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
645 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
646 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
647 static int preparsed_parse_finish_header(struct message_parser_ctx *ctx, |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
648 struct message_block *block_r) |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
649 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
650 if (ctx->part->children != NULL) { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
651 ctx->parse_next_block = preparsed_parse_next_header_init; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
652 ctx->part = ctx->part->children; |
5522
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
653 } else if ((ctx->flags & MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK) == 0) { |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
654 ctx->parse_next_block = preparsed_parse_body_init; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
655 } else { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
656 preparsed_skip_to_next(ctx); |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
657 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
658 return ctx->parse_next_block(ctx, block_r); |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
659 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
660 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
661 static int preparsed_parse_next_header(struct message_parser_ctx *ctx, |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
662 struct message_block *block_r) |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
663 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
664 struct message_header_line *hdr; |
6654 | 665 size_t size; |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
666 int ret; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
667 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
668 ret = message_parse_header_next(ctx->hdr_parser_ctx, &hdr); |
6654 | 669 if (ret == 0 || (ret < 0 && ctx->input->stream_errno != 0)) { |
670 (void)i_stream_get_data(ctx->input, &size); | |
671 ctx->want_count = size + 1; | |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
672 return ret; |
6654 | 673 } |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
674 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
675 if (hdr != NULL) { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
676 block_r->hdr = hdr; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
677 block_r->size = 0; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
678 return 1; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
679 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
680 message_parse_header_deinit(&ctx->hdr_parser_ctx); |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
681 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
682 ctx->parse_next_block = preparsed_parse_finish_header; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
683 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
684 /* return empty block as end of headers */ |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
685 block_r->hdr = NULL; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
686 block_r->size = 0; |
7243
289765861d66
Changed message_parser_deinit() to return -1 if the parser was using
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
687 |
289765861d66
Changed message_parser_deinit() to return -1 if the parser was using
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
688 i_assert(ctx->skip == 0); |
289765861d66
Changed message_parser_deinit() to return -1 if the parser was using
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
689 if (ctx->input->v_offset != ctx->part->physical_pos + |
8121
d95770cfd935
message_parser_init_from_parts(): If parts were broken, we may have assert-crashed.
Timo Sirainen <tss@iki.fi>
parents:
8103
diff
changeset
|
690 ctx->part->header_size.physical_size) { |
7243
289765861d66
Changed message_parser_deinit() to return -1 if the parser was using
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
691 ctx->broken = TRUE; |
8121
d95770cfd935
message_parser_init_from_parts(): If parts were broken, we may have assert-crashed.
Timo Sirainen <tss@iki.fi>
parents:
8103
diff
changeset
|
692 return -1; |
d95770cfd935
message_parser_init_from_parts(): If parts were broken, we may have assert-crashed.
Timo Sirainen <tss@iki.fi>
parents:
8103
diff
changeset
|
693 } |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
694 return 1; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
695 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
696 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
697 static int preparsed_parse_next_header_init(struct message_parser_ctx *ctx, |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
698 struct message_block *block_r) |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
699 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
700 i_assert(ctx->hdr_parser_ctx == NULL); |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
701 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
702 i_assert(ctx->part->physical_pos >= ctx->input->v_offset); |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
703 i_stream_skip(ctx->input, ctx->part->physical_pos - |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
704 ctx->input->v_offset); |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
705 |
5522
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
706 ctx->hdr_parser_ctx = |
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
707 message_parse_header_init(ctx->input, NULL, ctx->hdr_flags); |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
708 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
709 ctx->parse_next_block = preparsed_parse_next_header; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
710 return preparsed_parse_next_header(ctx, block_r); |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
711 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
712 |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
713 struct message_parser_ctx * |
5522
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
714 message_parser_init(pool_t part_pool, struct istream *input, |
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
715 enum message_header_parser_flags hdr_flags, |
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
716 enum message_parser_flags flags) |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
717 { |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
718 struct message_parser_ctx *ctx; |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
719 pool_t pool; |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
720 |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
721 pool = pool_alloconly_create("Message Parser", 1024); |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
722 ctx = p_new(pool, struct message_parser_ctx, 1); |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
723 ctx->parser_pool = pool; |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
724 ctx->part_pool = part_pool; |
5522
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
725 ctx->hdr_flags = hdr_flags; |
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
726 ctx->flags = flags; |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
727 ctx->input = input; |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
728 ctx->parts = ctx->part = part_pool == NULL ? NULL : |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
729 p_new(part_pool, struct message_part, 1); |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
730 ctx->parse_next_block = parse_next_header_init; |
6082
d62bddb414ef
ref/unref stream when parsing it.
Timo Sirainen <tss@iki.fi>
parents:
5989
diff
changeset
|
731 i_stream_ref(input); |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
732 return ctx; |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
733 } |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
734 |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
735 struct message_parser_ctx * |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
736 message_parser_init_from_parts(struct message_part *parts, |
5522
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
737 struct istream *input, |
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
738 enum message_header_parser_flags hdr_flags, |
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
739 enum message_parser_flags flags) |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
740 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
741 struct message_parser_ctx *ctx; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
742 |
5522
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
743 ctx = message_parser_init(NULL, input, hdr_flags, flags); |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
744 ctx->parts = ctx->part = parts; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
745 ctx->parse_next_block = preparsed_parse_next_header_init; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
746 return ctx; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
747 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
748 |
7243
289765861d66
Changed message_parser_deinit() to return -1 if the parser was using
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
749 int message_parser_deinit(struct message_parser_ctx **_ctx, |
289765861d66
Changed message_parser_deinit() to return -1 if the parser was using
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
750 struct message_part **parts_r) |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
751 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
752 struct message_parser_ctx *ctx = *_ctx; |
7243
289765861d66
Changed message_parser_deinit() to return -1 if the parser was using
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
753 int ret = ctx->broken ? -1 : 0; |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
754 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
755 *_ctx = NULL; |
7243
289765861d66
Changed message_parser_deinit() to return -1 if the parser was using
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
756 *parts_r = ctx->parts; |
289765861d66
Changed message_parser_deinit() to return -1 if the parser was using
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
757 |
7245 | 758 if (ctx->hdr_parser_ctx != NULL) |
759 message_parse_header_deinit(&ctx->hdr_parser_ctx); | |
6082
d62bddb414ef
ref/unref stream when parsing it.
Timo Sirainen <tss@iki.fi>
parents:
5989
diff
changeset
|
760 i_stream_unref(&ctx->input); |
6428
7cad076906eb
pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
761 pool_unref(&ctx->parser_pool); |
7243
289765861d66
Changed message_parser_deinit() to return -1 if the parser was using
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
762 return ret; |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
763 } |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
764 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
765 int message_parser_parse_next_block(struct message_parser_ctx *ctx, |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
766 struct message_block *block_r) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
767 { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
768 int ret; |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
769 bool eof = FALSE, full; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
770 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
771 while ((ret = ctx->parse_next_block(ctx, block_r)) == 0) { |
8128
fcf0c5ac5975
message parser: Cleaned up the code and another attempt at fixing infinite looping.
Timo Sirainen <tss@iki.fi>
parents:
8121
diff
changeset
|
772 ret = message_parser_read_more(ctx, block_r, &full); |
6586
d6b2343238f9
Handle lines longer than 8192 bytes without going to infinite loop.
Timo Sirainen <tss@iki.fi>
parents:
6529
diff
changeset
|
773 if (ret == 0) { |
d6b2343238f9
Handle lines longer than 8192 bytes without going to infinite loop.
Timo Sirainen <tss@iki.fi>
parents:
6529
diff
changeset
|
774 i_assert(!ctx->input->blocking); |
d6b2343238f9
Handle lines longer than 8192 bytes without going to infinite loop.
Timo Sirainen <tss@iki.fi>
parents:
6529
diff
changeset
|
775 return 0; |
d6b2343238f9
Handle lines longer than 8192 bytes without going to infinite loop.
Timo Sirainen <tss@iki.fi>
parents:
6529
diff
changeset
|
776 } |
d6b2343238f9
Handle lines longer than 8192 bytes without going to infinite loop.
Timo Sirainen <tss@iki.fi>
parents:
6529
diff
changeset
|
777 if (ret == -1) { |
d6b2343238f9
Handle lines longer than 8192 bytes without going to infinite loop.
Timo Sirainen <tss@iki.fi>
parents:
6529
diff
changeset
|
778 i_assert(!eof); |
d6b2343238f9
Handle lines longer than 8192 bytes without going to infinite loop.
Timo Sirainen <tss@iki.fi>
parents:
6529
diff
changeset
|
779 eof = TRUE; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
780 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
781 } |
5109 | 782 |
4673
f5bef033a9ac
message_parser_parse_next_block() returned body part wrong for first header
Timo Sirainen <tss@iki.fi>
parents:
4267
diff
changeset
|
783 block_r->part = ctx->part; |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
784 |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
785 if (ret < 0 && ctx->part != NULL) { |
7272 | 786 /* Successful EOF or unexpected failure */ |
787 i_assert(ctx->input->eof || ctx->input->closed || | |
7938
e06d4049d282
Message parser: Fixed assert-crash if cached MIME structure was broken.
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
788 ctx->input->stream_errno != 0 || ctx->broken); |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
789 while (ctx->part->parent != NULL) { |
4265
75d5843153f1
Added message_part to struct message_block and some cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
790 message_size_add(&ctx->part->parent->body_size, |
75d5843153f1
Added message_part to struct message_block and some cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
791 &ctx->part->body_size); |
4267
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
792 message_size_add(&ctx->part->parent->body_size, |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
793 &ctx->part->header_size); |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
794 ctx->part = ctx->part->parent; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
795 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
796 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
797 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
798 return ret; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
799 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
800 |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4673
diff
changeset
|
801 #undef message_parser_parse_header |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
802 void message_parser_parse_header(struct message_parser_ctx *ctx, |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
803 struct message_size *hdr_size, |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
804 message_part_header_callback_t *callback, |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
805 void *context) |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
806 { |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
807 struct message_block block; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
808 int ret; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
809 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
810 while ((ret = message_parser_parse_next_block(ctx, &block)) > 0) { |
4265
75d5843153f1
Added message_part to struct message_block and some cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
811 callback(block.part, block.hdr, context); |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
812 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
813 if (block.hdr == NULL) |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
814 break; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
815 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
816 i_assert(ret != 0); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
817 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
818 if (ret < 0) { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
819 /* well, can't return error so fake end of headers */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
820 callback(ctx->part, NULL, context); |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
821 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
822 |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
823 *hdr_size = ctx->part->header_size; |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
824 } |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
825 |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4673
diff
changeset
|
826 #undef message_parser_parse_body |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
827 void message_parser_parse_body(struct message_parser_ctx *ctx, |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
828 message_part_header_callback_t *hdr_callback, |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
829 void *context) |
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
830 { |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
831 struct message_block block; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
832 int ret; |
1697
ef79ce6507ff
Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents:
1689
diff
changeset
|
833 |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
834 while ((ret = message_parser_parse_next_block(ctx, &block)) > 0) { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
835 if (block.size == 0 && hdr_callback != NULL) |
4265
75d5843153f1
Added message_part to struct message_block and some cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
836 hdr_callback(block.part, block.hdr, context); |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
837 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
838 i_assert(ret != 0); |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
839 } |