annotate src/lib-mail/message-parser.c @ 5112:c72eb76e4173 HEAD

Inifinite looping fixes
author Timo Sirainen <tss@iki.fi>
date Tue, 06 Feb 2007 15:42:54 +0200
parents daf87522bce4
children aeb72263352d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents: 579
diff changeset
4 #include "istream.h"
896
21ffcce83c70 Rewrote rfc822-tokenize.c to work one token at a time so it won't uselessly
Timo Sirainen <tss@iki.fi>
parents: 874
diff changeset
5 #include "strescape.h"
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "message-content-parser.h"
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 const char *boundary;
184
4223b9ed0c80 move size_t fixes
Timo Sirainen <tss@iki.fi>
parents: 169
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27
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
28 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
29 struct message_boundary *boundaries;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
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 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
32 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
33 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
34
4259
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
35 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
36
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
37 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
38 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
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 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
41 };
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1253
diff changeset
42
4903
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4673
diff changeset
43 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
44
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
45 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
46 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
47 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
48 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
49 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
50 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
51
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
52 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
53 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
54 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
55 {
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
56 /* 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
57 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
58 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
59 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
60 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
61 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
62 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
63 return boundaries;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64
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
65 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
66 }
fd315deac28f Rewrote the message bodystructure parser to allow 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
fd315deac28f Rewrote the message bodystructure parser to allow 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 NULL;
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
69 }
fd315deac28f Rewrote the message bodystructure parser to allow 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
fd315deac28f Rewrote the message bodystructure parser to allow 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 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
72 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
73 {
fd315deac28f Rewrote the message bodystructure parser to allow 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 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
75 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
76 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
77
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
78 i_assert(ctx->skip == 0);
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
79
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
80 block->hdr = NULL;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81
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
82 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
83 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
84 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
85 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
86 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
87 (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
88 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
89 } 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
90 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
91 }
fd315deac28f Rewrote the message bodystructure parser to allow 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 }
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
93
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
94 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
95 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
96
fd315deac28f Rewrote the message bodystructure parser to allow 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->last_chr = data[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
98 ctx->skip = 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
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
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
101 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
102 struct message_block *block_r)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 {
5112
c72eb76e4173 Inifinite looping fixes
Timo Sirainen <tss@iki.fi>
parents: 5111
diff changeset
104 int ret;
c72eb76e4173 Inifinite looping fixes
Timo Sirainen <tss@iki.fi>
parents: 5111
diff changeset
105
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
106 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
107 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
108 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
109 }
fd315deac28f Rewrote the message bodystructure parser to allow 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
5112
c72eb76e4173 Inifinite looping fixes
Timo Sirainen <tss@iki.fi>
parents: 5111
diff changeset
111 ret = i_stream_read_data(ctx->input, &block_r->data,
c72eb76e4173 Inifinite looping fixes
Timo Sirainen <tss@iki.fi>
parents: 5111
diff changeset
112 &block_r->size, ctx->want_count);
c72eb76e4173 Inifinite looping fixes
Timo Sirainen <tss@iki.fi>
parents: 5111
diff changeset
113 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
114 return -1;
5112
c72eb76e4173 Inifinite looping fixes
Timo Sirainen <tss@iki.fi>
parents: 5111
diff changeset
115
c72eb76e4173 Inifinite looping fixes
Timo Sirainen <tss@iki.fi>
parents: 5111
diff changeset
116 if (ret == 0) {
c72eb76e4173 Inifinite looping fixes
Timo Sirainen <tss@iki.fi>
parents: 5111
diff changeset
117 if (!ctx->input->eof) {
c72eb76e4173 Inifinite looping fixes
Timo Sirainen <tss@iki.fi>
parents: 5111
diff changeset
118 i_assert(!ctx->input->blocking);
c72eb76e4173 Inifinite looping fixes
Timo Sirainen <tss@iki.fi>
parents: 5111
diff changeset
119 return 0;
c72eb76e4173 Inifinite looping fixes
Timo Sirainen <tss@iki.fi>
parents: 5111
diff changeset
120 }
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
121 }
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
122
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
123 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
124 return 1;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
127 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
128 message_part_append(pool_t pool, struct message_part *parent)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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 struct message_part *part, **list;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
131
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
132 part = p_new(pool, struct message_part, 1);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
133 part->parent = parent;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134
212
4327b1266604 message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents: 184
diff changeset
135 /* set child position */
4327b1266604 message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents: 184
diff changeset
136 part->physical_pos =
4327b1266604 message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents: 184
diff changeset
137 parent->physical_pos +
4327b1266604 message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents: 184
diff changeset
138 parent->body_size.physical_size +
4327b1266604 message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents: 184
diff changeset
139 parent->header_size.physical_size;
4327b1266604 message/rfc822 mime parts weren't parsed correctly
Timo Sirainen <tss@iki.fi>
parents: 184
diff changeset
140
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141 list = &part->parent->children;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
142 while (*list != NULL)
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 list = &(*list)->next;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145 *list = part;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146 return part;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148
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
149 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
150 {
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
151 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
152
fd315deac28f Rewrote the message bodystructure parser to allow 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 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
154 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
155 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
156 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
157
fd315deac28f Rewrote the message bodystructure parser to allow 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->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
159 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
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 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
162 }
fd315deac28f Rewrote the message bodystructure parser to allow 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 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
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 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
167 }
fd315deac28f Rewrote the message bodystructure parser to allow 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 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
170 boundary_line_find(struct message_parser_ctx *ctx,
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
171 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
172 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
173 {
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
174 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
175
fd315deac28f Rewrote the message bodystructure parser to allow 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 *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
177
fd315deac28f Rewrote the message bodystructure parser to allow 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 if (size < 2) {
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
179 i_assert(!full);
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
180
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
181 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
182 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
183 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
184 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
185 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
186
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
187 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
188 /* 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
189 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
190 }
fd315deac28f Rewrote the message bodystructure parser to allow 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
fd315deac28f Rewrote the message bodystructure parser to allow 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 /* 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
193 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
194 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
195 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
196 }
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
197 if (i == size && i < BOUNDARY_END_MAX_LEN &&
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
198 !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
199 /* 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
200 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
201 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
202 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
203
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
204 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
205 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
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 *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
208 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
209 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
210
fd315deac28f Rewrote the message bodystructure parser to allow 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 (*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
212 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
213 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
214 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
215 }
fd315deac28f Rewrote the message bodystructure parser to allow 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
fd315deac28f Rewrote the message bodystructure parser to allow 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 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
218 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
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 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
221 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
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 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
224 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
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 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
227 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
228 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
229 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
230
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
231 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
232 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
233 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
234 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
235
fd315deac28f Rewrote the message bodystructure parser to allow 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 /* 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
237 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
238 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
239
fd315deac28f Rewrote the message bodystructure parser to allow 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 /* 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
241 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
242 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
243
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
244 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
245 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
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
fd315deac28f Rewrote the message bodystructure parser to allow 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 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
249 struct message_boundary *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
250 struct message_block *block_r)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
251 {
5111
Timo Sirainen <tss@iki.fi>
parents: 5109
diff changeset
252 struct message_part *part;
Timo Sirainen <tss@iki.fi>
parents: 5109
diff changeset
253
4259
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
254 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
255 /* 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
256 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
257 }
fd315deac28f Rewrote the message bodystructure parser to allow 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
fd315deac28f Rewrote the message bodystructure parser to allow 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 /* 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
260 into parent's body sizes */
5111
Timo Sirainen <tss@iki.fi>
parents: 5109
diff changeset
261 for (part = ctx->part; part != boundary->part; part = part->parent) {
Timo Sirainen <tss@iki.fi>
parents: 5109
diff changeset
262 message_size_add(&part->parent->body_size, &part->body_size);
Timo Sirainen <tss@iki.fi>
parents: 5109
diff changeset
263 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
264 }
5111
Timo Sirainen <tss@iki.fi>
parents: 5109
diff changeset
265 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
266
fd315deac28f Rewrote the message bodystructure parser to allow 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 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
268 /* 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
269 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
270
fd315deac28f Rewrote the message bodystructure parser to allow 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 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
272 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
273 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
274 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
275 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
276 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
277
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
278 /* 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
279 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
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 /* 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
282 block_r->data = i_stream_get_data(ctx->input, &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
283 i_assert(block_r->size >= 2 + boundary->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
284 block_r->size = 2 + boundary->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
285 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
286
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
287 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
288 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
289 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
290
fd315deac28f Rewrote the message bodystructure parser to allow 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 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
292 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
293 {
fd315deac28f Rewrote the message bodystructure parser to allow 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 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
295 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
296 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
297 int ret;
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
298 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
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 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
301 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
302 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
303 eof = ret == -1;
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
304 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
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 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
307 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
308 /* 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
309 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
310 ret = boundary_line_find(ctx, block_r->data,
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
311 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
312 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
313 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
314 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
315
fd315deac28f Rewrote the message bodystructure parser to allow 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 return parse_part_finish(ctx, boundary, 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
317 }
fd315deac28f Rewrote the message bodystructure parser to allow 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 }
fd315deac28f Rewrote the message bodystructure parser to allow 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
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
320 for (i = boundary_start = 0; i < block_r->size; i++) {
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
321 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
322 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
323 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
324 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
325 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
326 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
327 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
328 }
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
329 if (boundary_start != 0)
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
330 full = 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
331
fd315deac28f Rewrote the message bodystructure parser to allow 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 ret = boundary_line_find(ctx, block_r->data + i + 1,
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
333 block_r->size - (i + 1), 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
334 &boundary);
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
335 if (ret >= 0) {
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
336 /* found / need more data */
5112
c72eb76e4173 Inifinite looping fixes
Timo Sirainen <tss@iki.fi>
parents: 5111
diff changeset
337 if (ret == 0 && boundary_start == 0)
c72eb76e4173 Inifinite looping fixes
Timo Sirainen <tss@iki.fi>
parents: 5111
diff changeset
338 ctx->want_count += 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
339 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
340 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
341 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
342
5111
Timo Sirainen <tss@iki.fi>
parents: 5109
diff changeset
343 if (i >= block_r->size) {
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
344 /* the boundary wasn't found from this data block,
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
345 we'll need more data. */
5111
Timo Sirainen <tss@iki.fi>
parents: 5109
diff changeset
346 if (eof)
Timo Sirainen <tss@iki.fi>
parents: 5109
diff changeset
347 ret = -1;
Timo Sirainen <tss@iki.fi>
parents: 5109
diff changeset
348 else {
Timo Sirainen <tss@iki.fi>
parents: 5109
diff changeset
349 ret = 0;
Timo Sirainen <tss@iki.fi>
parents: 5109
diff changeset
350 ctx->want_count = i + 1;
Timo Sirainen <tss@iki.fi>
parents: 5109
diff changeset
351 }
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
352 }
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
353 i_assert(!(ret == 0 && full));
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
354
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
355 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
356 /* 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
357 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
358 }
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
359 if (ret <= 0) {
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
360 if (block_r->size != 0)
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
361 parse_body_add_block(ctx, block_r);
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
362 return ret;
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
363 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
364
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
365 return parse_part_finish(ctx, boundary, 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
366 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
367
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
368 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
369 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
370 {
fd315deac28f Rewrote the message bodystructure parser to allow 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 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
372
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
373 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
374 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
375
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
376 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
377 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
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
fd315deac28f Rewrote the message bodystructure parser to allow 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 static void
fd315deac28f Rewrote the message bodystructure parser to allow 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 parse_content_type(const unsigned char *value, size_t value_len, void *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
382 {
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
383 struct message_parser_ctx *ctx = context;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
384 const char *str;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
385
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
386 if (ctx->part_seen_content_type || value_len == 0)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
387 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
388 ctx->part_seen_content_type = TRUE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
389
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
390 t_push();
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
391 str = t_strndup(value, value_len);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
392 if (strcasecmp(str, "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
393 ctx->part->flags |= MESSAGE_PART_FLAG_MESSAGE_RFC822;
1662
aff92c2de6f5 "Content-Type: text" (without '/') didn't mark the message as containing
Timo Sirainen <tss@iki.fi>
parents: 1618
diff changeset
394 else if (strncasecmp(str, "text", 4) == 0 &&
aff92c2de6f5 "Content-Type: text" (without '/') didn't mark the message as containing
Timo Sirainen <tss@iki.fi>
parents: 1618
diff changeset
395 (str[4] == '/' || str[4] == '\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
396 ctx->part->flags |= MESSAGE_PART_FLAG_TEXT;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397 else if (strncasecmp(str, "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
398 ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
399
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 if (strcasecmp(str+10, "digest") == 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
401 ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART_DIGEST;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
402 }
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
403 t_pop();
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
404 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
405
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
406 static void
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
407 parse_content_type_param(const unsigned char *name, size_t name_len,
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
408 const unsigned char *value, size_t value_len,
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3676
diff changeset
409 bool value_quoted, void *context)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
410 {
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
411 struct message_parser_ctx *ctx = 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
412 char *boundary;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
413
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 if ((ctx->part->flags & MESSAGE_PART_FLAG_MULTIPART) == 0 ||
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
415 name_len != 8 || memcasecmp(name, "boundary", 8) != 0)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
416 return;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
417
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
418 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
419 boundary = p_strndup(ctx->parser_pool, value, value_len);
896
21ffcce83c70 Rewrote rfc822-tokenize.c to work one token at a time so it won't uselessly
Timo Sirainen <tss@iki.fi>
parents: 874
diff changeset
420 if (value_quoted)
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
421 str_unescape(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
422 ctx->last_boundary = boundary;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
423 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
424 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
425
874
a60e12a66ad3 extra assert.
Timo Sirainen <tss@iki.fi>
parents: 856
diff changeset
426 #define MUTEX_FLAGS \
a60e12a66ad3 extra assert.
Timo Sirainen <tss@iki.fi>
parents: 856
diff changeset
427 (MESSAGE_PART_FLAG_MESSAGE_RFC822 | MESSAGE_PART_FLAG_MULTIPART)
a60e12a66ad3 extra assert.
Timo Sirainen <tss@iki.fi>
parents: 856
diff changeset
428
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
429 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
430 struct message_block *block_r)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
431 {
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
432 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
433 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
434 int ret;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
435
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
436 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
437 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
438 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
439 }
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1253
diff changeset
440
4259
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
441 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
442 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
443 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
444
fd315deac28f Rewrote the message bodystructure parser to allow 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 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
446 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
447 ;
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
448 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
449 /* 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
450 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
451 } else if (strcasecmp(hdr->name, "Content-Type") == 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
452 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
453 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
454 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
455 message_content_parse_header(hdr->full_value,
fd315deac28f Rewrote the message bodystructure parser to allow 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 hdr->full_value_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
457 parse_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
458 parse_content_type_param, 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
459 }
1618
149ade487f48 Ignore Content-* headers if there's no MIME-Version header. Note that this
Timo Sirainen <tss@iki.fi>
parents: 1543
diff changeset
460 }
149ade487f48 Ignore Content-* headers if there's no MIME-Version header. Note that this
Timo Sirainen <tss@iki.fi>
parents: 1543
diff changeset
461
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
462 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
463 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
464 return 1;
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1253
diff changeset
465 }
1618
149ade487f48 Ignore Content-* headers if there's no MIME-Version header. Note that this
Timo Sirainen <tss@iki.fi>
parents: 1543
diff changeset
466
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
467 /* 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
468 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
469 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
470 /* 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
471 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
472 }
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
473 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
474 /* 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
475 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
476 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
477 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
478 }
874
a60e12a66ad3 extra assert.
Timo Sirainen <tss@iki.fi>
parents: 856
diff changeset
479
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
480 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
481 (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
482 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
483 (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
484 MESSAGE_PART_FLAG_MULTIPART_DIGEST) != 0) {
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
485 /* 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
486 below multipart/digest, assume message/rfc822
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
487 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
488 part->flags |= MESSAGE_PART_FLAG_MESSAGE_RFC822;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
489 } else {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
490 /* 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
491 part->flags |= MESSAGE_PART_FLAG_TEXT;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
492 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
493 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
494
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 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
496 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
497 message_parse_header_deinit(&ctx->hdr_parser_ctx);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
498
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
499 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
500
4259
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
501 if (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
502 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
503 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
504 } 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
505 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
506 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
507 } 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
508 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
509 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
510 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
511
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
512 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
513
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
514 /* 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
515 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
516 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
517 return 1;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
518 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
519
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
520 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
521 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
522 {
4259
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
523 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
524
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
525 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
526 message_parse_header_init(ctx->input, &ctx->part->header_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
527 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
528 ctx->part_seen_content_type = FALSE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
529
4259
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
530 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
531 return parse_next_header(ctx, block_r);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
532 }
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1253
diff changeset
533
1697
ef79ce6507ff Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents: 1689
diff changeset
534 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
535 message_parser_init(pool_t part_pool, struct istream *input)
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1253
diff changeset
536 {
1697
ef79ce6507ff Message parsing can now be done in two parts - header and body. We're now
Timo Sirainen <tss@iki.fi>
parents: 1689
diff changeset
537 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
538 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
539
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
540 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
541 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
542 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
543 ctx->part_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
544 ctx->input = 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
545 ctx->parts = ctx->part = 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
546 ctx->parse_next_block = parse_next_header_init;
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
547 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
548 }
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
549
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
550 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
551 {
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
552 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
553 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
554
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
555 *_ctx = NULL;
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
556 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
557 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
558 }
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1253
diff changeset
559
4259
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
560 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
561 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
562 {
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
563 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
564 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
565
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
566 while ((ret = ctx->parse_next_block(ctx, block_r)) == 0) {
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
567 ret = message_parser_read_more(ctx, block_r);
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
568 if (ret <= 0) {
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
569 i_assert(ret != -2);
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
570
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
571 if (ret == 0) {
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
572 i_assert(!ctx->input->blocking);
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
573 return 0;
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
574 }
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
575 if (ret < 0) {
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
576 i_assert(!eof);
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
577 eof = TRUE;
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
578 }
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
579 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
580 }
5109
Timo Sirainen <tss@iki.fi>
parents: 5001
diff changeset
581
4673
f5bef033a9ac message_parser_parse_next_block() returned body part wrong for first header
Timo Sirainen <tss@iki.fi>
parents: 4267
diff changeset
582 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
583
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
584 if (ret < 0) {
5111
Timo Sirainen <tss@iki.fi>
parents: 5109
diff changeset
585 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
586 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
587 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
588 &ctx->part->body_size);
4267
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
589 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
590 &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
591 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
592 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
593 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
594
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
595 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
596 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
597
4903
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4673
diff changeset
598 #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
599 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
600 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
601 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
602 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
603 {
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
604 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
605 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
606
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
607 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
608 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
609
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
610 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
611 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
612 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
613 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
614
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
615 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
616 /* 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
617 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
618 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
619
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
620 *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
621 }
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
622
4903
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4673
diff changeset
623 #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
624 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
625 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
626 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
627 {
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
628 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
629 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
630
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
631 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
632 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
633 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
634 }
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
635 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
636 }
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1253
diff changeset
637
1689
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
638 static void part_parse_headers(struct message_part *part, struct istream *input,
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
639 message_part_header_callback_t *callback,
1689
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
640 void *context)
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
641 {
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
642 struct message_header_parser_ctx *hdr_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
643 struct message_header_line *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
644 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
645
1689
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
646 while (part != NULL) {
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
647 /* note that we want to parse the header of all
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
648 the message parts, multiparts too. */
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
649 i_assert(part->physical_pos >= input->v_offset);
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
650 i_stream_skip(input, part->physical_pos - input->v_offset);
1689
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
651
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
652 hdr_ctx = message_parse_header_init(input, NULL, 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
653 while ((ret = message_parse_header_next(hdr_ctx, &hdr)) > 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
654 callback(part, hdr, 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
655 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
656 message_parse_header_deinit(&hdr_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
657
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
658 /* call after the final skipping */
fd315deac28f Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
659 callback(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
660
1689
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
661 if (part->children != NULL) {
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
662 part_parse_headers(part->children, 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
663 callback, context);
1689
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
664 }
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
665
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
666 part = part->next;
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
667 }
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
668 }
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
669
4903
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4673
diff changeset
670 #undef message_parse_from_parts
1689
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
671 void message_parse_from_parts(struct message_part *part, struct istream *input,
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
672 message_part_header_callback_t *callback,
1689
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
673 void *context)
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
674 {
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
675 part_parse_headers(part, input, callback, context);
1689
c07b98265577 If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents: 1662
diff changeset
676 }
4267
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
677
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
678 static void
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
679 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
680 off_t diff)
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
681 {
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
682 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
683 parts->physical_pos += diff;
4267
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
684
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
685 if (use_crlf) {
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
686 parts->header_size.physical_size =
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
687 parts->header_size.virtual_size;
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
688 parts->body_size.physical_size =
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
689 parts->body_size.virtual_size;
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
690 } else {
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
691 parts->header_size.physical_size =
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
692 parts->header_size.virtual_size -
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
693 parts->header_size.lines;
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
694 parts->body_size.physical_size =
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
695 parts->body_size.virtual_size -
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
696 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
697
c0a9bab3fc32 CR removing from parsed mails didn't work properly for multipart mails.
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
698 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
699 }
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
700
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
701 if (parts->children != NULL) {
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
702 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
703 use_crlf, diff);
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
704 }
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
705
5001
c0a9bab3fc32 CR removing from parsed mails didn't work properly for multipart mails.
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
706 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
707 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
708
4267
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
709 parts = parts->next;
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
710 }
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
711 }
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
712
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
713 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
714 {
bd99e8f5e3ac Some fixes and added message_parser_set_crlfs().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4265
diff changeset
715 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
716 }