Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-mail/message-parser.c @ 6411:6a64e64fa3a3 HEAD
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 16 Sep 2007 11:40:56 +0300 |
parents | e18086698ebf |
children | 7cad076906eb |
rev | line source |
---|---|
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
|
1 /* Copyright (C) 2002-2006 Timo Sirainen */ |
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" |
0 | 7 #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
|
8 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 /* 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
|
10 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
|
11 #define BOUNDARY_END_MAX_LEN (70 + 2 + 2 + 10) |
0 | 12 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
13 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
|
14 struct message_boundary *next; |
0 | 15 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
16 struct message_part *part; |
0 | 17 const char *boundary; |
184 | 18 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
|
19 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 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
|
21 }; |
0 | 22 |
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
|
23 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
|
24 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
|
25 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
|
26 struct message_part *parts, *part; |
0 | 27 |
5522
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
28 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
|
29 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
|
30 |
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
|
31 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
|
32 struct message_boundary *boundaries; |
0 | 33 |
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
|
34 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
|
35 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
|
36 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
|
37 |
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
|
38 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
|
39 |
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
|
40 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
|
41 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
|
42 |
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
|
43 unsigned int part_seen_content_type:1; |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
44 }; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
45 |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4673
diff
changeset
|
46 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
|
47 |
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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 |
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
|
57 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
|
58 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
|
59 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
|
60 { |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 /* 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 return boundaries; |
0 | 69 |
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
|
70 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
|
71 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
72 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 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
|
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 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
|
77 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
|
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 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
|
80 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
|
81 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
|
82 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 block->hdr = NULL; |
0 | 84 |
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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 (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
|
91 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
|
92 } 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
|
93 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
|
94 } |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 } |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
96 |
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
|
97 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
|
98 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
|
99 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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->last_chr = data[i-1]; |
5244 | 101 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
|
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 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
104 static int message_parser_read_more(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
|
105 struct message_block *block_r) |
0 | 106 { |
5112 | 107 int ret; |
108 | |
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
|
109 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
|
110 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
|
111 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
|
112 } |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 |
5112 | 114 ret = i_stream_read_data(ctx->input, &block_r->data, |
115 &block_r->size, ctx->want_count); | |
116 if (ret == -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
|
117 return -1; |
5112 | 118 |
119 if (ret == 0) { | |
120 if (!ctx->input->eof) { | |
121 i_assert(!ctx->input->blocking); | |
122 return 0; | |
123 } | |
5109 | 124 } |
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
|
125 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
126 ctx->want_count = 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
|
127 return 1; |
0 | 128 } |
129 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
130 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
|
131 message_part_append(pool_t pool, struct message_part *parent) |
0 | 132 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
133 struct message_part *part, **list; |
0 | 134 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
135 part = p_new(pool, struct message_part, 1); |
0 | 136 part->parent = parent; |
137 | |
212
4327b1266604
message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
138 /* set child position */ |
4327b1266604
message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
139 part->physical_pos = |
4327b1266604
message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
140 parent->physical_pos + |
4327b1266604
message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
141 parent->body_size.physical_size + |
4327b1266604
message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
142 parent->header_size.physical_size; |
4327b1266604
message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
143 |
0 | 144 list = &part->parent->children; |
145 while (*list != NULL) | |
146 list = &(*list)->next; | |
147 | |
148 *list = part; | |
149 return part; | |
150 } | |
151 | |
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
|
152 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
|
153 { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
154 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
|
155 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
156 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
|
157 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
|
158 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
|
159 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
|
160 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
161 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
|
162 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
|
163 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
164 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
|
165 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
166 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
167 static void parse_next_body_message_rfc822_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
|
168 { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
169 ctx->part = message_part_append(ctx->part_pool, 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
|
170 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
171 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
172 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
|
173 boundary_line_find(struct message_parser_ctx *ctx, |
5109 | 174 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
|
175 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
|
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 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
|
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 *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
|
180 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 if (size < 2) { |
5109 | 182 i_assert(!full); |
183 | |
184 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
|
185 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
|
186 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
|
187 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
|
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 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
190 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
|
191 /* 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
|
192 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
|
193 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
194 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 /* 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
|
196 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
|
197 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
|
198 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
|
199 } |
5109 | 200 if (i == size && i < BOUNDARY_END_MAX_LEN && |
201 !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
|
202 /* 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
|
203 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
|
204 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
|
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 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
207 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
|
208 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
|
209 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 *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
|
211 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
|
212 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
|
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 (*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
|
215 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
|
216 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
|
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 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
|
221 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
|
222 { |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 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
|
224 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
|
225 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
226 if ((ret = message_parser_read_more(ctx, block_r)) <= 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
|
227 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
|
228 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 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
|
230 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
|
231 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
|
232 } |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 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
|
235 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
|
236 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
|
237 } |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 /* 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
|
240 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
|
241 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
|
242 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 /* a new MIME part begins */ |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 ctx->part = message_part_append(ctx->part_pool, 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
|
245 ctx->part->flags |= MESSAGE_PART_FLAG_IS_MIME; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
246 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
247 ctx->parse_next_block = parse_next_header_init; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
248 return parse_next_header_init(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
|
249 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
250 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
251 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
|
252 struct message_boundary *boundary, |
5305
43d3955ce03f
Fixes to counting MIME part sizes
Timo Sirainen <tss@iki.fi>
parents:
5244
diff
changeset
|
253 struct message_block *block_r, bool first_line) |
0 | 254 { |
5111 | 255 struct message_part *part; |
256 | |
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
|
257 if (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
|
258 /* message ended unexpectedly */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
259 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
|
260 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
261 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 /* 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
|
263 into parent's body sizes */ |
5111 | 264 for (part = ctx->part; part != boundary->part; part = part->parent) { |
265 message_size_add(&part->parent->body_size, &part->body_size); | |
266 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
|
267 } |
5111 | 268 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
|
269 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 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
|
271 /* 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
|
272 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
|
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 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
280 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 /* 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
|
282 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
|
283 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 /* 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
|
285 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
|
286 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
|
287 (first_line ? 0 : 1)); |
43d3955ce03f
Fixes to counting MIME part sizes
Timo Sirainen <tss@iki.fi>
parents:
5244
diff
changeset
|
288 block_r->data += ctx->skip; |
43d3955ce03f
Fixes to counting MIME part sizes
Timo Sirainen <tss@iki.fi>
parents:
5244
diff
changeset
|
289 /* [\n]--<boundary> */ |
43d3955ce03f
Fixes to counting MIME part sizes
Timo Sirainen <tss@iki.fi>
parents:
5244
diff
changeset
|
290 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
|
291 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
|
292 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
293 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
|
294 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
|
295 } |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 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
|
298 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
|
299 { |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 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
|
301 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
|
302 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
|
303 int ret; |
5109 | 304 bool 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
|
305 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 if ((ret = message_parser_read_more(ctx, block_r)) == 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
|
307 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
|
308 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
|
309 eof = ret == -1; |
5109 | 310 full = ret == -2; |
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
|
311 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 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
|
313 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
|
314 /* 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
|
315 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
|
316 ret = boundary_line_find(ctx, block_r->data, |
5109 | 317 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
|
318 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
|
319 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
|
320 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
|
321 |
5305
43d3955ce03f
Fixes to counting MIME part sizes
Timo Sirainen <tss@iki.fi>
parents:
5244
diff
changeset
|
322 return 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
|
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 } |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 |
5109 | 326 for (i = boundary_start = 0; i < block_r->size; i++) { |
5411 | 327 /* skip to beginning of the next line. the first line was |
328 handled already. */ | |
5440 | 329 size_t next_line_idx = block_r->size; |
330 | |
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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 boundary_start--; |
5440 | 336 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
|
337 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
|
338 } |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 } |
5411 | 340 if (boundary_start != 0) { |
341 /* we can skip the first lines. input buffer can't be | |
342 full anymore. */ | |
5109 | 343 full = FALSE; |
5411 | 344 } |
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 |
5440 | 346 ret = boundary_line_find(ctx, block_r->data + next_line_idx, |
347 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
|
348 &boundary); |
5109 | 349 if (ret >= 0) { |
350 /* found / need more data */ | |
5112 | 351 if (ret == 0 && boundary_start == 0) |
5440 | 352 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
|
353 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
|
354 } |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 } |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 |
5111 | 357 if (i >= block_r->size) { |
5109 | 358 /* the boundary wasn't found from this data block, |
359 we'll need more data. */ | |
5111 | 360 if (eof) |
361 ret = -1; | |
362 else { | |
363 ret = 0; | |
5989
1a7f5c04af1d
We wanted to read too many bytes when finding end boundary, which could have
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
364 ctx->want_count = (block_r->size - boundary_start) + 1; |
5111 | 365 } |
5109 | 366 } |
367 i_assert(!(ret == 0 && full)); | |
368 | |
369 if (ret >= 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
|
370 /* leave CR+LF + last line to buffer */ |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
371 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
|
372 } |
5244 | 373 if (block_r->size != 0) |
374 parse_body_add_block(ctx, block_r); | |
375 return ret <= 0 ? ret : | |
5305
43d3955ce03f
Fixes to counting MIME part sizes
Timo Sirainen <tss@iki.fi>
parents:
5244
diff
changeset
|
376 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
|
377 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
378 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
379 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
|
380 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
|
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 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
|
383 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
384 if ((ret = message_parser_read_more(ctx, block_r)) <= 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
|
385 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
|
386 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
387 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
|
388 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
|
389 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
390 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
391 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
|
392 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
|
393 { |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
394 struct rfc822_parser_context parser; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
395 const char *key, *value; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
396 string_t *content_type; |
0 | 397 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
398 if (ctx->part_seen_content_type) |
0 | 399 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
|
400 ctx->part_seen_content_type = TRUE; |
0 | 401 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
402 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
|
403 (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
|
404 |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
405 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
|
406 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
|
407 return; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
408 |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
409 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
|
410 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
|
411 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
|
412 (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
|
413 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
|
414 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
|
415 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
|
416 ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART; |
0 | 417 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
418 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
|
419 ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART_DIGEST; |
0 | 420 } |
421 | |
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
|
422 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
|
423 ctx->last_boundary != NULL) |
0 | 424 return; |
425 | |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
426 while (rfc822_parse_content_param(&parser, &key, &value) > 0) { |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
427 if (strcasecmp(key, "boundary") == 0) { |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
428 ctx->last_boundary = p_strdup(ctx->parser_pool, value); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
429 break; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
430 } |
0 | 431 } |
432 } | |
433 | |
874 | 434 #define MUTEX_FLAGS \ |
435 (MESSAGE_PART_FLAG_MESSAGE_RFC822 | MESSAGE_PART_FLAG_MULTIPART) | |
436 | |
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
|
437 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
|
438 struct message_block *block_r) |
0 | 439 { |
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
|
440 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
|
441 struct message_header_line *hdr; |
2430
7c1dc4a7db3a
message_parse_header_next() can now return "need more data" with nonblocking
Timo Sirainen <tss@iki.fi>
parents:
2404
diff
changeset
|
442 int ret; |
0 | 443 |
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
|
444 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
|
445 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
|
446 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
|
447 } |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
448 |
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
|
449 ret = message_parse_header_next(ctx->hdr_parser_ctx, &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
|
450 if (ret == 0 || (ret < 0 && ctx->input->stream_errno != 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
|
451 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
|
452 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 (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
|
454 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
|
455 ; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
456 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
|
457 /* 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
|
458 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
|
459 } 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
|
460 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
|
461 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
|
462 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
|
463 |
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
|
464 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
|
465 hdr->use_full_value = TRUE; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
466 else { |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
467 t_push(); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
468 parse_content_type(ctx, hdr); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
6082
diff
changeset
|
469 t_pop(); |
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 } |
1618
149ade487f48
Ignore Content-* headers if there's no MIME-Version header. Note that this
Timo Sirainen <tss@iki.fi>
parents:
1543
diff
changeset
|
471 } |
149ade487f48
Ignore Content-* headers if there's no MIME-Version header. Note that this
Timo Sirainen <tss@iki.fi>
parents:
1543
diff
changeset
|
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 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
|
474 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
|
475 return 1; |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
476 } |
1618
149ade487f48
Ignore Content-* headers if there's no MIME-Version header. Note that this
Timo Sirainen <tss@iki.fi>
parents:
1543
diff
changeset
|
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 /* 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
|
479 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
|
480 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
|
481 /* 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
|
482 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
|
483 } |
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
|
484 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
|
485 /* 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
|
486 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
|
487 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
|
488 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
|
489 } |
874 | 490 |
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
|
491 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
|
492 (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
|
493 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
|
494 (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
|
495 MESSAGE_PART_FLAG_MULTIPART_DIGEST) != 0) { |
0 | 496 /* 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
|
497 below multipart/digest, assume message/rfc822 |
0 | 498 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
|
499 part->flags |= MESSAGE_PART_FLAG_MESSAGE_RFC822; |
0 | 500 } else { |
501 /* 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
|
502 part->flags |= MESSAGE_PART_FLAG_TEXT; |
0 | 503 } |
504 } | |
505 | |
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
|
506 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
|
507 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
|
508 message_parse_header_deinit(&ctx->hdr_parser_ctx); |
0 | 509 |
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
|
510 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
|
511 |
5244 | 512 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
|
513 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
|
514 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
|
515 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
|
516 } else if (part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) { |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 parse_next_body_message_rfc822_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
|
518 ctx->parse_next_block = parse_next_header_init; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
519 } else 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
|
520 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
|
521 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
|
522 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
|
523 |
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
|
524 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
|
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 /* 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
|
527 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
|
528 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
|
529 return 1; |
0 | 530 } |
531 | |
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 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
|
533 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
|
534 { |
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
|
535 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
|
536 |
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
|
537 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
|
538 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
|
539 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
|
540 ctx->part_seen_content_type = FALSE; |
0 | 541 |
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
|
542 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
|
543 return parse_next_header(ctx, block_r); |
0 | 544 } |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
545 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6156
diff
changeset
|
546 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
|
547 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
|
548 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
549 return -1; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
550 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
551 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
552 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
|
553 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
554 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
|
555 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
|
556 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
|
557 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
|
558 break; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
559 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
560 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
|
561 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
562 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
|
563 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
|
564 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
565 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
566 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
|
567 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
|
568 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
569 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
|
570 ctx->skip = 0; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
571 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
572 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
|
573 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
|
574 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
575 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
576 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
|
577 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
|
578 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
579 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
|
580 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
|
581 ctx->part->body_size.physical_size; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
582 int ret; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
583 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
584 ret = message_parser_read_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
|
585 if (ret <= 0) |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
586 return ret; |
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 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
|
589 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
|
590 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
|
591 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
592 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
|
593 return 1; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
594 } |
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 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
|
597 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
|
598 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
599 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
|
600 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
|
601 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
602 i_assert(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
|
603 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
|
604 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
605 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
|
606 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
|
607 } |
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 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
|
610 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
|
611 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
612 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
|
613 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
|
614 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
|
615 } 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
|
616 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
|
617 } else { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
618 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
|
619 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
620 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
|
621 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
622 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
623 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
|
624 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
|
625 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
626 struct message_header_line *hdr; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
627 int ret; |
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 ret = message_parse_header_next(ctx->hdr_parser_ctx, &hdr); |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
630 if (ret == 0 || (ret < 0 && ctx->input->stream_errno != 0)) |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
631 return ret; |
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 if (hdr != NULL) { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
634 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
|
635 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
|
636 return 1; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
637 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
638 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
|
639 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
640 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
|
641 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
642 /* 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
|
643 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
|
644 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
|
645 return 1; |
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 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
648 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
|
649 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
|
650 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
651 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
|
652 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
653 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
|
654 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
|
655 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
|
656 |
5522
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
657 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
|
658 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
|
659 |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
660 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
|
661 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
|
662 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
663 |
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
|
664 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
|
665 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
|
666 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
|
667 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
|
668 { |
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
|
669 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
|
670 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
|
671 |
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
|
672 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
|
673 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
|
674 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
|
675 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
|
676 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
|
677 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
|
678 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
|
679 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
|
680 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
|
681 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
|
682 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
|
683 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
|
684 } |
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
|
685 |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
686 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
|
687 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
|
688 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
|
689 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
|
690 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
|
691 { |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
692 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
|
693 |
5522
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5506
diff
changeset
|
694 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
|
695 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
|
696 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
|
697 return ctx; |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
698 } |
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
699 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
700 struct message_part *message_parser_deinit(struct message_parser_ctx **_ctx) |
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
|
701 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
702 struct message_parser_ctx *ctx = *_ctx; |
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
|
703 struct message_part *parts = ctx->parts; |
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
|
704 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
705 *_ctx = NULL; |
6082
d62bddb414ef
ref/unref stream when parsing it.
Timo Sirainen <tss@iki.fi>
parents:
5989
diff
changeset
|
706 i_stream_unref(&ctx->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
|
707 pool_unref(ctx->parser_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
|
708 return parts; |
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
|
709 } |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
710 |
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
|
711 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
|
712 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
|
713 { |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
714 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
|
715 bool eof = FALSE; |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
716 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
717 while ((ret = ctx->parse_next_block(ctx, block_r)) == 0) { |
5109 | 718 ret = message_parser_read_more(ctx, block_r); |
719 if (ret <= 0) { | |
720 i_assert(ret != -2); | |
721 | |
722 if (ret == 0) { | |
723 i_assert(!ctx->input->blocking); | |
724 return 0; | |
725 } | |
726 if (ret < 0) { | |
727 i_assert(!eof); | |
728 eof = TRUE; | |
729 } | |
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 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
731 } |
5109 | 732 |
4673
f5bef033a9ac
message_parser_parse_next_block() returned body part wrong for first header
Timo Sirainen <tss@iki.fi>
parents:
4267
diff
changeset
|
733 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
|
734 |
5506
6cd889c652b0
Removed message_parse_from_parts(). Added message_parser_init_from_parts()
Timo Sirainen <tss@iki.fi>
parents:
5440
diff
changeset
|
735 if (ret < 0 && ctx->part != NULL) { |
5111 | 736 i_assert(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
|
737 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
|
738 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
|
739 &ctx->part->body_size); |
4267
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
740 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
|
741 &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
|
742 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
|
743 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
744 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
745 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
746 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
|
747 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
748 |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4673
diff
changeset
|
749 #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
|
750 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
|
751 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
|
752 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
|
753 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
|
754 { |
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
|
755 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
|
756 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
|
757 |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
758 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
|
759 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
|
760 |
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
|
761 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
|
762 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
|
763 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
764 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
|
765 |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 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
|
767 /* 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
|
768 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
|
769 } |
fd315deac28f
Rewrote the message bodystructure parser to allow 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 |
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
|
771 *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
|
772 } |
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
|
773 |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4673
diff
changeset
|
774 #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
|
775 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
|
776 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
|
777 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
|
778 { |
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
|
779 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
|
780 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
|
781 |
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
|
782 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
|
783 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
|
784 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
|
785 } |
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
786 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
|
787 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1253
diff
changeset
|
788 |
4267
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
789 static void |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
790 message_parser_set_crlfs_diff(struct message_part *parts, bool use_crlf, |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
791 off_t diff) |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
792 { |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
793 while (parts != NULL) { |
5001
c0a9bab3fc32
CR removing from parsed mails didn't work properly for multipart mails.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
794 parts->physical_pos += diff; |
4267
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
795 |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
796 if (use_crlf) { |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
797 parts->header_size.physical_size = |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
798 parts->header_size.virtual_size; |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
799 parts->body_size.physical_size = |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
800 parts->body_size.virtual_size; |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
801 } else { |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
802 parts->header_size.physical_size = |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
803 parts->header_size.virtual_size - |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
804 parts->header_size.lines; |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
805 parts->body_size.physical_size = |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
806 parts->body_size.virtual_size - |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
807 parts->body_size.lines; |
5001
c0a9bab3fc32
CR removing from parsed mails didn't work properly for multipart mails.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
808 |
c0a9bab3fc32
CR removing from parsed mails didn't work properly for multipart mails.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
809 diff -= parts->header_size.lines; |
4267
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
810 } |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
811 |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
812 if (parts->children != NULL) { |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
813 message_parser_set_crlfs_diff(parts->children, |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
814 use_crlf, diff); |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
815 } |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
816 |
5001
c0a9bab3fc32
CR removing from parsed mails didn't work properly for multipart mails.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
817 if (!use_crlf) |
c0a9bab3fc32
CR removing from parsed mails didn't work properly for multipart mails.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
818 diff -= parts->body_size.lines; |
c0a9bab3fc32
CR removing from parsed mails didn't work properly for multipart mails.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
819 |
4267
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
820 parts = parts->next; |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
821 } |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
822 } |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
823 |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
824 void message_parser_set_crlfs(struct message_part *parts, bool use_crlf) |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
825 { |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
826 message_parser_set_crlfs_diff(parts, use_crlf, 0); |
bd99e8f5e3ac
Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4265
diff
changeset
|
827 } |