Mercurial > dovecot > core-2.2
annotate src/lib-imap/imap-bodystructure.c @ 21629:4a61612dab4f
lib-imap: imap-bodystructure: Renamed imap_bodystructure_parse_header() to message_part_data_parse_from_header().
author | Stephan Bosch <stephan.bosch@dovecot.fi> |
---|---|
date | Sun, 23 Oct 2016 17:51:59 +0200 |
parents | a22181aad13a |
children | 65907879d3d5 |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21389
diff
changeset
|
1 /* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */ |
0 | 2 |
3 #include "lib.h" | |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
4 #include "buffer.h" |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
647
diff
changeset
|
5 #include "istream.h" |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
6 #include "str.h" |
0 | 7 #include "message-parser.h" |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
8 #include "rfc822-parser.h" |
7950
3412c43d6707
Merge RFC 2231 header continuations in BODY/BODYSTRUCTURE replies. Also use
Timo Sirainen <tss@iki.fi>
parents:
7949
diff
changeset
|
9 #include "rfc2231-parser.h" |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
10 #include "imap-parser.h" |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
11 #include "imap-quote.h" |
0 | 12 #include "imap-envelope.h" |
13 #include "imap-bodystructure.h" | |
14 | |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
15 #define DEFAULT_CHARSET "us-ascii" |
1537
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
16 |
0 | 17 #define EMPTY_BODYSTRUCTURE \ |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
18 "(\"text\" \"plain\" (\"charset\" \""DEFAULT_CHARSET"\") NIL NIL \"7bit\" 0 0)" |
0 | 19 |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
20 static void |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
21 parse_mime_parameters(struct rfc822_parser_context *parser, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
22 pool_t pool, const struct message_part_param **params_r, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
23 unsigned int *params_count_r) |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
24 { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
25 const char *const *results; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
26 struct message_part_param *params; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
27 unsigned int params_count, i; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
28 |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
29 rfc2231_parse(parser, &results); |
0 | 30 |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
31 params_count = str_array_length(results); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
32 i_assert((params_count % 2) == 0); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
33 params_count /= 2; |
15248
cb143b430787
lib-imap: bodystructure parsing now uses imap_append_string() instead of imap_quote*()
Timo Sirainen <tss@iki.fi>
parents:
15062
diff
changeset
|
34 |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
35 if (params_count > 0) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
36 params = p_new(pool, struct message_part_param, params_count); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
37 for (i = 0; i < params_count; i++) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
38 params[i].name = p_strdup(pool, results[i*2+0]); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
39 params[i].value = p_strdup(pool, results[i*2+1]); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
40 } |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
41 *params_r = params; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
42 } |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
43 |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
44 *params_count_r = params_count; |
15248
cb143b430787
lib-imap: bodystructure parsing now uses imap_append_string() instead of imap_quote*()
Timo Sirainen <tss@iki.fi>
parents:
15062
diff
changeset
|
45 } |
cb143b430787
lib-imap: bodystructure parsing now uses imap_append_string() instead of imap_quote*()
Timo Sirainen <tss@iki.fi>
parents:
15062
diff
changeset
|
46 |
21623
ff0f2eb98d79
lib-imap: imap-bodystructure: Removed useless pool field from struct message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21622
diff
changeset
|
47 static void |
ff0f2eb98d79
lib-imap: imap-bodystructure: Removed useless pool field from struct message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21622
diff
changeset
|
48 parse_content_type(struct message_part_data *data, |
ff0f2eb98d79
lib-imap: imap-bodystructure: Removed useless pool field from struct message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21622
diff
changeset
|
49 pool_t pool, struct message_header_line *hdr) |
0 | 50 { |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
51 struct rfc822_parser_context parser; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
52 string_t *str; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
53 const char *value; |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
54 unsigned int i; |
20889
f8ba998a6b7c
lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19677
diff
changeset
|
55 int ret; |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
56 |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
57 rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); |
14689
096e4c4d62bb
Try to avoid (void) casts by adding more ATTR_NOWARN_UNUSED_RESULT.
Timo Sirainen <tss@iki.fi>
parents:
14688
diff
changeset
|
58 rfc822_skip_lwsp(&parser); |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
59 |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
60 str = t_str_new(256); |
20889
f8ba998a6b7c
lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19677
diff
changeset
|
61 ret = rfc822_parse_content_type(&parser, str); |
0 | 62 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
63 /* Save content type and subtype */ |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
64 value = str_c(str); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
65 for (i = 0; value[i] != '\0'; i++) { |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
66 if (value[i] == '/') { |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
67 data->content_subtype = p_strdup(pool, value + i+1); |
0 | 68 break; |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
69 } |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
70 } |
15248
cb143b430787
lib-imap: bodystructure parsing now uses imap_append_string() instead of imap_quote*()
Timo Sirainen <tss@iki.fi>
parents:
15062
diff
changeset
|
71 str_truncate(str, i); |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
72 data->content_type = p_strdup(pool, str_c(str)); |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
73 |
20889
f8ba998a6b7c
lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19677
diff
changeset
|
74 if (ret < 0) { |
f8ba998a6b7c
lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19677
diff
changeset
|
75 /* Content-Type is broken, but we wanted to get it as well as |
f8ba998a6b7c
lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19677
diff
changeset
|
76 we could. Don't try to read the parameters anymore though. |
f8ba998a6b7c
lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19677
diff
changeset
|
77 |
f8ba998a6b7c
lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19677
diff
changeset
|
78 We don't completely ignore a broken Content-Type, because |
f8ba998a6b7c
lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19677
diff
changeset
|
79 then it would be written as text/plain. This would cause a |
f8ba998a6b7c
lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19677
diff
changeset
|
80 mismatch with the message_part's MESSAGE_PART_FLAG_TEXT. */ |
f8ba998a6b7c
lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19677
diff
changeset
|
81 return; |
f8ba998a6b7c
lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19677
diff
changeset
|
82 } |
f8ba998a6b7c
lib-imap: Don't write a broken Content-Type as text/plain to BODYSTRUCTURE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19677
diff
changeset
|
83 |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
84 parse_mime_parameters(&parser, pool, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
85 &data->content_type_params, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
86 &data->content_type_params_count); |
0 | 87 } |
88 | |
21623
ff0f2eb98d79
lib-imap: imap-bodystructure: Removed useless pool field from struct message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21622
diff
changeset
|
89 static void |
ff0f2eb98d79
lib-imap: imap-bodystructure: Removed useless pool field from struct message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21622
diff
changeset
|
90 parse_content_transfer_encoding(struct message_part_data *data, |
ff0f2eb98d79
lib-imap: imap-bodystructure: Removed useless pool field from struct message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21622
diff
changeset
|
91 pool_t pool, struct message_header_line *hdr) |
0 | 92 { |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
93 struct rfc822_parser_context parser; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
94 string_t *str; |
0 | 95 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
96 rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); |
14689
096e4c4d62bb
Try to avoid (void) casts by adding more ATTR_NOWARN_UNUSED_RESULT.
Timo Sirainen <tss@iki.fi>
parents:
14688
diff
changeset
|
97 rfc822_skip_lwsp(&parser); |
0 | 98 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
99 str = t_str_new(256); |
19677
a904c19c42ff
lib-imap: Write invalid Content-Transfer-Encoding value as "7bit" to BODY/BODYSTRUCTURE.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
100 if (rfc822_parse_mime_token(&parser, str) >= 0 && |
a904c19c42ff
lib-imap: Write invalid Content-Transfer-Encoding value as "7bit" to BODY/BODYSTRUCTURE.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
101 rfc822_skip_lwsp(&parser) == 0 && str_len(str) > 0) { |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
102 data->content_transfer_encoding = |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
103 p_strdup(pool, str_c(str)); |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
104 } |
0 | 105 } |
106 | |
21623
ff0f2eb98d79
lib-imap: imap-bodystructure: Removed useless pool field from struct message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21622
diff
changeset
|
107 static void |
ff0f2eb98d79
lib-imap: imap-bodystructure: Removed useless pool field from struct message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21622
diff
changeset
|
108 parse_content_disposition(struct message_part_data *data, |
ff0f2eb98d79
lib-imap: imap-bodystructure: Removed useless pool field from struct message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21622
diff
changeset
|
109 pool_t pool, struct message_header_line *hdr) |
0 | 110 { |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
111 struct rfc822_parser_context parser; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
112 string_t *str; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
113 |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
114 rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); |
14689
096e4c4d62bb
Try to avoid (void) casts by adding more ATTR_NOWARN_UNUSED_RESULT.
Timo Sirainen <tss@iki.fi>
parents:
14688
diff
changeset
|
115 rfc822_skip_lwsp(&parser); |
0 | 116 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
117 str = t_str_new(256); |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
118 if (rfc822_parse_mime_token(&parser, str) < 0) |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
119 return; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
120 data->content_disposition = p_strdup(pool, str_c(str)); |
0 | 121 |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
122 parse_mime_parameters(&parser, pool, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
123 &data->content_disposition_params, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
124 &data->content_disposition_params_count); |
0 | 125 } |
126 | |
21623
ff0f2eb98d79
lib-imap: imap-bodystructure: Removed useless pool field from struct message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21622
diff
changeset
|
127 static void |
ff0f2eb98d79
lib-imap: imap-bodystructure: Removed useless pool field from struct message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21622
diff
changeset
|
128 parse_content_language(struct message_part_data *data, |
ff0f2eb98d79
lib-imap: imap-bodystructure: Removed useless pool field from struct message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21622
diff
changeset
|
129 pool_t pool, const unsigned char *value, size_t value_len) |
0 | 130 { |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
131 struct rfc822_parser_context parser; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
132 ARRAY_TYPE(const_string) langs; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
133 string_t *str; |
398
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
134 |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
135 /* Language-Header = "Content-Language" ":" 1#Language-tag |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
136 Language-Tag = Primary-tag *( "-" Subtag ) |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
137 Primary-tag = 1*8ALPHA |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
138 Subtag = 1*8ALPHA */ |
0 | 139 |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
140 rfc822_parser_init(&parser, value, value_len, NULL); |
0 | 141 |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
142 t_array_init(&langs, 16); |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
143 str = t_str_new(128); |
0 | 144 |
14689
096e4c4d62bb
Try to avoid (void) casts by adding more ATTR_NOWARN_UNUSED_RESULT.
Timo Sirainen <tss@iki.fi>
parents:
14688
diff
changeset
|
145 rfc822_skip_lwsp(&parser); |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
146 while (rfc822_parse_atom(&parser, str) >= 0) { |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
147 const char *lang = p_strdup(pool, str_c(str)); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
148 |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
149 array_append(&langs, &lang, 1); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
150 str_truncate(str, 0); |
398
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
151 |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
152 if (parser.data == parser.end || *parser.data != ',') |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
153 break; |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
154 parser.data++; |
14689
096e4c4d62bb
Try to avoid (void) casts by adding more ATTR_NOWARN_UNUSED_RESULT.
Timo Sirainen <tss@iki.fi>
parents:
14688
diff
changeset
|
155 rfc822_skip_lwsp(&parser); |
398
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
156 } |
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
157 |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
158 if (array_count(&langs) > 0) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
159 array_append_zero(&langs); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
160 data->content_language = |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
161 p_strarray_dup(pool, array_idx(&langs, 0)); |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
162 } |
0 | 163 } |
164 | |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
165 static void |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
166 parse_content_header(struct message_part_data *data, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
167 pool_t pool, struct message_header_line *hdr) |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
168 { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
169 const char *name = hdr->name + strlen("Content-"); |
15248
cb143b430787
lib-imap: bodystructure parsing now uses imap_append_string() instead of imap_quote*()
Timo Sirainen <tss@iki.fi>
parents:
15062
diff
changeset
|
170 const char *value; |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
171 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
172 if (hdr->continues) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
173 hdr->use_full_value = TRUE; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
174 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
175 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
176 |
15248
cb143b430787
lib-imap: bodystructure parsing now uses imap_append_string() instead of imap_quote*()
Timo Sirainen <tss@iki.fi>
parents:
15062
diff
changeset
|
177 value = t_strndup(hdr->full_value, hdr->full_value_len); |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
178 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
179 switch (*name) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
180 case 'i': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
181 case 'I': |
21625
06bcaedc2149
lib-imap: imap-bodystructure: Renamed `d' parameter to `data' in parse_content_header() function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21623
diff
changeset
|
182 if (strcasecmp(name, "ID") == 0 && data->content_id == NULL) |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
183 data->content_id = p_strdup(pool, value); |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
184 break; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
185 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
186 case 'm': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
187 case 'M': |
21625
06bcaedc2149
lib-imap: imap-bodystructure: Renamed `d' parameter to `data' in parse_content_header() function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21623
diff
changeset
|
188 if (strcasecmp(name, "MD5") == 0 && data->content_md5 == NULL) |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
189 data->content_md5 = p_strdup(pool, value); |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
190 break; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
191 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
192 case 't': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
193 case 'T': |
21625
06bcaedc2149
lib-imap: imap-bodystructure: Renamed `d' parameter to `data' in parse_content_header() function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21623
diff
changeset
|
194 if (strcasecmp(name, "Type") == 0 && data->content_type == NULL) |
06bcaedc2149
lib-imap: imap-bodystructure: Renamed `d' parameter to `data' in parse_content_header() function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21623
diff
changeset
|
195 parse_content_type(data, pool, hdr); |
7949
e787f6cae97c
Added missing Content-Language: support for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
196 else if (strcasecmp(name, "Transfer-Encoding") == 0 && |
21625
06bcaedc2149
lib-imap: imap-bodystructure: Renamed `d' parameter to `data' in parse_content_header() function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21623
diff
changeset
|
197 data->content_transfer_encoding == NULL) |
06bcaedc2149
lib-imap: imap-bodystructure: Renamed `d' parameter to `data' in parse_content_header() function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21623
diff
changeset
|
198 parse_content_transfer_encoding(data, pool, hdr); |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
199 break; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
200 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
201 case 'l': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
202 case 'L': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
203 if (strcasecmp(name, "Language") == 0 && |
21625
06bcaedc2149
lib-imap: imap-bodystructure: Renamed `d' parameter to `data' in parse_content_header() function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21623
diff
changeset
|
204 data->content_language == NULL) { |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
205 parse_content_language(data, pool, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
206 hdr->full_value, hdr->full_value_len); |
15248
cb143b430787
lib-imap: bodystructure parsing now uses imap_append_string() instead of imap_quote*()
Timo Sirainen <tss@iki.fi>
parents:
15062
diff
changeset
|
207 } else if (strcasecmp(name, "Location") == 0 && |
21625
06bcaedc2149
lib-imap: imap-bodystructure: Renamed `d' parameter to `data' in parse_content_header() function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21623
diff
changeset
|
208 data->content_location == NULL) { |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
209 data->content_location = p_strdup(pool, value); |
7949
e787f6cae97c
Added missing Content-Language: support for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
210 } |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
211 break; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
212 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
213 case 'd': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
214 case 'D': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
215 if (strcasecmp(name, "Description") == 0 && |
21625
06bcaedc2149
lib-imap: imap-bodystructure: Renamed `d' parameter to `data' in parse_content_header() function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21623
diff
changeset
|
216 data->content_description == NULL) |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
217 data->content_description = p_strdup(pool, value); |
15248
cb143b430787
lib-imap: bodystructure parsing now uses imap_append_string() instead of imap_quote*()
Timo Sirainen <tss@iki.fi>
parents:
15062
diff
changeset
|
218 else if (strcasecmp(name, "Disposition") == 0 && |
21625
06bcaedc2149
lib-imap: imap-bodystructure: Renamed `d' parameter to `data' in parse_content_header() function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21623
diff
changeset
|
219 data->content_disposition_params == NULL) |
06bcaedc2149
lib-imap: imap-bodystructure: Renamed `d' parameter to `data' in parse_content_header() function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21623
diff
changeset
|
220 parse_content_disposition(data, pool, hdr); |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
221 break; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
222 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
223 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
224 |
21629
4a61612dab4f
lib-imap: imap-bodystructure: Renamed imap_bodystructure_parse_header() to message_part_data_parse_from_header().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21628
diff
changeset
|
225 void message_part_data_parse_from_header(pool_t pool, |
4a61612dab4f
lib-imap: imap-bodystructure: Renamed imap_bodystructure_parse_header() to message_part_data_parse_from_header().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21628
diff
changeset
|
226 struct message_part *part, |
4a61612dab4f
lib-imap: imap-bodystructure: Renamed imap_bodystructure_parse_header() to message_part_data_parse_from_header().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21628
diff
changeset
|
227 struct message_header_line *hdr) |
0 | 228 { |
21621
4e137a17cfd7
lib-imap: imap-bodystructure: Renamed struct message_part_body_data to message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21618
diff
changeset
|
229 struct message_part_data *part_data; |
1619
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
230 struct message_part_envelope_data *envelope; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3571
diff
changeset
|
231 bool parent_rfc822; |
0 | 232 |
1619
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
233 if (hdr == NULL) { |
21622
b6b198961bc6
lib-mail: Gave message_part_data its own field in struct message_part.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21621
diff
changeset
|
234 if (part->data == NULL) { |
7014
6835ac721609
Add a context structure to all message parts and remove the NULL checks.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
235 /* no Content-* headers. add an empty context |
6835ac721609
Add a context structure to all message parts and remove the NULL checks.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
236 structure anyway. */ |
21622
b6b198961bc6
lib-mail: Gave message_part_data its own field in struct message_part.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21621
diff
changeset
|
237 part->data = part_data = |
21621
4e137a17cfd7
lib-imap: imap-bodystructure: Renamed struct message_part_body_data to message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21618
diff
changeset
|
238 p_new(pool, struct message_part_data, 1); |
7014
6835ac721609
Add a context structure to all message parts and remove the NULL checks.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
239 } else if ((part->flags & MESSAGE_PART_FLAG_IS_MIME) == 0) { |
6835ac721609
Add a context structure to all message parts and remove the NULL checks.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
240 /* If there was no Mime-Version, forget all |
6835ac721609
Add a context structure to all message parts and remove the NULL checks.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
241 the Content-stuff */ |
21622
b6b198961bc6
lib-mail: Gave message_part_data its own field in struct message_part.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21621
diff
changeset
|
242 part_data = part->data; |
1619
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
243 envelope = part_data->envelope; |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
244 |
21389
59437f8764c6
global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21294
diff
changeset
|
245 i_zero(part_data); |
1619
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
246 part_data->envelope = envelope; |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
247 } |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
248 return; |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
249 } |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
250 |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
251 if (hdr->eoh) |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
252 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
253 |
106
5fe3e04ca8d9
Added support for caching of MessagePart data. This is useful for fetching
Timo Sirainen <tss@iki.fi>
parents:
105
diff
changeset
|
254 parent_rfc822 = part->parent != NULL && |
1619
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
255 (part->parent->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) != 0; |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
256 if (!parent_rfc822 && strncasecmp(hdr->name, "Content-", 8) != 0) |
0 | 257 return; |
258 | |
21622
b6b198961bc6
lib-mail: Gave message_part_data its own field in struct message_part.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21621
diff
changeset
|
259 if (part->data == NULL) { |
0 | 260 /* initialize message part data */ |
21622
b6b198961bc6
lib-mail: Gave message_part_data its own field in struct message_part.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21621
diff
changeset
|
261 part->data = part_data = |
21621
4e137a17cfd7
lib-imap: imap-bodystructure: Renamed struct message_part_body_data to message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21618
diff
changeset
|
262 p_new(pool, struct message_part_data, 1); |
0 | 263 } |
21622
b6b198961bc6
lib-mail: Gave message_part_data its own field in struct message_part.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21621
diff
changeset
|
264 part_data = part->data; |
0 | 265 |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
266 if (strncasecmp(hdr->name, "Content-", 8) == 0) { |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
267 T_BEGIN { |
21623
ff0f2eb98d79
lib-imap: imap-bodystructure: Removed useless pool field from struct message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21622
diff
changeset
|
268 parse_content_header(part_data, pool, hdr); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
269 } T_END; |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
270 } |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
271 |
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
272 if (parent_rfc822) { |
0 | 273 /* message/rfc822, we need the envelope */ |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
274 imap_envelope_parse_header(pool, &part_data->envelope, hdr); |
0 | 275 } |
276 } | |
277 | |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
278 static void |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
279 params_write(const struct message_part_param *params, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
280 unsigned int params_count, string_t *str, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
281 bool default_charset) |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
282 { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
283 unsigned int i; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
284 bool seen_charset; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
285 |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
286 if (!default_charset && params_count == 0) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
287 str_append(str, "NIL"); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
288 return; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
289 } |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
290 str_append_c(str, '('); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
291 |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
292 seen_charset = FALSE; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
293 for (i = 0; i < params_count; i++) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
294 if (i > 0) |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
295 str_append_c(str, ' '); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
296 if (default_charset && |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
297 strcasecmp(params[i].name, "charset") == 0) |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
298 seen_charset = TRUE; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
299 imap_append_string(str, params[i].name); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
300 str_append_c(str, ' '); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
301 imap_append_string(str, params[i].value); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
302 } |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
303 if (default_charset && !seen_charset) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
304 if (i > 0) |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
305 str_append_c(str, ' '); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
306 str_append(str, "\"charset\" \""DEFAULT_CHARSET"\""); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
307 } |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
308 str_append_c(str, ')'); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
309 } |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
310 |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
311 static void |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
312 part_write_bodystructure_siblings(const struct message_part *part, |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
313 string_t *dest, bool extended) |
0 | 314 { |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
315 for (; part != NULL; part = part->next) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
316 str_append_c(dest, '('); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
317 imap_bodystructure_write(part, dest, extended); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
318 str_append_c(dest, ')'); |
0 | 319 } |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
320 } |
0 | 321 |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
322 static void |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
323 part_write_bodystructure_common(const struct message_part_data *data, |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
324 string_t *str) |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
325 { |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
326 str_append_c(str, ' '); |
0 | 327 if (data->content_disposition == NULL) |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
328 str_append(str, "NIL"); |
0 | 329 else { |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
330 str_append_c(str, '('); |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
331 imap_append_string(str, data->content_disposition); |
862
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
332 |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
333 str_append_c(str, ' '); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
334 params_write(data->content_disposition_params, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
335 data->content_disposition_params_count, str, FALSE); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
336 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
337 str_append_c(str, ')'); |
0 | 338 } |
339 | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
340 str_append_c(str, ' '); |
0 | 341 if (data->content_language == NULL) |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
342 str_append(str, "NIL"); |
0 | 343 else { |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
344 const char *const *lang = data->content_language; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
345 |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
346 i_assert(*lang != NULL); |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
347 str_append_c(str, '('); |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
348 imap_append_string(str, *lang); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
349 lang++; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
350 while (*lang != NULL) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
351 str_append_c(str, ' '); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
352 imap_append_string(str, *lang); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
353 lang++; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
354 } |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
355 str_append_c(str, ')'); |
0 | 356 } |
7949
e787f6cae97c
Added missing Content-Language: support for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
357 |
e787f6cae97c
Added missing Content-Language: support for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
358 str_append_c(str, ' '); |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
359 imap_append_nstring(str, data->content_location); |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
360 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
361 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
362 static void part_write_body_multipart(const struct message_part *part, |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
363 string_t *str, bool extended) |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
364 { |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
365 const struct message_part_data *data = part->data; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
366 |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
367 i_assert(part->data != NULL); |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
368 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
369 if (part->children != NULL) |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
370 part_write_bodystructure_siblings(part->children, str, extended); |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
371 else { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
372 /* no parts in multipart message, |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
373 that's not allowed. write a single |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
374 0-length text/plain structure */ |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
375 str_append(str, EMPTY_BODYSTRUCTURE); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
376 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
377 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
378 str_append_c(str, ' '); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
379 if (data->content_subtype != NULL) |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
380 imap_append_string(str, data->content_subtype); |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
381 else |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
382 str_append(str, "\"x-unknown\""); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
383 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
384 if (!extended) |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
385 return; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
386 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
387 /* BODYSTRUCTURE data */ |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
388 |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
389 str_append_c(str, ' '); |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
390 params_write(data->content_type_params, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
391 data->content_type_params_count, str, FALSE); |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
392 |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
393 part_write_bodystructure_common(data, str); |
0 | 394 } |
395 | |
5334
8d9234a26a3f
Make imap_bodystructure_write() parameter constant. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
396 static void part_write_body(const struct message_part *part, |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3571
diff
changeset
|
397 string_t *str, bool extended) |
0 | 398 { |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
399 const struct message_part_data *data = part->data; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3571
diff
changeset
|
400 bool text; |
0 | 401 |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
402 i_assert(part->data != NULL); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
403 |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
404 if ((part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) != 0) { |
1665
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
405 str_append(str, "\"message\" \"rfc822\""); |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
406 text = FALSE; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
407 } else { |
1665
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
408 /* "content type" "subtype" */ |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
409 if (data->content_type == NULL) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
410 text = TRUE; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
411 str_append(str, "\"text\""); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
412 } else { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
413 text = (strcasecmp(data->content_type, "text") == 0); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
414 imap_append_string(str, data->content_type); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
415 } |
1665
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
416 str_append_c(str, ' '); |
1255
58041ce0a24c
Default to 7bit instead of 8bit content-encoding-type.
Timo Sirainen <tss@iki.fi>
parents:
1107
diff
changeset
|
417 |
1665
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
418 if (data->content_subtype != NULL) |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
419 imap_append_string(str, data->content_subtype); |
1665
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
420 else { |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
421 if (text) |
1665
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
422 str_append(str, "\"plain\""); |
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
423 else |
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
424 str_append(str, "\"unknown\""); |
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
425 } |
1255
58041ce0a24c
Default to 7bit instead of 8bit content-encoding-type.
Timo Sirainen <tss@iki.fi>
parents:
1107
diff
changeset
|
426 } |
0 | 427 |
428 /* ("content type param key" "value" ...) */ | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
429 str_append_c(str, ' '); |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
430 params_write(data->content_type_params, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
431 data->content_type_params_count, str, text); |
0 | 432 |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
433 str_append_c(str, ' '); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
434 imap_append_nstring(str, data->content_id); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
435 str_append_c(str, ' '); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
436 imap_append_nstring(str, data->content_description); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
437 str_append_c(str, ' '); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
438 if (data->content_transfer_encoding != NULL) |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
439 imap_append_string(str, data->content_transfer_encoding); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
440 else |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
441 str_append(str, "\"7bit\""); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
442 str_printfa(str, " %"PRIuUOFF_T, part->body_size.virtual_size); |
0 | 443 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
444 if (text) { |
0 | 445 /* text/.. contains line count */ |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
446 str_printfa(str, " %u", part->body_size.lines); |
106
5fe3e04ca8d9
Added support for caching of MessagePart data. This is useful for fetching
Timo Sirainen <tss@iki.fi>
parents:
105
diff
changeset
|
447 } else if (part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) { |
0 | 448 /* message/rfc822 contains envelope + body + line count */ |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
449 const struct message_part_data *child_data; |
0 | 450 |
451 i_assert(part->children != NULL); | |
452 i_assert(part->children->next == NULL); | |
453 | |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
454 child_data = part->children->data; |
0 | 455 |
1664 | 456 str_append(str, " ("); |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
457 imap_envelope_write_part_data(child_data->envelope, str); |
1663
4aca99baa9a4
Don't write envelope as NIL into bodystructure even if it's broken.
Timo Sirainen <tss@iki.fi>
parents:
1661
diff
changeset
|
458 str_append(str, ") "); |
4aca99baa9a4
Don't write envelope as NIL into bodystructure even if it's broken.
Timo Sirainen <tss@iki.fi>
parents:
1661
diff
changeset
|
459 |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
460 part_write_bodystructure_siblings(part->children, str, extended); |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
461 str_printfa(str, " %u", part->body_size.lines); |
0 | 462 } |
463 | |
464 if (!extended) | |
465 return; | |
466 | |
467 /* BODYSTRUCTURE data */ | |
468 | |
469 /* "md5" ("content disposition" ("disposition" "params")) | |
7949
e787f6cae97c
Added missing Content-Language: support for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
470 ("body" "language" "params") "location" */ |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
471 str_append_c(str, ' '); |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
472 imap_append_nstring(str, data->content_md5); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
473 part_write_bodystructure_common(data, str); |
0 | 474 } |
475 | |
7912
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
476 bool imap_bodystructure_is_plain_7bit(const struct message_part *part) |
3460
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
477 { |
21622
b6b198961bc6
lib-mail: Gave message_part_data its own field in struct message_part.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21621
diff
changeset
|
478 const struct message_part_data *data = part->data; |
3460
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
479 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
480 i_assert(part->parent == NULL); |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
481 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
482 /* if content-type is text/xxx we don't have to check any |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
483 multipart stuff */ |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
484 if ((part->flags & MESSAGE_PART_FLAG_TEXT) == 0) |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
485 return FALSE; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
486 if (part->next != NULL || part->children != NULL) |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
487 return FALSE; /* shouldn't happen normally.. */ |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
488 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
489 /* must be text/plain */ |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
490 if (data->content_subtype != NULL && |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
491 strcasecmp(data->content_subtype, "plain") != 0) |
3460
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
492 return FALSE; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
493 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
494 /* only allowed parameter is charset=us-ascii, which is also default */ |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
495 if (data->content_type_params_count > 0 && |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
496 (strcasecmp(data->content_type_params[0].name, "charset") != 0 || |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
497 strcasecmp(data->content_type_params[0].value, DEFAULT_CHARSET) != 0)) |
3460
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
498 return FALSE; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
499 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
500 if (data->content_id != NULL || |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
501 data->content_description != NULL) |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
502 return FALSE; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
503 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
504 if (data->content_transfer_encoding != NULL && |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
505 strcasecmp(data->content_transfer_encoding, "7bit") != 0) |
3460
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
506 return FALSE; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
507 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
508 /* BODYSTRUCTURE checks: */ |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
509 if (data->content_md5 != NULL || |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
510 data->content_disposition != NULL || |
7949
e787f6cae97c
Added missing Content-Language: support for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
511 data->content_language != NULL || |
e787f6cae97c
Added missing Content-Language: support for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
512 data->content_location != NULL) |
3460
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
513 return FALSE; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
514 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
515 return TRUE; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
516 } |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
517 |
5334
8d9234a26a3f
Make imap_bodystructure_write() parameter constant. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
518 void imap_bodystructure_write(const struct message_part *part, |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3571
diff
changeset
|
519 string_t *dest, bool extended) |
0 | 520 { |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
521 if (part->flags & MESSAGE_PART_FLAG_MULTIPART) |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
522 part_write_body_multipart(part, dest, extended); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
523 else |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
524 part_write_body(part, dest, extended); |
0 | 525 } |
526 | |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
527 static int |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
528 imap_bodystructure_strlist_parse(const struct imap_arg *arg, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
529 pool_t pool, const char *const **list_r) |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
530 { |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
531 const char *item, **list; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
532 const struct imap_arg *list_args; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
533 unsigned int list_count, i; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
534 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
535 if (arg->type == IMAP_ARG_NIL) { |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
536 *list_r = NULL; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
537 return 0; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
538 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
539 if (imap_arg_get_nstring(arg, &item)) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
540 list = p_new(pool, const char *, 2); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
541 list[0] = p_strdup(pool, item); |
21618
9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21614
diff
changeset
|
542 } else { |
9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21614
diff
changeset
|
543 if (!imap_arg_get_list_full(arg, &list_args, &list_count)) |
9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21614
diff
changeset
|
544 return -1; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
545 |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
546 list = p_new(pool, const char *, list_count+1); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
547 for (i = 0; i < list_count; i++) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
548 if (!imap_arg_get_nstring(&list_args[i], &item)) |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
549 return -1; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
550 list[i] = p_strdup(pool, item); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
551 } |
21618
9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21614
diff
changeset
|
552 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
553 *list_r = list; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
554 return 0; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
555 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
556 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
557 static int |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
558 imap_bodystructure_params_parse(const struct imap_arg *arg, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
559 pool_t pool, const struct message_part_param **params_r, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
560 unsigned int *count_r) |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
561 { |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
562 struct message_part_param *params; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
563 const struct imap_arg *list_args; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
564 unsigned int list_count, params_count, i; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
565 |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
566 if (arg->type == IMAP_ARG_NIL) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
567 *params_r = NULL; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
568 return 0; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
569 } |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
570 if (!imap_arg_get_list_full(arg, &list_args, &list_count)) |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
571 return -1; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
572 if ((list_count % 2) != 0) |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
573 return -1; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
574 |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
575 params_count = list_count/2; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
576 params = p_new(pool, struct message_part_param, params_count+1); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
577 for (i = 0; i < params_count; i++) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
578 const char *name, *value; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
579 |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
580 if (!imap_arg_get_nstring(&list_args[i*2+0], &name)) |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
581 return -1; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
582 if (!imap_arg_get_nstring(&list_args[i*2+1], &value)) |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
583 return -1; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
584 params[i].name = p_strdup(pool, name); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
585 params[i].value = p_strdup(pool, value); |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
586 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
587 *params_r = params; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
588 *count_r = params_count; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
589 return 0; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
590 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
591 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
592 static int |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
593 imap_bodystructure_parse_args_common(struct message_part *part, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
594 pool_t pool, const struct imap_arg *args, |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
595 const char **error_r) |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
596 { |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
597 struct message_part_data *data = part->data; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
598 const struct imap_arg *list_args; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
599 |
21618
9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21614
diff
changeset
|
600 if (args->type == IMAP_ARG_EOL) |
9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21614
diff
changeset
|
601 return 0; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
602 if (args->type == IMAP_ARG_NIL) |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
603 args++; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
604 else if (!imap_arg_get_list(args, &list_args)) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
605 *error_r = "Invalid content-disposition list"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
606 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
607 } else { |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
608 if (!imap_arg_get_nstring |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
609 (list_args++, &data->content_disposition)) { |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
610 *error_r = "Invalid content-disposition"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
611 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
612 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
613 data->content_disposition = p_strdup(pool, data->content_disposition); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
614 if (imap_bodystructure_params_parse(list_args, pool, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
615 &data->content_disposition_params, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
616 &data->content_disposition_params_count) < 0) { |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
617 *error_r = "Invalid content-disposition params"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
618 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
619 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
620 args++; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
621 } |
21618
9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21614
diff
changeset
|
622 if (args->type == IMAP_ARG_EOL) |
9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21614
diff
changeset
|
623 return 0; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
624 if (imap_bodystructure_strlist_parse |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
625 (args++, pool, &data->content_language) < 0) { |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
626 *error_r = "Invalid content-language"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
627 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
628 } |
21618
9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21614
diff
changeset
|
629 if (args->type == IMAP_ARG_EOL) |
9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21614
diff
changeset
|
630 return 0; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
631 if (!imap_arg_get_nstring |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
632 (args++, &data->content_location)) { |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
633 *error_r = "Invalid content-location"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
634 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
635 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
636 data->content_location = p_strdup(pool, data->content_location); |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
637 return 0; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
638 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
639 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
640 static int |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
641 imap_bodystructure_parse_args(const struct imap_arg *args, pool_t pool, |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
642 struct message_part *part, |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
643 const char **error_r) |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
644 { |
21621
4e137a17cfd7
lib-imap: imap-bodystructure: Renamed struct message_part_body_data to message_part_data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21618
diff
changeset
|
645 struct message_part_data *data; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
646 struct message_part *child_part; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
647 const struct imap_arg *list_args; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
648 const char *value, *content_type, *subtype, *error; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
649 bool multipart, text, message_rfc822, has_lines; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
650 unsigned int lines; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
651 uoff_t vsize; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
652 |
21622
b6b198961bc6
lib-mail: Gave message_part_data its own field in struct message_part.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21621
diff
changeset
|
653 i_assert(part->data == NULL); |
b6b198961bc6
lib-mail: Gave message_part_data its own field in struct message_part.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21621
diff
changeset
|
654 part->data = data = p_new(pool, struct message_part_data, 1); |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
655 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
656 multipart = FALSE; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
657 child_part = part->children; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
658 while (args->type == IMAP_ARG_LIST) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
659 if ((part->flags & MESSAGE_PART_FLAG_MULTIPART) == 0 || |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
660 child_part == NULL) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
661 *error_r = "message_part hierarchy doesn't match BODYSTRUCTURE"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
662 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
663 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
664 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
665 list_args = imap_arg_as_list(args); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
666 if (imap_bodystructure_parse_args(list_args, pool, |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
667 child_part, error_r) < 0) |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
668 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
669 child_part = child_part->next; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
670 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
671 multipart = TRUE; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
672 args++; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
673 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
674 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
675 if (multipart) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
676 if (child_part != NULL) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
677 *error_r = "message_part hierarchy doesn't match BODYSTRUCTURE"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
678 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
679 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
680 data->content_type = "multipart"; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
681 if (!imap_arg_get_nstring(args++, &data->content_subtype)) { |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
682 *error_r = "Invalid multipart content-type"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
683 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
684 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
685 data->content_subtype = p_strdup(pool, data->content_subtype); |
21618
9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21614
diff
changeset
|
686 if (args->type == IMAP_ARG_EOL) |
9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21614
diff
changeset
|
687 return 0; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
688 if (imap_bodystructure_params_parse(args++, pool, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
689 &data->content_type_params, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
690 &data->content_type_params_count) < 0) { |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
691 *error_r = "Invalid content params"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
692 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
693 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
694 return imap_bodystructure_parse_args_common |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
695 (part, pool, args, error_r); |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
696 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
697 if ((part->flags & MESSAGE_PART_FLAG_MULTIPART) != 0) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
698 *error_r = "message_part multipart flag doesn't match BODYSTRUCTURE"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
699 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
700 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
701 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
702 /* "content type" "subtype" */ |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
703 if (!imap_arg_get_astring(&args[0], &content_type) || |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
704 !imap_arg_get_astring(&args[1], &subtype)) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
705 *error_r = "Invalid content-type"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
706 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
707 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
708 data->content_type = p_strdup(pool, content_type); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
709 data->content_subtype = p_strdup(pool, subtype); |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
710 args += 2; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
711 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
712 text = strcasecmp(content_type, "text") == 0; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
713 message_rfc822 = strcasecmp(content_type, "message") == 0 && |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
714 strcasecmp(subtype, "rfc822") == 0; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
715 |
20890
d946c76fb3d4
lib-imap: imap_bodystructure_parse() ignores text/plain flag mismatch for now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20889
diff
changeset
|
716 #if 0 |
d946c76fb3d4
lib-imap: imap_bodystructure_parse() ignores text/plain flag mismatch for now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20889
diff
changeset
|
717 /* Disabled for now. Earlier Dovecot versions handled broken |
d946c76fb3d4
lib-imap: imap_bodystructure_parse() ignores text/plain flag mismatch for now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20889
diff
changeset
|
718 Content-Type headers by writing them as "text" "plain" to |
d946c76fb3d4
lib-imap: imap_bodystructure_parse() ignores text/plain flag mismatch for now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20889
diff
changeset
|
719 BODYSTRUCTURE reply, but the message_part didn't have |
d946c76fb3d4
lib-imap: imap_bodystructure_parse() ignores text/plain flag mismatch for now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20889
diff
changeset
|
720 MESSAGE_PART_FLAG_TEXT. */ |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
721 if (text != ((part->flags & MESSAGE_PART_FLAG_TEXT) != 0)) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
722 *error_r = "message_part text flag doesn't match BODYSTRUCTURE"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
723 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
724 } |
20890
d946c76fb3d4
lib-imap: imap_bodystructure_parse() ignores text/plain flag mismatch for now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20889
diff
changeset
|
725 #endif |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
726 if (message_rfc822 != ((part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) != 0)) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
727 *error_r = "message_part message/rfc822 flag doesn't match BODYSTRUCTURE"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
728 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
729 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
730 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
731 /* ("content type param key" "value" ...) | NIL */ |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
732 if (imap_bodystructure_params_parse(args++, pool, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
733 &data->content_type_params, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
734 &data->content_type_params_count) < 0) { |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
735 *error_r = "Invalid content params"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
736 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
737 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
738 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
739 /* "content id" "content description" "transfer encoding" size */ |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
740 if (!imap_arg_get_nstring(args++, &data->content_id)) { |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
741 *error_r = "Invalid content-id"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
742 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
743 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
744 if (!imap_arg_get_nstring(args++, &data->content_description)) { |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
745 *error_r = "Invalid content-description"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
746 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
747 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
748 if (!imap_arg_get_nstring(args++, &data->content_transfer_encoding)) { |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
749 *error_r = "Invalid content-transfer-encoding"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
750 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
751 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
752 data->content_id = p_strdup(pool, data->content_id); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
753 data->content_description = p_strdup(pool, data->content_description); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
754 data->content_transfer_encoding = |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
755 p_strdup(pool, data->content_transfer_encoding); |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
756 if (!imap_arg_get_atom(args++, &value) || |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
757 str_to_uoff(value, &vsize) < 0) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
758 *error_r = "Invalid size field"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
759 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
760 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
761 if (vsize != part->body_size.virtual_size) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
762 *error_r = "message_part virtual_size doesn't match " |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
763 "size in BODYSTRUCTURE"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
764 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
765 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
766 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
767 if (text) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
768 /* text/xxx - text lines */ |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
769 if (!imap_arg_get_atom(args++, &value) || |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
770 str_to_uint(value, &lines) < 0) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
771 *error_r = "Invalid lines field"; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
772 return -1; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
773 } |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
774 i_assert(part->children == NULL); |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
775 has_lines = TRUE; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
776 } else if (message_rfc822) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
777 /* message/rfc822 - envelope + bodystructure + text lines */ |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
778 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
779 i_assert(part->children != NULL && |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
780 part->children->next == NULL); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
781 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
782 if (!imap_arg_get_list(&args[1], &list_args)) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
783 *error_r = "Child bodystructure list expected"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
784 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
785 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
786 if (imap_bodystructure_parse_args |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
787 (list_args, pool, part->children, error_r) < 0) |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
788 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
789 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
790 if (!imap_arg_get_list(&args[0], &list_args)) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
791 *error_r = "Envelope list expected"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
792 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
793 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
794 if (!imap_envelope_parse_args(list_args, pool, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
795 &part->children->data->envelope, &error)) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
796 *error_r = t_strdup_printf |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
797 ("Invalid envelope list: %s", error); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
798 return -1; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
799 } |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
800 args += 2; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
801 if (!imap_arg_get_atom(args++, &value) || |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
802 str_to_uint(value, &lines) < 0) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
803 *error_r = "Invalid lines field"; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
804 return -1; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
805 } |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
806 has_lines = TRUE; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
807 } else { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
808 i_assert(part->children == NULL); |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
809 has_lines = FALSE; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
810 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
811 if (has_lines && lines != part->body_size.lines) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
812 *error_r = "message_part lines " |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
813 "doesn't match lines in BODYSTRUCTURE"; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
814 return -1; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
815 } |
21618
9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21614
diff
changeset
|
816 if (args->type == IMAP_ARG_EOL) |
9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21614
diff
changeset
|
817 return 0; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
818 if (!imap_arg_get_nstring(args++, &data->content_md5)) { |
21614
6629c995bb2a
lib-imap: imap-bodystructure: Fixed parse error message about invalid Content-M5 field.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
819 *error_r = "Invalid content-md5"; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
820 return -1; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
821 } |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
822 data->content_md5 = p_strdup(pool, data->content_md5); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
823 return imap_bodystructure_parse_args_common |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
824 (part, pool, args, error_r); |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
825 } |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
826 |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
827 int imap_bodystructure_parse(const char *bodystructure, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
828 pool_t pool, struct message_part *parts, |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
829 const char **error_r) |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
830 { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
831 struct istream *input; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
832 struct imap_parser *parser; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
833 const struct imap_arg *args; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
834 char *error; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
835 int ret; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
836 bool fatal; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
837 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
838 i_assert(parts != NULL); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
839 i_assert(parts->next == NULL); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
840 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
841 input = i_stream_create_from_data(bodystructure, strlen(bodystructure)); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
842 (void)i_stream_read(input); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
843 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
844 parser = imap_parser_create(input, NULL, (size_t)-1); |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
845 ret = imap_parser_finish_line(parser, 0, |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
846 IMAP_PARSE_FLAG_LITERAL_TYPE, &args); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
847 if (ret < 0) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
848 *error_r = t_strdup_printf("IMAP parser failed: %s", |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
849 imap_parser_get_error(parser, &fatal)); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
850 } else if (ret == 0) { |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
851 *error_r = "Empty bodystructure"; |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
852 ret = -1; |
21627
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
853 } else { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
854 T_BEGIN { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
855 ret = imap_bodystructure_parse_args |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
856 (args, pool, parts, error_r); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
857 if (ret < 0) |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
858 error = i_strdup(*error_r); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
859 } T_END; |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
860 |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
861 if (ret < 0) { |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
862 *error_r = t_strdup(error); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
863 i_free(error); |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
864 } |
6ced094b1759
lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21625
diff
changeset
|
865 } |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
866 |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
867 imap_parser_unref(&parser); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
868 i_stream_destroy(&input); |
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
869 return ret; |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
870 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
871 |
21628
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
872 static bool str_append_nstring(string_t *str, const struct imap_arg *arg) |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
873 { |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
874 const char *cstr; |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
875 |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
876 if (!imap_arg_get_nstring(arg, &cstr)) |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
877 return FALSE; |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
878 |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
879 switch (arg->type) { |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
880 case IMAP_ARG_NIL: |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
881 str_append(str, "NIL"); |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
882 break; |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
883 case IMAP_ARG_ATOM: |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
884 str_append(str, cstr); |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
885 break; |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
886 case IMAP_ARG_STRING: |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
887 str_append_c(str, '"'); |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
888 /* NOTE: we're parsing with no-unescape flag, |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
889 so don't double-escape it here */ |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
890 str_append(str, cstr); |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
891 str_append_c(str, '"'); |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
892 break; |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
893 case IMAP_ARG_LITERAL: { |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
894 str_printfa(str, "{%"PRIuSIZE_T"}\r\n", strlen(cstr)); |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
895 str_append(str, cstr); |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
896 break; |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
897 } |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
898 default: |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
899 i_unreached(); |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
900 return FALSE; |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
901 } |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
902 return TRUE; |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
903 } |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
904 |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
905 static void |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
906 imap_write_envelope_list(const struct imap_arg *args, string_t *str, |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
907 bool toplevel) |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
908 { |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
909 const struct imap_arg *children; |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
910 |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
911 /* don't do any typechecking, just write it out */ |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
912 while (!IMAP_ARG_IS_EOL(args)) { |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
913 bool list = FALSE; |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
914 |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
915 if (!str_append_nstring(str, args)) { |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
916 if (!imap_arg_get_list(args, &children)) { |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
917 /* everything is either nstring or list */ |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
918 i_unreached(); |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
919 } |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
920 |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
921 str_append_c(str, '('); |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
922 imap_write_envelope_list(children, str, FALSE); |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
923 str_append_c(str, ')'); |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
924 |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
925 list = TRUE; |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
926 } |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
927 args++; |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
928 |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
929 if ((toplevel || !list) && !IMAP_ARG_IS_EOL(args)) |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
930 str_append_c(str, ' '); |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
931 } |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
932 } |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
933 |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
934 static void |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
935 imap_write_envelope(const struct imap_arg *args, string_t *str) |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
936 { |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
937 imap_write_envelope_list(args, str, TRUE); |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
938 } |
a22181aad13a
lib-imap: imap-bodystructure: Grouped together functions relating to the conversion of BODYSTRUCTURE to BODY.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21627
diff
changeset
|
939 |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
940 static int imap_parse_bodystructure_args(const struct imap_arg *args, |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
941 string_t *str, const char **error_r) |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
942 { |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5334
diff
changeset
|
943 const struct imap_arg *subargs; |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
944 const struct imap_arg *list_args; |
11063
dbc864c0cff7
lib-imap: Changed imap_arg accessing APIs.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
945 const char *value, *content_type, *subtype; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3571
diff
changeset
|
946 bool multipart, text, message_rfc822; |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3571
diff
changeset
|
947 int i; |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
948 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
949 multipart = FALSE; |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
950 while (args->type == IMAP_ARG_LIST) { |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
951 str_append_c(str, '('); |
11063
dbc864c0cff7
lib-imap: Changed imap_arg accessing APIs.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
952 list_args = imap_arg_as_list(args); |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
953 if (imap_parse_bodystructure_args(list_args, str, error_r) < 0) |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
954 return -1; |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
955 str_append_c(str, ')'); |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
956 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
957 multipart = TRUE; |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
958 args++; |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
959 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
960 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
961 if (multipart) { |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
962 /* next is subtype of Content-Type. rest is skipped. */ |
1107
4044c2903ed7
Don't do x-unknown mime encoding. Correct way is to just send them as
Timo Sirainen <tss@iki.fi>
parents:
913
diff
changeset
|
963 str_append_c(str, ' '); |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
964 if (!str_append_nstring(str, args)) { |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
965 *error_r = "Invalid multipart content-type"; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
966 return -1; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
967 } |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
968 return 0; |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
969 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
970 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
971 /* "content type" "subtype" */ |
11063
dbc864c0cff7
lib-imap: Changed imap_arg accessing APIs.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
972 if (!imap_arg_get_astring(&args[0], &content_type) || |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
973 !imap_arg_get_astring(&args[1], &subtype)) { |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
974 *error_r = "Invalid content-type"; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
975 return -1; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
976 } |
1107
4044c2903ed7
Don't do x-unknown mime encoding. Correct way is to just send them as
Timo Sirainen <tss@iki.fi>
parents:
913
diff
changeset
|
977 |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
978 if (!str_append_nstring(str, &args[0])) |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
979 i_unreached(); |
1107
4044c2903ed7
Don't do x-unknown mime encoding. Correct way is to just send them as
Timo Sirainen <tss@iki.fi>
parents:
913
diff
changeset
|
980 str_append_c(str, ' '); |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
981 if (!str_append_nstring(str, &args[1])) |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
982 i_unreached(); |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
983 |
11063
dbc864c0cff7
lib-imap: Changed imap_arg accessing APIs.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
984 text = strcasecmp(content_type, "text") == 0; |
dbc864c0cff7
lib-imap: Changed imap_arg accessing APIs.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
985 message_rfc822 = strcasecmp(content_type, "message") == 0 && |
dbc864c0cff7
lib-imap: Changed imap_arg accessing APIs.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
986 strcasecmp(subtype, "rfc822") == 0; |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
987 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
988 args += 2; |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
989 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
990 /* ("content type param key" "value" ...) | NIL */ |
11063
dbc864c0cff7
lib-imap: Changed imap_arg accessing APIs.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
991 if (imap_arg_get_list(args, &subargs)) { |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
992 str_append(str, " ("); |
11063
dbc864c0cff7
lib-imap: Changed imap_arg accessing APIs.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
993 while (!IMAP_ARG_IS_EOL(subargs)) { |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
994 if (!str_append_nstring(str, &subargs[0])) { |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
995 *error_r = "Invalid content param key"; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
996 return -1; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
997 } |
1107
4044c2903ed7
Don't do x-unknown mime encoding. Correct way is to just send them as
Timo Sirainen <tss@iki.fi>
parents:
913
diff
changeset
|
998 str_append_c(str, ' '); |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
999 if (!str_append_nstring(str, &subargs[1])) { |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1000 *error_r = "Invalid content param value"; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1001 return -1; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1002 } |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1003 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1004 subargs += 2; |
11063
dbc864c0cff7
lib-imap: Changed imap_arg accessing APIs.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
1005 if (IMAP_ARG_IS_EOL(subargs)) |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1006 break; |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
1007 str_append_c(str, ' '); |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1008 } |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
1009 str_append(str, ")"); |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1010 } else if (args->type == IMAP_ARG_NIL) { |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
1011 str_append(str, " NIL"); |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1012 } else { |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1013 *error_r = "list/NIL expected"; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1014 return -1; |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1015 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1016 args++; |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1017 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1018 /* "content id" "content description" "transfer encoding" size */ |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1019 for (i = 0; i < 4; i++, args++) { |
1107
4044c2903ed7
Don't do x-unknown mime encoding. Correct way is to just send them as
Timo Sirainen <tss@iki.fi>
parents:
913
diff
changeset
|
1020 str_append_c(str, ' '); |
4044c2903ed7
Don't do x-unknown mime encoding. Correct way is to just send them as
Timo Sirainen <tss@iki.fi>
parents:
913
diff
changeset
|
1021 |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1022 if (!str_append_nstring(str, args)) { |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1023 *error_r = "nstring expected"; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1024 return -1; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1025 } |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1026 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1027 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1028 if (text) { |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1029 /* text/xxx - text lines */ |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1030 if (!imap_arg_get_atom(args, &value)) { |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1031 *error_r = "Text lines expected"; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1032 return -1; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1033 } |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1034 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
1035 str_append_c(str, ' '); |
11063
dbc864c0cff7
lib-imap: Changed imap_arg accessing APIs.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
1036 str_append(str, value); |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1037 } else if (message_rfc822) { |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1038 /* message/rfc822 - envelope + bodystructure + text lines */ |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
1039 str_append_c(str, ' '); |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1040 |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1041 if (!imap_arg_get_list(&args[0], &list_args)) { |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1042 *error_r = "Envelope list expected"; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1043 return -1; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1044 } |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
1045 str_append_c(str, '('); |
21294
dfa20786a81d
lib-imap: imap-bodystructure: Prevent writing erroneous whitespace between items in an envelope address list.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
20890
diff
changeset
|
1046 imap_write_envelope(list_args, str); |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
1047 str_append(str, ") ("); |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1048 |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1049 if (!imap_arg_get_list(&args[1], &list_args)) { |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1050 *error_r = "Child bodystructure list expected"; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1051 return -1; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1052 } |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1053 if (imap_parse_bodystructure_args(list_args, str, error_r) < 0) |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1054 return -1; |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1055 |
4027
0e7a9b0aa8c3
BODYSTRUCTURE -> BODY conversion was broken with mails containing
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1056 str_append(str, ") "); |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1057 if (!imap_arg_get_atom(&args[2], &value)) { |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1058 *error_r = "Text lines expected"; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1059 return -1; |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1060 } |
11063
dbc864c0cff7
lib-imap: Changed imap_arg accessing APIs.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
1061 str_append(str, value); |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1062 } |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1063 return 0; |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1064 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1065 |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1066 int imap_body_parse_from_bodystructure(const char *bodystructure, |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1067 string_t *dest, const char **error_r) |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1068 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
1069 struct istream *input; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
1070 struct imap_parser *parser; |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5334
diff
changeset
|
1071 const struct imap_arg *args; |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1072 bool fatal; |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1073 int ret; |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1074 |
6142
6c0bfc35af03
Removed memory pool parameter from iostreams. Default pool was almost always
Timo Sirainen <tss@iki.fi>
parents:
6117
diff
changeset
|
1075 input = i_stream_create_from_data(bodystructure, strlen(bodystructure)); |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
647
diff
changeset
|
1076 (void)i_stream_read(input); |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1077 |
1591
6eca99b727a0
IMAP parser memory limits are now enforced by bytes per line rather than
Timo Sirainen <tss@iki.fi>
parents:
1568
diff
changeset
|
1078 parser = imap_parser_create(input, NULL, (size_t)-1); |
1661
566fb4bf7066
Fixes for parsing BODYSTRUCTURE
Timo Sirainen <tss@iki.fi>
parents:
1619
diff
changeset
|
1079 ret = imap_parser_finish_line(parser, 0, IMAP_PARSE_FLAG_NO_UNESCAPE | |
566fb4bf7066
Fixes for parsing BODYSTRUCTURE
Timo Sirainen <tss@iki.fi>
parents:
1619
diff
changeset
|
1080 IMAP_PARSE_FLAG_LITERAL_TYPE, &args); |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1081 if (ret < 0) { |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1082 *error_r = t_strdup_printf("IMAP parser failed: %s", |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1083 imap_parser_get_error(parser, &fatal)); |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1084 } else if (ret == 0) { |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1085 *error_r = "Empty bodystructure"; |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
1086 ret = -1; |
15056
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1087 } else { |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1088 ret = imap_parse_bodystructure_args(args, dest, error_r); |
6acd8b149709
imap_body_parse_from_bodystructure() now returns the error instead of logging it.
Timo Sirainen <tss@iki.fi>
parents:
14689
diff
changeset
|
1089 } |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1090 |
13627
f63f2b2217c3
lib-imap: Added reference counting to imap parser.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1091 imap_parser_unref(&parser); |
4070
71b8faa84ec6
Added i_stream_destroy() and o_stream_destroy() and used them instead of
Timo Sirainen <tss@iki.fi>
parents:
4027
diff
changeset
|
1092 i_stream_destroy(&input); |
15057
d1f084a39708
lib-imap: Added support for parsing IMAP BODYSTRUCTURE and writing out a modified version.
Timo Sirainen <tss@iki.fi>
parents:
15056
diff
changeset
|
1093 return ret; |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
1094 } |