Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-imap/imap-bodystructure.c @ 6940:414c9d631a81 HEAD
Replaced t_push/t_pop calls with T_FRAME*() macros.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 05 Dec 2007 17:47:44 +0200 |
parents | 65c69a53a7be |
children | 6835ac721609 |
rev | line source |
---|---|
6429
65c69a53a7be
Replaced my Copyright notices. The year range always ends with 2007 now.
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
1 /* Copyright (c) 2002-2007 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" |
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
|
9 #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
|
10 #include "imap-quote.h" |
0 | 11 #include "imap-envelope.h" |
12 #include "imap-bodystructure.h" | |
13 | |
1537
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
14 #define DEFAULT_CHARSET \ |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
15 "\"charset\" \"us-ascii\"" |
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 \ |
1537
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
18 "(\"text\" \"plain\" ("DEFAULT_CHARSET") NIL NIL \"7bit\" 0 0)" |
0 | 19 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
20 struct message_part_body_data { |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
21 pool_t pool; |
4816
8ac2a2d27364
Cleanup: Don't put string literals into non-const pointers.
Timo Sirainen <tss@iki.fi>
parents:
4280
diff
changeset
|
22 const char *content_type, *content_subtype; |
8ac2a2d27364
Cleanup: Don't put string literals into non-const pointers.
Timo Sirainen <tss@iki.fi>
parents:
4280
diff
changeset
|
23 const char *content_type_params; |
8ac2a2d27364
Cleanup: Don't put string literals into non-const pointers.
Timo Sirainen <tss@iki.fi>
parents:
4280
diff
changeset
|
24 const char *content_transfer_encoding; |
8ac2a2d27364
Cleanup: Don't put string literals into non-const pointers.
Timo Sirainen <tss@iki.fi>
parents:
4280
diff
changeset
|
25 const char *content_id; |
8ac2a2d27364
Cleanup: Don't put string literals into non-const pointers.
Timo Sirainen <tss@iki.fi>
parents:
4280
diff
changeset
|
26 const char *content_description; |
8ac2a2d27364
Cleanup: Don't put string literals into non-const pointers.
Timo Sirainen <tss@iki.fi>
parents:
4280
diff
changeset
|
27 const char *content_disposition; |
8ac2a2d27364
Cleanup: Don't put string literals into non-const pointers.
Timo Sirainen <tss@iki.fi>
parents:
4280
diff
changeset
|
28 const char *content_disposition_params; |
8ac2a2d27364
Cleanup: Don't put string literals into non-const pointers.
Timo Sirainen <tss@iki.fi>
parents:
4280
diff
changeset
|
29 const char *content_md5; |
8ac2a2d27364
Cleanup: Don't put string literals into non-const pointers.
Timo Sirainen <tss@iki.fi>
parents:
4280
diff
changeset
|
30 const char *content_language; |
0 | 31 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
32 struct message_part_envelope_data *envelope; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
33 }; |
0 | 34 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
35 static void parse_content_type(struct message_part_body_data *data, |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
36 struct message_header_line *hdr) |
0 | 37 { |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
38 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
|
39 const char *key, *value; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
40 string_t *str; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
41 unsigned int i; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
42 bool charset_found = FALSE; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
43 |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
44 rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
45 (void)rfc822_skip_lwsp(&parser); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
46 |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
47 str = t_str_new(256); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
48 if (rfc822_parse_content_type(&parser, str) < 0) |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
49 return; |
0 | 50 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
51 /* 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
|
52 value = str_c(str); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
53 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
|
54 if (value[i] == '/') { |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
55 data->content_subtype = |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
56 imap_quote(data->pool, str_data(str) + i + 1, |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
57 str_len(str) - (i + 1)); |
0 | 58 break; |
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 } |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
61 data->content_type = |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
62 imap_quote(data->pool, str_data(str), i); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
63 |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
64 /* parse parameters and save them */ |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
65 str_truncate(str, 0); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
66 while (rfc822_parse_content_param(&parser, &key, &value) > 0) { |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
67 if (strcasecmp(key, "charset") == 0) |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
68 charset_found = TRUE; |
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 str_append_c(str, ' '); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
71 imap_quote_append_string(str, key, TRUE); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
72 str_append_c(str, ' '); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
73 imap_quote_append_string(str, value, TRUE); |
0 | 74 } |
75 | |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
76 if (!charset_found && |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
77 strcasecmp(data->content_type, "\"text\"") == 0) { |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
78 /* set a default charset */ |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
79 str_append_c(str, ' '); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
80 str_append(str, DEFAULT_CHARSET); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
81 } |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
82 if (str_len(str) > 0) { |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
83 data->content_type_params = |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
84 p_strdup(data->pool, str_c(str) + 1); |
896
21ffcce83c70
Rewrote rfc822-tokenize.c to work one token at a time so it won't uselessly
Timo Sirainen <tss@iki.fi>
parents:
877
diff
changeset
|
85 } |
0 | 86 } |
87 | |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
88 static void parse_content_transfer_encoding(struct message_part_body_data *data, |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
89 struct message_header_line *hdr) |
0 | 90 { |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
91 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
|
92 string_t *str; |
0 | 93 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
94 rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
95 (void)rfc822_skip_lwsp(&parser); |
0 | 96 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
97 str = t_str_new(256); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
98 if (rfc822_parse_mime_token(&parser, str) >= 0) { |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
99 data->content_transfer_encoding = |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
100 imap_quote(data->pool, str_data(str), str_len(str)); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
101 } |
0 | 102 } |
103 | |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
104 static void parse_content_disposition(struct message_part_body_data *data, |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
105 struct message_header_line *hdr) |
0 | 106 { |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
107 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
|
108 const char *key, *value; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
109 string_t *str; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
110 |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
111 rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
112 (void)rfc822_skip_lwsp(&parser); |
0 | 113 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
114 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
|
115 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
|
116 return; |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
117 data->content_disposition = |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
118 imap_quote(data->pool, str_data(str), str_len(str)); |
0 | 119 |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
120 /* parse parameters and save them */ |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
121 str_truncate(str, 0); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
122 while (rfc822_parse_content_param(&parser, &key, &value) > 0) { |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
123 str_append_c(str, ' '); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
124 imap_quote_append_string(str, key, TRUE); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
125 str_append_c(str, ' '); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
126 imap_quote_append_string(str, value, TRUE); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
127 } |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
128 if (str_len(str) > 0) { |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
129 data->content_disposition_params = |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
130 p_strdup(data->pool, str_c(str) + 1); |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
131 } |
0 | 132 } |
133 | |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
134 static void parse_content_language(const unsigned char *value, size_t value_len, |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
135 struct message_part_body_data *data) |
0 | 136 { |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
137 struct rfc822_parser_context parser; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
138 string_t *str; |
398
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
139 |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
140 /* 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
|
141 Language-Tag = Primary-tag *( "-" Subtag ) |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
142 Primary-tag = 1*8ALPHA |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
143 Subtag = 1*8ALPHA */ |
0 | 144 |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
145 rfc822_parser_init(&parser, value, value_len, NULL); |
0 | 146 |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
147 str = t_str_new(128); |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
148 str_append_c(str, '"'); |
0 | 149 |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
150 (void)rfc822_skip_lwsp(&parser); |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
151 while (rfc822_parse_atom(&parser, str) >= 0) { |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
152 str_append(str, "\" \""); |
398
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
153 |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
154 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
|
155 break; |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
156 parser.data++; |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
157 (void)rfc822_skip_lwsp(&parser); |
398
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
158 } |
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
159 |
3407
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
160 if (str_len(str) > 1) { |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
161 str_truncate(str, str_len(str) - 2); |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
162 data->content_language = p_strdup(data->pool, str_c(str)); |
f484ad51ad9f
Make Content-Language parser use rfc822-parser API.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
163 } |
0 | 164 } |
165 | |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
166 static void parse_content_header(struct message_part_body_data *d, |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
167 struct message_header_line *hdr, |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
168 pool_t pool) |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
169 { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
170 const char *name = hdr->name + strlen("Content-"); |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
171 const unsigned char *value; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
172 size_t value_len; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
173 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
174 if (hdr->continues) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
175 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
|
176 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
177 } |
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 value = hdr->full_value; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
180 value_len = hdr->full_value_len; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
181 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
182 switch (*name) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
183 case 'i': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
184 case 'I': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
185 if (strcasecmp(name, "ID") == 0 && d->content_id == NULL) |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
186 d->content_id = imap_quote(pool, value, value_len); |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
187 break; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
188 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
189 case 'm': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
190 case 'M': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
191 if (strcasecmp(name, "MD5") == 0 && d->content_md5 == NULL) |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
192 d->content_md5 = imap_quote(pool, value, value_len); |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
193 break; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
194 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
195 case 't': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
196 case 'T': |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
197 if (strcasecmp(name, "Type") == 0 && d->content_type == NULL) |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
198 parse_content_type(d, hdr); |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
199 if (strcasecmp(name, "Transfer-Encoding") == 0 && |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
200 d->content_transfer_encoding == NULL) |
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
201 parse_content_transfer_encoding(d, hdr); |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
202 break; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
203 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
204 case 'l': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
205 case 'L': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
206 if (strcasecmp(name, "Language") == 0 && |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
207 d->content_language == NULL) |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
208 parse_content_language(value, value_len, d); |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
209 break; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
210 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
211 case 'd': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
212 case 'D': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
213 if (strcasecmp(name, "Description") == 0 && |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
214 d->content_description == NULL) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
215 d->content_description = |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
216 imap_quote(pool, value, value_len); |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
217 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
218 if (strcasecmp(name, "Disposition") == 0 && |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
219 d->content_disposition_params == NULL) { |
6117
9214044ce1f1
Removed message-content-parser. Instead added rfc822_parse_content_type()
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
220 parse_content_disposition(d, hdr); |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
221 } |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
222 break; |
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 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
225 |
1689
c07b98265577
If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents:
1665
diff
changeset
|
226 void imap_bodystructure_parse_header(pool_t pool, struct message_part *part, |
c07b98265577
If BODY/BODYSTRUCTURE is requested with some other headers, parse the
Timo Sirainen <tss@iki.fi>
parents:
1665
diff
changeset
|
227 struct message_header_line *hdr) |
0 | 228 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
229 struct message_part_body_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) { |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
234 /* If there was no Mime-Version, forget all the Content-stuff */ |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
235 if ((part->flags & MESSAGE_PART_FLAG_IS_MIME) == 0 && |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
236 part->context != NULL) { |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
237 part_data = part->context; |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
238 envelope = part_data->envelope; |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
239 |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
240 memset(part_data, 0, sizeof(*part_data)); |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
241 part_data->pool = pool; |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
242 part_data->envelope = envelope; |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
243 } |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
244 return; |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
245 } |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
246 |
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
247 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
|
248 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
249 |
106
5fe3e04ca8d9
Added support for caching of MessagePart data. This is useful for fetching
Timo Sirainen <tss@iki.fi>
parents:
105
diff
changeset
|
250 parent_rfc822 = part->parent != NULL && |
1619
5bdda4147b36
Fixes for handling missing Mime-Version
Timo Sirainen <tss@iki.fi>
parents:
1618
diff
changeset
|
251 (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
|
252 if (!parent_rfc822 && strncasecmp(hdr->name, "Content-", 8) != 0) |
0 | 253 return; |
254 | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
255 if (part->context == NULL) { |
0 | 256 /* initialize message part data */ |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
257 part->context = part_data = |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
258 p_new(pool, struct message_part_body_data, 1); |
0 | 259 part_data->pool = pool; |
260 } | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
261 part_data = part->context; |
0 | 262 |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
263 if (strncasecmp(hdr->name, "Content-", 8) == 0) { |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
264 T_FRAME( |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
265 parse_content_header(part_data, hdr, pool); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
266 ); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
267 } |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
268 |
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
269 if (parent_rfc822) { |
0 | 270 /* 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
|
271 imap_envelope_parse_header(pool, &part_data->envelope, hdr); |
0 | 272 } |
273 } | |
274 | |
5334
8d9234a26a3f
Make imap_bodystructure_write() parameter constant. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
275 static void part_write_body_multipart(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
|
276 string_t *str, bool extended) |
0 | 277 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
278 struct message_part_body_data *data = part->context; |
0 | 279 |
647
1acbf6c8758c
handle broken multipart messages without crashing
Timo Sirainen <tss@iki.fi>
parents:
593
diff
changeset
|
280 if (data == NULL) { |
1acbf6c8758c
handle broken multipart messages without crashing
Timo Sirainen <tss@iki.fi>
parents:
593
diff
changeset
|
281 /* there was no content headers, use an empty structure */ |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
282 data = t_new(struct message_part_body_data, 1); |
647
1acbf6c8758c
handle broken multipart messages without crashing
Timo Sirainen <tss@iki.fi>
parents:
593
diff
changeset
|
283 } |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
398
diff
changeset
|
284 |
0 | 285 if (part->children != NULL) |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
286 imap_bodystructure_write(part->children, str, extended); |
0 | 287 else { |
288 /* no parts in multipart message, | |
289 that's not allowed. write a single | |
290 0-length text/plain structure */ | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
291 str_append(str, EMPTY_BODYSTRUCTURE); |
0 | 292 } |
293 | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
294 str_append_c(str, ' '); |
647
1acbf6c8758c
handle broken multipart messages without crashing
Timo Sirainen <tss@iki.fi>
parents:
593
diff
changeset
|
295 if (data->content_subtype != 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
|
296 str_append(str, data->content_subtype); |
647
1acbf6c8758c
handle broken multipart messages without crashing
Timo Sirainen <tss@iki.fi>
parents:
593
diff
changeset
|
297 else |
896
21ffcce83c70
Rewrote rfc822-tokenize.c to work one token at a time so it won't uselessly
Timo Sirainen <tss@iki.fi>
parents:
877
diff
changeset
|
298 str_append(str, "\"x-unknown\""); |
0 | 299 |
300 if (!extended) | |
301 return; | |
302 | |
303 /* BODYSTRUCTURE data */ | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
304 str_append_c(str, ' '); |
0 | 305 if (data->content_type_params == 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
|
306 str_append(str, "NIL"); |
0 | 307 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
|
308 str_append_c(str, '('); |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
309 str_append(str, data->content_type_params); |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
310 str_append_c(str, ')'); |
0 | 311 } |
312 | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
313 str_append_c(str, ' '); |
0 | 314 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
|
315 str_append(str, "NIL"); |
0 | 316 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
|
317 str_append_c(str, '('); |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
318 str_append(str, data->content_disposition); |
862
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
319 str_append_c(str, ' '); |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
320 |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
321 if (data->content_disposition_params == NULL) |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
322 str_append(str, "NIL"); |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
323 else { |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
324 str_append_c(str, '('); |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
325 str_append(str, data->content_disposition_params); |
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 } |
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_c(str, ')'); |
0 | 329 } |
330 | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
331 str_append_c(str, ' '); |
0 | 332 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
|
333 str_append(str, "NIL"); |
0 | 334 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
|
335 str_append_c(str, '('); |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
336 str_append(str, data->content_language); |
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 } | |
340 | |
5334
8d9234a26a3f
Make imap_bodystructure_write() parameter constant. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
341 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
|
342 string_t *str, bool extended) |
0 | 343 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
344 struct message_part_body_data *data = part->context; |
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
|
345 bool text; |
0 | 346 |
347 if (data == NULL) { | |
348 /* there was no content headers, use an empty structure */ | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
349 data = t_new(struct message_part_body_data, 1); |
0 | 350 } |
351 | |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
352 if (part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) { |
1665
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
353 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
|
354 text = FALSE; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
355 } else { |
1665
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
356 /* "content type" "subtype" */ |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
357 text = data->content_type == NULL || |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
358 strcasecmp(data->content_type, "\"text\"") == 0; |
1665
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
359 str_append(str, NVL(data->content_type, "\"text\"")); |
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
360 str_append_c(str, ' '); |
1255
58041ce0a24c
Default to 7bit instead of 8bit content-encoding-type.
Timo Sirainen <tss@iki.fi>
parents:
1107
diff
changeset
|
361 |
1665
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
362 if (data->content_subtype != NULL) |
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
363 str_append(str, data->content_subtype); |
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
364 else { |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
365 if (text) |
1665
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
366 str_append(str, "\"plain\""); |
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
367 else |
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
368 str_append(str, "\"unknown\""); |
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
369 |
e50e21588020
Some message/rfc822 mails were returned as text/plain
Timo Sirainen <tss@iki.fi>
parents:
1664
diff
changeset
|
370 } |
1255
58041ce0a24c
Default to 7bit instead of 8bit content-encoding-type.
Timo Sirainen <tss@iki.fi>
parents:
1107
diff
changeset
|
371 } |
0 | 372 |
373 /* ("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
|
374 str_append_c(str, ' '); |
1537
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
375 if (data->content_type_params == NULL) { |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
376 if (!text) |
1537
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
377 str_append(str, "NIL"); |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
378 else |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
379 str_append(str, "("DEFAULT_CHARSET")"); |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
380 } 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
|
381 str_append_c(str, '('); |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
382 str_append(str, data->content_type_params); |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
383 str_append_c(str, ')'); |
0 | 384 } |
385 | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
386 str_printfa(str, " %s %s %s %"PRIuUOFF_T, |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
387 NVL(data->content_id, "NIL"), |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
388 NVL(data->content_description, "NIL"), |
1255
58041ce0a24c
Default to 7bit instead of 8bit content-encoding-type.
Timo Sirainen <tss@iki.fi>
parents:
1107
diff
changeset
|
389 NVL(data->content_transfer_encoding, "\"7bit\""), |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
390 part->body_size.virtual_size); |
0 | 391 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
392 if (text) { |
0 | 393 /* 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
|
394 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
|
395 } else if (part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) { |
0 | 396 /* message/rfc822 contains envelope + body + line count */ |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
397 struct message_part_body_data *child_data; |
1663
4aca99baa9a4
Don't write envelope as NIL into bodystructure even if it's broken.
Timo Sirainen <tss@iki.fi>
parents:
1661
diff
changeset
|
398 struct message_part_envelope_data *env_data; |
0 | 399 |
400 i_assert(part->children != NULL); | |
401 i_assert(part->children->next == NULL); | |
402 | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
403 child_data = part->children->context; |
1663
4aca99baa9a4
Don't write envelope as NIL into bodystructure even if it's broken.
Timo Sirainen <tss@iki.fi>
parents:
1661
diff
changeset
|
404 env_data = child_data != NULL ? child_data->envelope : NULL; |
0 | 405 |
1664 | 406 str_append(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
|
407 imap_envelope_write_part_data(env_data, str); |
4aca99baa9a4
Don't write envelope as NIL into bodystructure even if it's broken.
Timo Sirainen <tss@iki.fi>
parents:
1661
diff
changeset
|
408 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
|
409 |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
410 imap_bodystructure_write(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
|
411 str_printfa(str, " %u", part->body_size.lines); |
0 | 412 } |
413 | |
414 if (!extended) | |
415 return; | |
416 | |
417 /* BODYSTRUCTURE data */ | |
418 | |
419 /* "md5" ("content disposition" ("disposition" "params")) | |
420 ("body" "language" "params") */ | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
421 str_append_c(str, ' '); |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
422 str_append(str, NVL(data->content_md5, "NIL")); |
0 | 423 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
424 str_append_c(str, ' '); |
0 | 425 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
|
426 str_append(str, "NIL"); |
0 | 427 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
|
428 str_append_c(str, '('); |
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(str, data->content_disposition); |
862
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
430 str_append_c(str, ' '); |
0 | 431 |
862
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
432 if (data->content_disposition_params == NULL) |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
433 str_append(str, "NIL"); |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
434 else { |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
435 str_append_c(str, '('); |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
436 str_append(str, data->content_disposition_params); |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
437 str_append_c(str, ')'); |
0 | 438 } |
862
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
439 |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
440 str_append_c(str, ')'); |
0 | 441 } |
442 | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
443 str_append_c(str, ' '); |
0 | 444 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
|
445 str_append(str, "NIL"); |
0 | 446 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
|
447 str_append_c(str, '('); |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
448 str_append(str, data->content_language); |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
449 str_append_c(str, ')'); |
0 | 450 } |
451 } | |
452 | |
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
|
453 bool imap_bodystructure_is_plain_7bit(struct message_part *part) |
3460
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
454 { |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
455 struct message_part_body_data *data = part->context; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
456 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
457 i_assert(part->parent == NULL); |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
458 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
459 if (data == NULL) { |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
460 /* no bodystructure headers found */ |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
461 return TRUE; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
462 } |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
463 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
464 /* 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
|
465 multipart stuff */ |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
466 if ((part->flags & MESSAGE_PART_FLAG_TEXT) == 0) |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
467 return FALSE; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
468 if (part->next != NULL || part->children != NULL) |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
469 return FALSE; /* shouldn't happen normally.. */ |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
470 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
471 /* must be text/plain */ |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
472 if (data->content_subtype != NULL && |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
473 strcasecmp(data->content_subtype, "\"plain\"") != 0) |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
474 return FALSE; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
475 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
476 /* only allowed parameter is charset=us-ascii, which is also default */ |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
477 if (data->content_type_params != NULL && |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
478 strcasecmp(data->content_type_params, DEFAULT_CHARSET) != 0) |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
479 return FALSE; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
480 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
481 if (data->content_id != NULL || |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
482 data->content_description != NULL) |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
483 return FALSE; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
484 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
485 if (data->content_transfer_encoding != NULL && |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
486 strcasecmp(data->content_transfer_encoding, "\"7bit\"") != 0) |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
487 return FALSE; |
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 /* BODYSTRUCTURE checks: */ |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
490 if (data->content_md5 != NULL || |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
491 data->content_disposition != NULL || |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
492 data->content_language != NULL) |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
493 return FALSE; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
494 |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
495 return TRUE; |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
496 } |
e8cbf3ae00db
Added imap_bodystructure_is_plain_7bit()
Timo Sirainen <tss@iki.fi>
parents:
3407
diff
changeset
|
497 |
5334
8d9234a26a3f
Make imap_bodystructure_write() parameter constant. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
498 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
|
499 string_t *dest, bool extended) |
0 | 500 { |
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
|
501 i_assert(part->parent != NULL || part->next == NULL); |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
502 |
0 | 503 while (part != NULL) { |
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
|
504 if (part->parent != NULL) |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
505 str_append_c(dest, '('); |
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
|
506 |
106
5fe3e04ca8d9
Added support for caching of MessagePart data. This is useful for fetching
Timo Sirainen <tss@iki.fi>
parents:
105
diff
changeset
|
507 if (part->flags & MESSAGE_PART_FLAG_MULTIPART) |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
508 part_write_body_multipart(part, dest, extended); |
0 | 509 else |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
510 part_write_body(part, dest, extended); |
0 | 511 |
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
|
512 if (part->parent != NULL) |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
513 str_append_c(dest, ')'); |
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
|
514 |
0 | 515 part = part->next; |
516 } | |
517 } | |
518 | |
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 static bool str_append_imap_arg(string_t *str, const struct imap_arg *arg) |
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
|
520 { |
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
|
521 switch (arg->type) { |
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
|
522 case IMAP_ARG_NIL: |
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
|
523 str_append(str, "NIL"); |
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
|
524 break; |
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
|
525 case IMAP_ARG_ATOM: |
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
|
526 str_append(str, IMAP_ARG_STR(arg)); |
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
|
527 break; |
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
|
528 case IMAP_ARG_STRING: |
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
|
529 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
|
530 str_append(str, IMAP_ARG_STR(arg)); |
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
|
531 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
|
532 break; |
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
|
533 case IMAP_ARG_LITERAL: { |
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
|
534 const char *argstr = IMAP_ARG_STR(arg); |
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
|
535 |
4280
92bf418b8a60
BODYSTRUCTURE -> BODY translation was missing CRLF after literal.
Timo Sirainen <tss@iki.fi>
parents:
4070
diff
changeset
|
536 str_printfa(str, "{%"PRIuSIZE_T"}\r\n", strlen(argstr)); |
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
|
537 str_append(str, argstr); |
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
|
538 break; |
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
|
539 } |
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
|
540 default: |
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
|
541 return FALSE; |
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
|
542 } |
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
|
543 |
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
|
544 return TRUE; |
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
|
545 } |
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
|
546 |
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
|
547 static bool imap_write_list(const struct imap_arg *args, string_t *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
|
548 { |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
549 /* don't do any typechecking, just write it out */ |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
550 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
|
551 while (args->type != IMAP_ARG_EOL) { |
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
|
552 if (!str_append_imap_arg(str, args)) { |
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
|
553 if (args->type != IMAP_ARG_LIST) |
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
|
554 return FALSE; |
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
|
555 |
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
|
556 if (!imap_write_list(IMAP_ARG_LIST_ARGS(args), 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
|
557 return 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
|
558 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
559 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
|
560 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
561 if (args->type != IMAP_ARG_EOL) |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
562 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
|
563 } |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
564 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
|
565 return 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
|
566 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
567 |
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
|
568 static bool imap_parse_bodystructure_args(const struct imap_arg *args, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3571
diff
changeset
|
569 string_t *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
|
570 { |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5334
diff
changeset
|
571 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
|
572 const struct imap_arg *list_args; |
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
|
573 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
|
574 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
|
575 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
576 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
|
577 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
|
578 str_append_c(str, '('); |
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
|
579 list_args = IMAP_ARG_LIST_ARGS(args); |
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
580 if (!imap_parse_bodystructure_args(list_args, 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
|
581 return FALSE; |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
582 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
|
583 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
584 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
|
585 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
|
586 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
587 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
588 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
|
589 /* 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
|
590 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
|
591 return str_append_imap_arg(str, args); |
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
|
592 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
593 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
594 /* "content type" "subtype" */ |
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
|
595 if (args[0].type == IMAP_ARG_NIL || args[1].type == IMAP_ARG_NIL) |
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
|
596 return FALSE; |
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
|
597 |
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
|
598 if (!str_append_imap_arg(str, &args[0])) |
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
|
599 return FALSE; |
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
|
600 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
|
601 if (!str_append_imap_arg(str, &args[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
|
602 return 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
|
603 |
3571 | 604 text = strcasecmp(IMAP_ARG_STR_NONULL(&args[0]), "text") == 0; |
605 message_rfc822 = | |
606 strcasecmp(IMAP_ARG_STR_NONULL(&args[0]), "message") == 0 && | |
607 strcasecmp(IMAP_ARG_STR_NONULL(&args[1]), "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
|
608 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
609 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
|
610 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
611 /* ("content type param key" "value" ...) | NIL */ |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
612 if (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
|
613 str_append(str, " ("); |
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
|
614 subargs = IMAP_ARG_LIST_ARGS(args); |
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
|
615 for (; subargs->type != IMAP_ARG_EOL; ) { |
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
|
616 if (!str_append_imap_arg(str, &subargs[0])) |
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
|
617 return FALSE; |
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
|
618 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
|
619 if (!str_append_imap_arg(str, &subargs[1])) |
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
|
620 return FALSE; |
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
|
621 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
622 subargs += 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
|
623 if (subargs->type == IMAP_ARG_EOL) |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
624 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
|
625 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
|
626 } |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
627 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
|
628 } 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
|
629 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
|
630 } else { |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
631 return 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
|
632 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
633 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
|
634 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
635 /* "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
|
636 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
|
637 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
|
638 |
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
|
639 if (!str_append_imap_arg(str, args)) |
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
|
640 return 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
|
641 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
642 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
643 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
|
644 /* text/xxx - text lines */ |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
645 if (args->type != IMAP_ARG_ATOM) |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
646 return 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
|
647 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
648 str_append_c(str, ' '); |
877
7935347f54f1
Don't access ImapArg's union members directly - too easy to mess up. Fixes a
Timo Sirainen <tss@iki.fi>
parents:
862
diff
changeset
|
649 str_append(str, IMAP_ARG_STR(args)); |
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
|
650 } 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
|
651 /* message/rfc822 - envelope + bodystructure + text lines */ |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
652 if (args[0].type != IMAP_ARG_LIST || |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
653 args[1].type != IMAP_ARG_LIST || |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
654 args[2].type != IMAP_ARG_ATOM) |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
655 return 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
|
656 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
657 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
|
658 |
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
|
659 list_args = IMAP_ARG_LIST_ARGS(&args[0]); |
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
660 if (!imap_write_list(list_args, 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
|
661 return 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
|
662 |
4027
0e7a9b0aa8c3
BODYSTRUCTURE -> BODY conversion was broken with mails containing
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
663 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
|
664 |
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
|
665 list_args = IMAP_ARG_LIST_ARGS(&args[1]); |
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
666 if (!imap_parse_bodystructure_args(list_args, 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
|
667 return 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
|
668 |
4027
0e7a9b0aa8c3
BODYSTRUCTURE -> BODY conversion was broken with mails containing
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
669 str_append(str, ") "); |
877
7935347f54f1
Don't access ImapArg's union members directly - too easy to mess up. Fixes a
Timo Sirainen <tss@iki.fi>
parents:
862
diff
changeset
|
670 str_append(str, IMAP_ARG_STR(&args[2])); |
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
|
671 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
672 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
673 return 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
|
674 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
675 |
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
|
676 bool imap_body_parse_from_bodystructure(const char *bodystructure, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3571
diff
changeset
|
677 string_t *dest) |
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
|
678 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
679 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
|
680 struct imap_parser *parser; |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5334
diff
changeset
|
681 const struct imap_arg *args; |
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
|
682 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
|
683 |
6142
6c0bfc35af03
Removed memory pool parameter from iostreams. Default pool was almost always
Timo Sirainen <tss@iki.fi>
parents:
6117
diff
changeset
|
684 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
|
685 (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
|
686 |
1591
6eca99b727a0
IMAP parser memory limits are now enforced by bytes per line rather than
Timo Sirainen <tss@iki.fi>
parents:
1568
diff
changeset
|
687 parser = imap_parser_create(input, NULL, (size_t)-1); |
1661
566fb4bf7066
Fixes for parsing BODYSTRUCTURE
Timo Sirainen <tss@iki.fi>
parents:
1619
diff
changeset
|
688 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
|
689 IMAP_PARSE_FLAG_LITERAL_TYPE, &args); |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
690 ret = ret > 0 && imap_parse_bodystructure_args(args, dest); |
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
|
691 |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
692 if (!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
|
693 i_error("Error parsing IMAP bodystructure: %s", bodystructure); |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
694 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
695 imap_parser_destroy(&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
|
696 i_stream_destroy(&input); |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
697 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
|
698 } |