Mercurial > dovecot > core-2.2
annotate src/lib-imap/imap-bodystructure.c @ 1537:d4563a5ba30b HEAD
Add charset/us-ascii into body/bodystructure replies if no charset is given
for text/* body parts.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 04 Jun 2003 19:13:23 +0300 |
parents | 36ba64c5dbb2 |
children | 235f67c3cc9f |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2002 Timo Sirainen */ |
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" |
8 #include "message-content-parser.h" | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
9 #include "message-tokenize.h" |
445
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
10 #include "imap-parser.h" |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
11 #include "imap-quote.h" |
0 | 12 #include "imap-envelope.h" |
13 #include "imap-bodystructure.h" | |
14 | |
1537
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
15 #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
|
16 "\"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
|
17 |
0 | 18 #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
|
19 "(\"text\" \"plain\" ("DEFAULT_CHARSET") NIL NIL \"7bit\" 0 0)" |
0 | 20 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
21 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
|
22 pool_t pool; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
23 string_t *str; |
0 | 24 char *content_type, *content_subtype; |
25 char *content_type_params; | |
26 char *content_transfer_encoding; | |
27 char *content_id; | |
28 char *content_description; | |
29 char *content_disposition; | |
30 char *content_disposition_params; | |
31 char *content_md5; | |
32 char *content_language; | |
33 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
34 struct message_part_envelope_data *envelope; |
1537
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
35 |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
36 unsigned int charset_found:1; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
37 }; |
0 | 38 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
39 static void part_write_bodystructure(struct message_part *part, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
40 string_t *str, int extended); |
0 | 41 |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
42 static void parse_content_type(const unsigned char *value, size_t value_len, |
896
21ffcce83c70
Rewrote rfc822-tokenize.c to work one token at a time so it won't uselessly
Timo Sirainen <tss@iki.fi>
parents:
877
diff
changeset
|
43 void *context) |
0 | 44 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
45 struct message_part_body_data *data = context; |
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
|
46 size_t i; |
0 | 47 |
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
|
48 for (i = 0; i < value_len; i++) { |
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
|
49 if (value[i] == '/') |
0 | 50 break; |
51 } | |
52 | |
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
|
53 if (i == value_len) |
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
|
54 data->content_type = imap_quote(data->pool, value, value_len); |
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
|
55 else { |
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
|
56 data->content_type = imap_quote(data->pool, value, i); |
0 | 57 |
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
|
58 i++; |
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
|
59 data->content_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
|
60 imap_quote(data->pool, value+i, value_len-i); |
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
|
61 } |
0 | 62 } |
63 | |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
64 static void parse_save_params_list(const unsigned char *name, size_t name_len, |
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
65 const unsigned char *value, size_t value_len, |
896
21ffcce83c70
Rewrote rfc822-tokenize.c to work one token at a time so it won't uselessly
Timo Sirainen <tss@iki.fi>
parents:
877
diff
changeset
|
66 int value_quoted __attr_unused__, |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
67 void *context) |
0 | 68 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
69 struct message_part_body_data *data = context; |
0 | 70 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
71 if (str_len(data->str) != 0) |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
72 str_append_c(data->str, ' '); |
0 | 73 |
1537
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
74 if (name_len == 7 && memcasecmp(name, "charset", 7) == 0) |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
75 data->charset_found = TRUE; |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
76 |
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
|
77 imap_quote_append(data->str, name, name_len); |
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
|
78 str_append_c(data->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
|
79 imap_quote_append(data->str, value, value_len); |
0 | 80 } |
81 | |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
82 static void parse_content_transfer_encoding(const unsigned char *value, |
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
83 size_t value_len, void *context) |
0 | 84 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
85 struct message_part_body_data *data = context; |
0 | 86 |
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
|
87 data->content_transfer_encoding = |
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
|
88 imap_quote(data->pool, value, value_len); |
0 | 89 } |
90 | |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
91 static void parse_content_disposition(const unsigned char *value, |
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
92 size_t value_len, void *context) |
0 | 93 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
94 struct message_part_body_data *data = context; |
0 | 95 |
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
|
96 data->content_disposition = imap_quote(data->pool, value, value_len); |
0 | 97 } |
98 | |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
99 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
|
100 struct message_part_body_data *data) |
0 | 101 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
102 struct message_tokenizer *tok; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
103 enum message_token token; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
104 string_t *str; |
398
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
105 int quoted; |
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
106 |
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
107 /* Content-Language: en-US, az-arabic (comments allowed) */ |
0 | 108 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
109 tok = message_tokenize_init(value, value_len, NULL, NULL); |
0 | 110 |
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
|
111 t_push(); |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
112 str = t_str_new(256); |
0 | 113 |
398
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
114 quoted = FALSE; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
115 while ((token = message_tokenize_next(tok)) != TOKEN_LAST) { |
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
|
116 if (token == ',') { |
398
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
117 /* list separator */ |
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
118 if (quoted) { |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
119 str_append_c(str, '"'); |
398
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
120 quoted = FALSE; |
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
121 } |
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
|
122 } else { |
398
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
123 /* anything else goes as-is. only alphabetic characters |
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
124 and '-' is allowed, so anything else is error |
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
125 which we can deal with however we want. */ |
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
126 if (!quoted) { |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
127 if (str_len(str) > 0) |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
128 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
|
129 str_append_c(str, '"'); |
398
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
130 quoted = TRUE; |
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
131 } |
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
132 |
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
|
133 if (!IS_TOKEN_STRING(token)) |
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
|
134 str_append_c(str, token); |
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
|
135 else { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
136 value = message_tokenize_get_value(tok, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
137 &value_len); |
896
21ffcce83c70
Rewrote rfc822-tokenize.c to work one token at a time so it won't uselessly
Timo Sirainen <tss@iki.fi>
parents:
877
diff
changeset
|
138 str_append_n(str, value, value_len); |
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
|
139 } |
398
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
140 } |
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
141 } |
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
142 |
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
143 if (quoted) |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
144 str_append_c(str, '"'); |
398
e807d88e653c
Parse Content-Language correctly for BODYSTRUCTURE.
Timo Sirainen <tss@iki.fi>
parents:
342
diff
changeset
|
145 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
146 data->content_language = p_strdup(data->pool, str_c(str)); |
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
|
147 |
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
|
148 t_pop(); |
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
|
149 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
150 message_tokenize_deinit(tok); |
0 | 151 } |
152 | |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
153 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
|
154 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
|
155 pool_t pool) |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
156 { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
157 const char *name = hdr->name; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
158 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
|
159 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
|
160 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
161 if (strncasecmp(name, "Content-", 8) != 0) |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
162 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
163 name += 8; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
164 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
165 if (hdr->continues) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
166 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
|
167 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
168 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
169 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
170 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
|
171 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
|
172 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
173 switch (*name) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
174 case 'i': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
175 case 'I': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
176 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
|
177 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
|
178 break; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
179 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
180 case 'm': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
181 case 'M': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
182 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
|
183 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
|
184 break; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
185 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
186 case 't': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
187 case 'T': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
188 if (strcasecmp(name, "Type") == 0 && d->content_type == NULL) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
189 d->str = t_str_new(256); |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
190 message_content_parse_header(value, value_len, |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
191 parse_content_type, |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
192 parse_save_params_list, d); |
1537
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
193 if (!d->charset_found && |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
194 strncasecmp(d->content_type, "\"text\"", 6) == 0) { |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
195 /* set a 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
|
196 if (str_len(d->str) != 0) |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
197 str_append_c(d->str, ' '); |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
198 str_append(d->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
|
199 } |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
200 d->content_type_params = |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
201 p_strdup_empty(pool, str_c(d->str)); |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
202 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
203 if (strcasecmp(name, "Transfer-Encoding") == 0 && |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
204 d->content_transfer_encoding == NULL) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
205 message_content_parse_header(value, value_len, |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
206 parse_content_transfer_encoding, |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
207 NULL, d); |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
208 } |
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 'l': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
212 case 'L': |
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, "Language") == 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_language == NULL) |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
215 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
|
216 break; |
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 case 'd': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
219 case 'D': |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
220 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
|
221 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
|
222 d->content_description = |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
223 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
|
224 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
225 if (strcasecmp(name, "Disposition") == 0 && |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
226 d->content_disposition_params == NULL) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
227 d->str = t_str_new(256); |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
228 message_content_parse_header(value, value_len, |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
229 parse_content_disposition, |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
230 parse_save_params_list, d); |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
231 d->content_disposition_params = |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
232 p_strdup_empty(pool, str_c(d->str)); |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
233 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
234 break; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
235 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
236 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
237 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
238 static void parse_header(struct message_part *part, |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
239 struct message_header_line *hdr, void *context) |
0 | 240 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
241 pool_t pool = context; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
242 struct message_part_body_data *part_data; |
0 | 243 int parent_rfc822; |
244 | |
1327 | 245 if (hdr == NULL || hdr->eoh) |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
246 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
247 |
106
5fe3e04ca8d9
Added support for caching of MessagePart data. This is useful for fetching
Timo Sirainen <tss@iki.fi>
parents:
105
diff
changeset
|
248 parent_rfc822 = part->parent != NULL && |
5fe3e04ca8d9
Added support for caching of MessagePart data. This is useful for fetching
Timo Sirainen <tss@iki.fi>
parents:
105
diff
changeset
|
249 (part->parent->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822); |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
250 if (!parent_rfc822 && strncasecmp(hdr->name, "Content-", 8) != 0) |
0 | 251 return; |
252 | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
253 if (part->context == NULL) { |
0 | 254 /* initialize message part data */ |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
255 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
|
256 p_new(pool, struct message_part_body_data, 1); |
0 | 257 part_data->pool = pool; |
258 } | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
259 part_data = part->context; |
0 | 260 |
261 t_push(); | |
262 | |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1257
diff
changeset
|
263 parse_content_header(part_data, hdr, pool); |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
264 |
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
897
diff
changeset
|
265 if (parent_rfc822) { |
0 | 266 /* 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
|
267 imap_envelope_parse_header(pool, &part_data->envelope, hdr); |
0 | 268 } |
269 t_pop(); | |
270 } | |
271 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
272 static void part_parse_headers(struct message_part *part, 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
|
273 uoff_t start_offset, pool_t pool) |
0 | 274 { |
275 while (part != NULL) { | |
276 /* note that we want to parse the header of all | |
277 the message parts, multiparts too. */ | |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
647
diff
changeset
|
278 i_assert(part->physical_pos >= input->v_offset - start_offset); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
647
diff
changeset
|
279 i_stream_skip(input, part->physical_pos - |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
647
diff
changeset
|
280 (input->v_offset - start_offset)); |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
281 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
647
diff
changeset
|
282 message_parse_header(part, input, NULL, parse_header, pool); |
307
5954f9c2e620
BODY / BODYSTRUCTURE generator didn't like if message didn't start from zero
Timo Sirainen <tss@iki.fi>
parents:
193
diff
changeset
|
283 if (part->children != NULL) { |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
647
diff
changeset
|
284 part_parse_headers(part->children, input, |
307
5954f9c2e620
BODY / BODYSTRUCTURE generator didn't like if message didn't start from zero
Timo Sirainen <tss@iki.fi>
parents:
193
diff
changeset
|
285 start_offset, pool); |
5954f9c2e620
BODY / BODYSTRUCTURE generator didn't like if message didn't start from zero
Timo Sirainen <tss@iki.fi>
parents:
193
diff
changeset
|
286 } |
0 | 287 |
288 part = part->next; | |
289 } | |
290 } | |
291 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
292 static void part_write_body_multipart(struct message_part *part, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
293 string_t *str, int extended) |
0 | 294 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
295 struct message_part_body_data *data = part->context; |
0 | 296 |
647
1acbf6c8758c
handle broken multipart messages without crashing
Timo Sirainen <tss@iki.fi>
parents:
593
diff
changeset
|
297 if (data == NULL) { |
1acbf6c8758c
handle broken multipart messages without crashing
Timo Sirainen <tss@iki.fi>
parents:
593
diff
changeset
|
298 /* 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
|
299 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
|
300 } |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
398
diff
changeset
|
301 |
0 | 302 if (part->children != NULL) |
303 part_write_bodystructure(part->children, str, extended); | |
304 else { | |
305 /* no parts in multipart message, | |
306 that's not allowed. write a single | |
307 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
|
308 str_append(str, EMPTY_BODYSTRUCTURE); |
0 | 309 } |
310 | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
311 str_append_c(str, ' '); |
647
1acbf6c8758c
handle broken multipart messages without crashing
Timo Sirainen <tss@iki.fi>
parents:
593
diff
changeset
|
312 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
|
313 str_append(str, data->content_subtype); |
647
1acbf6c8758c
handle broken multipart messages without crashing
Timo Sirainen <tss@iki.fi>
parents:
593
diff
changeset
|
314 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
|
315 str_append(str, "\"x-unknown\""); |
0 | 316 |
317 if (!extended) | |
318 return; | |
319 | |
320 /* 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
|
321 str_append_c(str, ' '); |
0 | 322 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
|
323 str_append(str, "NIL"); |
0 | 324 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
|
325 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
|
326 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
|
327 str_append_c(str, ')'); |
0 | 328 } |
329 | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
330 str_append_c(str, ' '); |
0 | 331 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
|
332 str_append(str, "NIL"); |
0 | 333 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
|
334 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
|
335 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
|
336 str_append_c(str, ' '); |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
337 |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
338 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
|
339 str_append(str, "NIL"); |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
340 else { |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
341 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
|
342 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
|
343 str_append_c(str, ')'); |
0 | 344 } |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
345 str_append_c(str, ')'); |
0 | 346 } |
347 | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
348 str_append_c(str, ' '); |
0 | 349 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
|
350 str_append(str, "NIL"); |
0 | 351 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
|
352 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
|
353 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
|
354 str_append_c(str, ')'); |
0 | 355 } |
356 } | |
357 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
358 static void part_write_body(struct message_part *part, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
359 string_t *str, int extended) |
0 | 360 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
361 struct message_part_body_data *data = part->context; |
0 | 362 |
363 if (data == NULL) { | |
364 /* 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
|
365 data = t_new(struct message_part_body_data, 1); |
0 | 366 } |
367 | |
368 /* "content type" "subtype" */ | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
369 str_append(str, NVL(data->content_type, "\"text\"")); |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
370 str_append_c(str, ' '); |
1255
58041ce0a24c
Default to 7bit instead of 8bit content-encoding-type.
Timo Sirainen <tss@iki.fi>
parents:
1107
diff
changeset
|
371 if (data->content_subtype != NULL) |
58041ce0a24c
Default to 7bit instead of 8bit content-encoding-type.
Timo Sirainen <tss@iki.fi>
parents:
1107
diff
changeset
|
372 str_append(str, data->content_subtype); |
58041ce0a24c
Default to 7bit instead of 8bit content-encoding-type.
Timo Sirainen <tss@iki.fi>
parents:
1107
diff
changeset
|
373 else { |
58041ce0a24c
Default to 7bit instead of 8bit content-encoding-type.
Timo Sirainen <tss@iki.fi>
parents:
1107
diff
changeset
|
374 if (data->content_type == NULL || |
1257
cee5e11b08f3
final fix: text-content subtype wasn't defaulted to plain
Timo Sirainen <tss@iki.fi>
parents:
1255
diff
changeset
|
375 strcasecmp(data->content_type, "\"text\"") == 0) |
1255
58041ce0a24c
Default to 7bit instead of 8bit content-encoding-type.
Timo Sirainen <tss@iki.fi>
parents:
1107
diff
changeset
|
376 str_append(str, "\"plain\""); |
58041ce0a24c
Default to 7bit instead of 8bit content-encoding-type.
Timo Sirainen <tss@iki.fi>
parents:
1107
diff
changeset
|
377 else |
58041ce0a24c
Default to 7bit instead of 8bit content-encoding-type.
Timo Sirainen <tss@iki.fi>
parents:
1107
diff
changeset
|
378 str_append(str, "\"unknown\""); |
58041ce0a24c
Default to 7bit instead of 8bit content-encoding-type.
Timo Sirainen <tss@iki.fi>
parents:
1107
diff
changeset
|
379 |
58041ce0a24c
Default to 7bit instead of 8bit content-encoding-type.
Timo Sirainen <tss@iki.fi>
parents:
1107
diff
changeset
|
380 } |
0 | 381 |
382 /* ("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
|
383 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
|
384 if (data->content_type_params == NULL) { |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
385 if (data->content_type != NULL && |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
386 strncasecmp(data->content_type, "\"text\"", 6) != 0) |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
387 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
|
388 else |
d4563a5ba30b
Add charset/us-ascii into body/bodystructure replies if no charset is given
Timo Sirainen <tss@iki.fi>
parents:
1327
diff
changeset
|
389 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
|
390 } 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
|
391 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
|
392 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
|
393 str_append_c(str, ')'); |
0 | 394 } |
395 | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
396 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
|
397 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
|
398 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
|
399 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
|
400 part->body_size.virtual_size); |
0 | 401 |
106
5fe3e04ca8d9
Added support for caching of MessagePart data. This is useful for fetching
Timo Sirainen <tss@iki.fi>
parents:
105
diff
changeset
|
402 if (part->flags & MESSAGE_PART_FLAG_TEXT) { |
0 | 403 /* 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
|
404 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
|
405 } else if (part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) { |
0 | 406 /* 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
|
407 struct message_part_body_data *child_data; |
0 | 408 |
409 i_assert(part->children != NULL); | |
410 i_assert(part->children->next == NULL); | |
411 | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
412 child_data = part->children->context; |
0 | 413 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
414 str_append_c(str, ' '); |
0 | 415 if (child_data != NULL && child_data->envelope != 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
|
416 str_append_c(str, '('); |
0 | 417 imap_envelope_write_part_data(child_data->envelope, |
418 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
|
419 str_append_c(str, ')'); |
0 | 420 } else { |
421 /* buggy message */ | |
833
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, "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 part_write_bodystructure(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
|
426 str_printfa(str, " %u", part->body_size.lines); |
0 | 427 } |
428 | |
429 if (!extended) | |
430 return; | |
431 | |
432 /* BODYSTRUCTURE data */ | |
433 | |
434 /* "md5" ("content disposition" ("disposition" "params")) | |
435 ("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
|
436 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
|
437 str_append(str, NVL(data->content_md5, "NIL")); |
0 | 438 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
439 str_append_c(str, ' '); |
0 | 440 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
|
441 str_append(str, "NIL"); |
0 | 442 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
|
443 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
|
444 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
|
445 str_append_c(str, ' '); |
0 | 446 |
862
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
447 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
|
448 str_append(str, "NIL"); |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
449 else { |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
450 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
|
451 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
|
452 str_append_c(str, ')'); |
0 | 453 } |
862
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
454 |
375923d2f910
BODYSTRUCTURE reply was incorrect. pine didn't like it.
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
455 str_append_c(str, ')'); |
0 | 456 } |
457 | |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
458 str_append_c(str, ' '); |
0 | 459 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
|
460 str_append(str, "NIL"); |
0 | 461 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
|
462 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
|
463 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
|
464 str_append_c(str, ')'); |
0 | 465 } |
466 } | |
467 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
468 static void part_write_bodystructure(struct message_part *part, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
469 string_t *str, int extended) |
0 | 470 { |
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
|
471 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
|
472 |
0 | 473 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
|
474 if (part->parent != 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
|
475 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
|
476 |
106
5fe3e04ca8d9
Added support for caching of MessagePart data. This is useful for fetching
Timo Sirainen <tss@iki.fi>
parents:
105
diff
changeset
|
477 if (part->flags & MESSAGE_PART_FLAG_MULTIPART) |
0 | 478 part_write_body_multipart(part, str, extended); |
479 else | |
480 part_write_body(part, str, extended); | |
481 | |
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
|
482 if (part->parent != 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
|
483 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
|
484 |
0 | 485 part = part->next; |
486 } | |
487 } | |
488 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
489 const char *imap_part_get_bodystructure(pool_t pool, struct message_part **part, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
490 struct istream *input, int extended) |
0 | 491 { |
913 | 492 string_t *str; |
307
5954f9c2e620
BODY / BODYSTRUCTURE generator didn't like if message didn't start from zero
Timo Sirainen <tss@iki.fi>
parents:
193
diff
changeset
|
493 uoff_t start_offset; |
5954f9c2e620
BODY / BODYSTRUCTURE generator didn't like if message didn't start from zero
Timo Sirainen <tss@iki.fi>
parents:
193
diff
changeset
|
494 |
0 | 495 if (*part == NULL) |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
647
diff
changeset
|
496 *part = message_parse(pool, input, parse_header, pool); |
307
5954f9c2e620
BODY / BODYSTRUCTURE generator didn't like if message didn't start from zero
Timo Sirainen <tss@iki.fi>
parents:
193
diff
changeset
|
497 else { |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
647
diff
changeset
|
498 start_offset = input->v_offset; |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
647
diff
changeset
|
499 part_parse_headers(*part, input, start_offset, pool); |
307
5954f9c2e620
BODY / BODYSTRUCTURE generator didn't like if message didn't start from zero
Timo Sirainen <tss@iki.fi>
parents:
193
diff
changeset
|
500 } |
0 | 501 |
913 | 502 str = t_str_new(2048); |
503 part_write_bodystructure(*part, str, extended); | |
504 return str_c(str); | |
0 | 505 } |
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 |
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
|
507 static int str_append_imap_arg(string_t *str, const struct imap_arg *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
|
508 { |
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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 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
|
518 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
|
519 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
|
520 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
|
521 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
|
522 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
|
523 |
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 str_printfa(str, "{%"PRIuSIZE_T"}", strlen(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
|
525 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
|
526 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
|
527 } |
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 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
|
529 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
|
530 } |
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 |
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 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
|
533 } |
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 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
535 static int 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
|
536 { |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
537 /* 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
|
538 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
|
539 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
|
540 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
|
541 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
|
542 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
|
543 |
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
|
544 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
|
545 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
|
546 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
547 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
|
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 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
|
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 } |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
552 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
|
553 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
|
554 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
555 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
556 static int imap_parse_bodystructure_args(const struct imap_arg *args, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
557 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
|
558 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
559 struct imap_arg *subargs; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
560 struct imap_arg_list *list; |
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
|
561 int i, multipart, text, 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
|
562 |
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 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
|
564 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
|
565 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
|
566 list = IMAP_ARG_LIST(args); |
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
|
567 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
|
568 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
|
569 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
|
570 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
571 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
|
572 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
|
573 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
574 |
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 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
|
576 /* 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
|
577 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
|
578 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
|
579 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
580 |
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 /* "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
|
582 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
|
583 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
|
584 |
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
|
585 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
|
586 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
|
587 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
|
588 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
|
589 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
|
590 |
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
|
591 text = strcasecmp(IMAP_ARG_STR(&args[0]), "text") == 0; |
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
|
592 message_rfc822 = strcasecmp(IMAP_ARG_STR(&args[0]), "message") == 0 && |
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
|
593 strcasecmp(IMAP_ARG_STR(&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
|
594 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
595 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
|
596 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
597 /* ("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
|
598 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
|
599 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
|
600 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
|
601 for (; 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
|
602 if (subargs[0].type != IMAP_ARG_STRING || |
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 subargs[1].type != IMAP_ARG_STRING) |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
604 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
|
605 |
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
|
606 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
|
607 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
|
608 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
|
609 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
|
610 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
|
611 |
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 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
|
613 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
|
614 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
|
615 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
|
616 } |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
617 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
|
618 } 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
|
619 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
|
620 } 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
|
621 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
|
622 } |
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 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
|
624 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
625 /* "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
|
626 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
|
627 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
|
628 |
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
|
629 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
|
630 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
|
631 } |
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 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
|
634 /* 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
|
635 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
|
636 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
|
637 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
638 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
|
639 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
|
640 } 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
|
641 /* 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
|
642 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
|
643 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
|
644 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
|
645 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
|
646 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
647 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
|
648 |
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 list = IMAP_ARG_LIST(&args[0]); |
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
|
650 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
|
651 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
|
652 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
653 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
|
654 |
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
|
655 list = IMAP_ARG_LIST(&args[1]); |
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
|
656 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
|
657 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
|
658 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
659 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
|
660 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
|
661 } |
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 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
663 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
|
664 } |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
665 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
666 const char *imap_body_parse_from_bodystructure(const char *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
|
667 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
668 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
|
669 struct imap_parser *parser; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
670 struct imap_arg *args; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
671 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
|
672 const char *value; |
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 size_t len; |
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 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
|
675 |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
676 len = strlen(bodystructure); |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
768
diff
changeset
|
677 str = t_str_new(len); |
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 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
647
diff
changeset
|
679 input = i_stream_create_from_data(data_stack_pool, bodystructure, len); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
647
diff
changeset
|
680 (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
|
681 |
768
8b3518bb327e
Limited max. command argument elements to 128. Added more verbose error
Timo Sirainen <tss@iki.fi>
parents:
764
diff
changeset
|
682 parser = imap_parser_create(input, NULL, 0, (size_t)-1); |
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
|
683 ret = imap_parser_read_args(parser, 0, IMAP_PARSE_FLAG_NO_UNESCAPE | |
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
|
684 IMAP_PARSE_FLAG_LITERAL_TYPE, &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
|
685 |
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 if (ret <= 0 || !imap_parse_bodystructure_args(args, str)) |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
687 value = 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
|
688 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
|
689 value = str_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
|
690 |
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 if (value == 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
|
692 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
|
693 |
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 imap_parser_destroy(parser); |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
647
diff
changeset
|
695 i_stream_unref(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
|
696 return value; |
8179ef2a2c62
If BODYSTRUCTURE is cached, we can use it to generate BODY reply. It takes
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
697 } |