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)
return rc;
}
static int
build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text)
static void
mime_create_reason (mu_mime_t mime, mu_message_t msg, const char *text)
{
mu_mime_t mime = NULL;
char datestr[80];
mu_mime_create (&mime, NULL, 0);
{
mu_message_t newmsg;
mu_stream_t stream;
time_t t;
......@@ -147,6 +142,10 @@ build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text)
char *sender;
size_t off = 0;
mu_body_t body;
mu_header_t hdr;
char datestr[80];
static char *content_header = "Content-Type: text/plain;charset=" MU_SIEVE_CHARSET "\n"
"Content-Transfer-Encoding: 8bit\n";
mu_message_create (&newmsg, NULL);
mu_message_get_body (newmsg, &body);
......@@ -167,18 +166,22 @@ build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text)
mu_stream_printf (stream, &off, "Reason given was as follows:\n\n");
mu_stream_printf (stream, &off, "%s", text);
mu_stream_close (stream);
mu_header_create (&hdr, content_header, strlen (content_header), newmsg);
mu_message_set_header (newmsg, hdr, NULL);
mu_mime_add_part (mime, newmsg);
mu_message_unref (newmsg);
}
}
/* message/delivery-status */
{
static void
mime_create_ds (mu_mime_t mime)
{
mu_message_t newmsg;
mu_stream_t stream;
mu_header_t hdr;
size_t off = 0;
mu_body_t body;
char *email;
char datestr[80];
mu_message_create (&newmsg, NULL);
mu_message_get_header (newmsg, &hdr);
......@@ -198,10 +201,13 @@ build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text)
mu_stream_close (stream);
mu_mime_add_part(mime, newmsg);
mu_message_unref (newmsg);
}
}
/* Quote original message */
{
/* Quote original message */
static int
mime_create_quote (mu_mime_t mime, mu_message_t msg)
{
mu_message_t newmsg;
mu_stream_t istream, ostream;
mu_header_t hdr;
......@@ -229,6 +235,23 @@ build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text)
mu_stream_close (ostream);
mu_mime_add_part (mime, newmsg);
mu_message_unref (newmsg);
return 0;
}
static int
build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text)
{
mu_mime_t mime = NULL;
int status;
mu_mime_create (&mime, NULL, 0);
mime_create_reason (mime, msg, text);
mime_create_ds (mime);
status = mime_create_quote (mime, msg);
if (status)
{
mu_mime_destroy (&mime);
return status;
}
*pmime = mime;
......