summaryrefslogtreecommitdiff
path: root/examples/mimetest.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-04-08 23:13:38 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-04-08 23:13:38 +0300
commit787121995cef1f77d279df9b70a9eb1f4fb35325 (patch)
tree795ae383ac877b97091d738ea6d4b9a50a5b80b8 /examples/mimetest.c
parentd02e8bf4ee35f5b1f81208b56b545e1f2d6ac2a9 (diff)
downloadmailutils-787121995cef1f77d279df9b70a9eb1f4fb35325.tar.gz
mailutils-787121995cef1f77d279df9b70a9eb1f4fb35325.tar.bz2
Fix all FIXMEs from b2c1b1ff. Revise attachment API.
* include/mailutils/message.h (mu_message_save_attachment) (mu_message_encapsulate, mu_message_unencapsulate): Change type of the last argument. (mu_mime_io_buffer_create,mu_mime_io_buffer_destroy) (mu_mime_io_buffer_set_size,mu_mime_io_buffer_get_size) (mu_mime_io_buffer_set_charset,mu_mime_io_buffer_sget_charset) (mu_mime_io_buffer_aget_charset): New prototypes. (mu_mimehdr_get_disp,mu_mimehdr_aget_disp): Remove unneeded parameter. * include/mailutils/types.hin (mu_mime_io_buffer_t): New type. * mailbox/attachment.c (_msg_info): Rename structure to _mu_mime_io_buffer. <header_buf,header_len,mu_header_size>: Remove unreferenced members. <refcnt,bufsize,charset>: New members. <ioffset,ooffset>: Change type to size_t. (mu_mime_io_buffer_create,mu_mime_io_buffer_destroy) (mu_mime_io_buffer_set_size,mu_mime_io_buffer_get_size) (mu_mime_io_buffer_set_charset,mu_mime_io_buffer_sget_charset) (mu_mime_io_buffer_aget_charset): New functions. (mu_message_save_attachment) (mu_message_encapsulate, mu_message_unencapsulate): Take mu_mime_io_buffer_t as the last argument. * mailbox/mimehdr.c (mu_mimehdr_get_disp): Remove unneeded parameter. (mu_mimehdr_aget_disp): Remove unneeded parameter. Store return value into pvalue. * examples/mimetest.c (message_display_parts): Use mu_mimehdr_aget_disp and mu_mime_io_buffer_* functions. * mailbox/testsuite/Mime: Update. * mh/mhn.c (options, opt_handler): New option --charset. (store_handler): Use mu_message_aget_decoded_attachment_name.
Diffstat (limited to 'examples/mimetest.c')
-rw-r--r--examples/mimetest.c59
1 files changed, 37 insertions, 22 deletions
diff --git a/examples/mimetest.c b/examples/mimetest.c
index 53ae37719..bca97af28 100644
--- a/examples/mimetest.c
+++ b/examples/mimetest.c
@@ -35,7 +35,7 @@ void message_display_parts(mu_message_t msg, int indent);
const char *from;
const char *subject;
-const char *charset = "UTF-8";
+const char *charset;
int print_attachments;
int indent_level = 4;
@@ -180,8 +180,6 @@ message_display_parts (mu_message_t msg, int indent)
size_t nparts, nsubparts;
mu_message_t part;
mu_header_t hdr;
- const char *type;
- const char *encoding;
mu_stream_t str;
mu_body_t body;
int offset, ismulti;
@@ -200,24 +198,34 @@ message_display_parts (mu_message_t msg, int indent)
for (j = 1; j <= nparts; j++)
{
int status;
+ const char *hvalue;
+ char *type = NULL;
+ const char *encoding = "";
+
MU_ASSERT (mu_message_get_part (msg, j, &part));
MU_ASSERT (mu_message_get_header (part, &hdr));
- status = mu_header_sget_value (hdr, MU_HEADER_CONTENT_TYPE, &type);
+ status = mu_header_sget_value (hdr, MU_HEADER_CONTENT_TYPE,
+ &hvalue);
if (status == MU_ERR_NOENT)
- type = "";
+ /* nothing */;
else if (status != 0)
+ mu_error ("Cannot get header value: %s", mu_strerror (status));
+ else
{
- type = "";
- mu_error ("Cannot get header value: %s", mu_strerror (status));
+ status = mu_mimehdr_aget_disp (hvalue, &type);
+ if (status)
+ mu_error ("Cannot extract content type field: %s",
+ mu_strerror (status));
}
- printf ("%*.*sType of part %d = %s\n", indent, indent, "", j, type);
+ printf ("%*.*sType of part %d = %s\n", indent, indent, "",
+ j, type ? type : "");
print_message_part_sizes (part, indent);
if (mu_header_sget_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING,
&encoding))
encoding = "";
ismulti = 0;
- if ((type[0]
- && mu_c_strncasecmp (type, "message/rfc822", strlen (type)) == 0)
+ if ((type
+ && mu_c_strcasecmp (type, "message/rfc822") == 0)
|| (mu_message_is_multipart (part, &ismulti) == 0 && ismulti))
{
if (!ismulti)
@@ -232,23 +240,21 @@ message_display_parts (mu_message_t msg, int indent)
indent, indent, "", from, subject);
printf ("%*.*sBegin\n", indent, indent, "");
MU_ASSERT (mu_message_get_num_parts (part, &nsubparts));
- message_display_parts (part, indent+indent_level);
+ message_display_parts (part, indent + indent_level);
mu_message_destroy (&part, NULL);
}
- else if (type[0] == '\0'
- || (mu_c_strncasecmp (type, "text/plain", strlen ("text/plain")) ==
- 0)
- || (mu_c_strncasecmp (type, "text/html", strlen ("text/html")) ==
- 0))
- {
- printf ("%*.*sText Message\n", indent, indent, "");
+ else if (!type
+ || (mu_c_strcasecmp (type, "text/plain") == 0)
+ || (mu_c_strcasecmp (type, "text/html")) == 0)
+ {
+ printf ("%*.*sText Message\n", indent, indent, "");
printf ("%*.*sBegin\n", indent, indent, "");
mu_message_get_body (part, &body);
mu_body_get_stream (body, &str);
mu_filter_create (&str, str, encoding, 0, 0);
offset = 0;
- while (mu_stream_readline (str, buf, sizeof (buf), offset, &nbytes) ==
- 0 && nbytes)
+ while (mu_stream_readline (str, buf, sizeof (buf),
+ offset, &nbytes) == 0 && nbytes)
{
printf ("%*.*s%s", indent, indent, "", buf);
offset += nbytes;
@@ -268,13 +274,22 @@ message_display_parts (mu_message_t msg, int indent)
printf ("%*.*sAttachment - saving [%s]\n", indent, indent, "",
fname);
printf ("%*.*sBegin\n", indent, indent, "");
- /*FIXME: What is the 'data' argument for? */
- mu_message_save_attachment (part, fname, NULL);
+ if (charset)
+ {
+ mu_mime_io_buffer_t info;
+ mu_mime_io_buffer_create (&info);
+ mu_mime_io_buffer_set_charset (info, charset);
+ MU_ASSERT (mu_message_save_attachment (part, NULL, info));
+ mu_mime_io_buffer_destroy (&info);
+ }
+ else
+ MU_ASSERT (mu_message_save_attachment (part, fname, NULL));
if (print_attachments)
print_file (fname, indent);
free (fname);
}
printf ("\n%*.*sEnd\n", indent, indent, "");
+ free (type);
}
}

Return to:

Send suggestions and report system problems to the System administrator.