summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-12-22 12:31:25 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2011-12-22 12:40:45 +0200
commite218f1ec00749701a00c074c4574a75a6f156d2b (patch)
tree2e2bcfaeefbd30fd5cc55d01cd95e3c792e4dc60 /testsuite
parent690b1bf8506e50cb85d2634ba2db2fddbff99dfe (diff)
downloadmailutils-e218f1ec00749701a00c074c4574a75a6f156d2b.tar.gz
mailutils-e218f1ec00749701a00c074c4574a75a6f156d2b.tar.bz2
Implement imap (client) bodystructure and envelope.
* libmailutils/string/wordsplit.c (alloc_space): Fix reallocation calculations. * imap4d/fetch.c (bodystructure): Output number of lines for any TEXT part, not only TEXT/PLAIN. * include/mailutils/header.h (MU_HEADER_CONTENT_LOCATION): New define. * include/mailutils/imap.h (mu_imap_fetch_bodystructure): Implement. (mu_imap_fetch_envelope): Replace data fields with a single pointer to struct mu_imapenvelope. * include/mailutils/message.h: Include datetime.h (mu_imapenvelope, mu_bodystructure): New structs. (mu_message_type): New type. (mu_message_get_imapenvelope,mu_message_imapenvelope_free) (mu_message_set_imapenvelope) (mu_bodystructure_free,mu_list_free_bodystructure) (mu_message_get_bodystructure) (mu_message_set_bodystructure): New protos. * include/mailutils/mime.h (mu_mime_param_assoc_create) (mu_mime_param_assoc_add): New protos. * include/mailutils/sys/message.h (_mu_message)<_imapenvelope> <_bodystructure>: New methods. * libmailutils/mailbox/bodystruct.c: New file. * libmailutils/mailbox/imapenv.c: New file. * libmailutils/mailbox/Makefile.am (libmailbox_la_SOURCES): Add new sources. * libproto/imap/fetch.c: Implement bodystructure. * mu/imap.c: Likewise. * testsuite/bs.c: New file. * testsuite/Makefile.am (noinst_PROGRAMS): Add bs.
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/Makefile.am1
-rw-r--r--testsuite/bs.c169
2 files changed, 170 insertions, 0 deletions
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 219731def..2a9f4ea89 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -50,6 +50,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
INCLUDES = @MU_LIB_COMMON_INCLUDES@
noinst_PROGRAMS = \
+ bs\
fldel\
lstuid\
mbdel\
diff --git a/testsuite/bs.c b/testsuite/bs.c
new file mode 100644
index 000000000..8f74b2d86
--- /dev/null
+++ b/testsuite/bs.c
@@ -0,0 +1,169 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ GNU Mailutils is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GNU Mailutils is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <mailutils/mailutils.h>
+
+#define S(str) ((str) ? (str) : "")
+
+static void
+print_param (const char *prefix, mu_assoc_t assoc, int indent)
+{
+ mu_iterator_t itr;
+ int i;
+
+ mu_printf ("%*s%s:\n", indent, "", prefix);
+ if (!assoc)
+ return;
+ indent += 4;
+ MU_ASSERT (mu_assoc_get_iterator (assoc, &itr));
+
+ for (i = 0, mu_iterator_first (itr);
+ !mu_iterator_is_done (itr);
+ i++, mu_iterator_next (itr))
+ {
+ const char *name;
+ struct mu_mime_param *p;
+
+ mu_iterator_current_kv (itr, (const void **)&name, (void**)&p);
+ mu_printf ("%*s%d: %s=%s\n", indent, "", i, name, p->value);
+ }
+ mu_iterator_destroy (&itr);
+}
+
+struct print_data
+{
+ int num;
+ int level;
+};
+
+static void print_bs (struct mu_bodystructure *bs, int level);
+
+static int
+print_item (void *item, void *data)
+{
+ struct mu_bodystructure *bs = item;
+ struct print_data *pd = data;
+ mu_printf ("%*sPart #%d\n", (pd->level-1) << 2, "", pd->num);
+ print_bs (bs, pd->level);
+ ++pd->num;
+ return 0;
+}
+
+static void
+print_address (const char *title, mu_address_t addr, int indent)
+{
+ mu_printf ("%*s%s: ", indent, "", title);
+ mu_stream_format_address (mu_strout, addr);
+ mu_printf ("\n");
+}
+
+static void
+print_imapenvelope (struct mu_imapenvelope *env, int level)
+{
+ int indent = (level << 2);
+
+ mu_printf ("%*sEnvelope:\n", indent, "");
+ indent += 4;
+ mu_printf ("%*sTime: ", indent, "");
+ mu_c_streamftime (mu_strout, "%c%n", &env->date, &env->tz);
+ mu_printf ("%*sSubject: %s\n", indent, "", S(env->subject));
+ print_address ("From", env->from, indent);
+ print_address ("Sender", env->sender, indent);
+ print_address ("Reply-to", env->reply_to, indent);
+ print_address ("To", env->to, indent);
+ print_address ("Cc", env->cc, indent);
+ print_address ("Bcc", env->bcc, indent);
+ mu_printf ("%*sIn-Reply-To: %s\n", indent, "", S(env->in_reply_to));
+ mu_printf ("%*sMessage-ID: %s\n", indent, "", S(env->message_id));
+}
+
+static void
+print_bs (struct mu_bodystructure *bs, int level)
+{
+ int indent = level << 2;
+ mu_printf ("%*sbody_type=%s\n", indent, "", S(bs->body_type));
+ mu_printf ("%*sbody_subtype=%s\n", indent, "", S(bs->body_subtype));
+ print_param ("Parameters", bs->body_param, indent);
+ mu_printf ("%*sbody_id=%s\n", indent, "", S(bs->body_id));
+ mu_printf ("%*sbody_descr=%s\n", indent, "", S(bs->body_descr));
+ mu_printf ("%*sbody_encoding=%s\n", indent, "", S(bs->body_encoding));
+ mu_printf ("%*sbody_size=%lu\n", indent, "", (unsigned long) bs->body_size);
+ /* Optional */
+ mu_printf ("%*sbody_md5=%s\n", indent, "", S(bs->body_md5));
+ mu_printf ("%*sbody_disposition=%s\n", indent, "", S(bs->body_disposition));
+ print_param ("Disposition Parameters", bs->body_disp_param, indent);
+ mu_printf ("%*sbody_language=%s\n", indent, "", S(bs->body_language));
+ mu_printf ("%*sbody_location=%s\n", indent, "", S(bs->body_location));
+
+ mu_printf ("%*sType ", indent, "");
+ switch (bs->body_message_type)
+ {
+ case mu_message_other:
+ mu_printf ("mu_message_other\n");
+ break;
+
+ case mu_message_text:
+ mu_printf ("mu_message_text:\n%*sbody_lines=%lu\n", indent + 4, "",
+ (unsigned long) bs->v.text.body_lines);
+ break;
+
+ case mu_message_rfc822:
+ mu_printf ("mu_message_rfc822:\n%*sbody_lines=%lu\n", indent + 4, "",
+ (unsigned long) bs->v.rfc822.body_lines);
+ print_imapenvelope (bs->v.rfc822.body_env, level + 1);
+ print_bs (bs->v.rfc822.body_struct, level + 1);
+ break;
+
+ case mu_message_multipart:
+ {
+ struct print_data pd;
+ pd.num = 0;
+ pd.level = level + 1;
+ mu_printf ("mu_message_multipart:\n");
+ mu_list_foreach (bs->v.multipart.body_parts, print_item, &pd);
+ }
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ mu_mailbox_t mbox;
+ mu_message_t mesg;
+ struct mu_bodystructure *bs;
+
+ if (argc != 3)
+ {
+ fprintf (stderr, "usage: %s URL NUM\n", argv[0]);
+ return 1;
+ }
+
+ mu_register_all_mbox_formats ();
+ MU_ASSERT (mu_mailbox_create (&mbox, argv[1]));
+ MU_ASSERT (mu_mailbox_open (mbox, MU_STREAM_READ));
+ MU_ASSERT (mu_mailbox_get_message (mbox, atoi (argv[2]), &mesg));
+ MU_ASSERT (mu_message_get_bodystructure (mesg, &bs));
+ print_bs (bs, 0);
+ mu_bodystructure_free (bs);
+
+ return 0;
+}

Return to:

Send suggestions and report system problems to the System administrator.