Commit 42a59a2f 42a59a2fb37dd5f7b01e2d1d08405163d17c10ab by Sergey Poznyakoff

(build_mime): Split into three smaller

functions, each for its own task.
Add Content-Type,Content-Transfer-Encoding headers to the
DSN. Proposed by Kostas Zorbadelos.
1 parent ccc5e5a2
...@@ -132,14 +132,9 @@ mu_sieve_get_message_sender (mu_message_t msg, char **ptext) ...@@ -132,14 +132,9 @@ mu_sieve_get_message_sender (mu_message_t msg, char **ptext)
132 return rc; 132 return rc;
133 } 133 }
134 134
135 static int 135 static void
136 build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text) 136 mime_create_reason (mu_mime_t mime, mu_message_t msg, const char *text)
137 { 137 {
138 mu_mime_t mime = NULL;
139 char datestr[80];
140
141 mu_mime_create (&mime, NULL, 0);
142 {
143 mu_message_t newmsg; 138 mu_message_t newmsg;
144 mu_stream_t stream; 139 mu_stream_t stream;
145 time_t t; 140 time_t t;
...@@ -147,6 +142,10 @@ build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text) ...@@ -147,6 +142,10 @@ build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text)
147 char *sender; 142 char *sender;
148 size_t off = 0; 143 size_t off = 0;
149 mu_body_t body; 144 mu_body_t body;
145 mu_header_t hdr;
146 char datestr[80];
147 static char *content_header = "Content-Type: text/plain;charset=" MU_SIEVE_CHARSET "\n"
148 "Content-Transfer-Encoding: 8bit\n";
150 149
151 mu_message_create (&newmsg, NULL); 150 mu_message_create (&newmsg, NULL);
152 mu_message_get_body (newmsg, &body); 151 mu_message_get_body (newmsg, &body);
...@@ -167,18 +166,22 @@ build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text) ...@@ -167,18 +166,22 @@ build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text)
167 mu_stream_printf (stream, &off, "Reason given was as follows:\n\n"); 166 mu_stream_printf (stream, &off, "Reason given was as follows:\n\n");
168 mu_stream_printf (stream, &off, "%s", text); 167 mu_stream_printf (stream, &off, "%s", text);
169 mu_stream_close (stream); 168 mu_stream_close (stream);
169 mu_header_create (&hdr, content_header, strlen (content_header), newmsg);
170 mu_message_set_header (newmsg, hdr, NULL);
170 mu_mime_add_part (mime, newmsg); 171 mu_mime_add_part (mime, newmsg);
171 mu_message_unref (newmsg); 172 mu_message_unref (newmsg);
172 } 173 }
173 174
174 /* message/delivery-status */ 175 static void
175 { 176 mime_create_ds (mu_mime_t mime)
177 {
176 mu_message_t newmsg; 178 mu_message_t newmsg;
177 mu_stream_t stream; 179 mu_stream_t stream;
178 mu_header_t hdr; 180 mu_header_t hdr;
179 size_t off = 0; 181 size_t off = 0;
180 mu_body_t body; 182 mu_body_t body;
181 char *email; 183 char *email;
184 char datestr[80];
182 185
183 mu_message_create (&newmsg, NULL); 186 mu_message_create (&newmsg, NULL);
184 mu_message_get_header (newmsg, &hdr); 187 mu_message_get_header (newmsg, &hdr);
...@@ -198,10 +201,13 @@ build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text) ...@@ -198,10 +201,13 @@ build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text)
198 mu_stream_close (stream); 201 mu_stream_close (stream);
199 mu_mime_add_part(mime, newmsg); 202 mu_mime_add_part(mime, newmsg);
200 mu_message_unref (newmsg); 203 mu_message_unref (newmsg);
201 } 204 }
202 205
203 /* Quote original message */ 206
204 { 207 /* Quote original message */
208 static int
209 mime_create_quote (mu_mime_t mime, mu_message_t msg)
210 {
205 mu_message_t newmsg; 211 mu_message_t newmsg;
206 mu_stream_t istream, ostream; 212 mu_stream_t istream, ostream;
207 mu_header_t hdr; 213 mu_header_t hdr;
...@@ -229,6 +235,23 @@ build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text) ...@@ -229,6 +235,23 @@ build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text)
229 mu_stream_close (ostream); 235 mu_stream_close (ostream);
230 mu_mime_add_part (mime, newmsg); 236 mu_mime_add_part (mime, newmsg);
231 mu_message_unref (newmsg); 237 mu_message_unref (newmsg);
238 return 0;
239 }
240
241 static int
242 build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text)
243 {
244 mu_mime_t mime = NULL;
245 int status;
246
247 mu_mime_create (&mime, NULL, 0);
248 mime_create_reason (mime, msg, text);
249 mime_create_ds (mime);
250 status = mime_create_quote (mime, msg);
251 if (status)
252 {
253 mu_mime_destroy (&mime);
254 return status;
232 } 255 }
233 256
234 *pmime = mime; 257 *pmime = mime;
......