summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-09-15 00:38:16 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-09-15 00:48:22 +0300
commit548d50fb19cd66dbe153e4d7e879501bab58c0aa (patch)
tree15d314cb92ab33406233ffcf79f72461a7b2f280 /examples
parent7b79a6edcda94d4224bc4cbbe47cb6dcf2ea42db (diff)
downloadmailutils-548d50fb19cd66dbe153e4d7e879501bab58c0aa.tar.gz
mailutils-548d50fb19cd66dbe153e4d7e879501bab58c0aa.tar.bz2
Rewrite libmailutils testsuite in Autotest.
* configure.ac: Create libmailutils/tests/atlocal and libmailutils/tests/Makefile. Remove libmailutils/testsuite. * examples/Makefile.am (noinst_PROGRAMS): Remove programs moved to libmailutils/tests. * examples/argcv.c -> libmailutils/tests/argcv.c * libmailutils/testsuite/Decode -> libmailutils/tests/Decode * libmailutils/testsuite/Encode -> libmailutils/tests/Encode * examples/decode2047.c: Move to libmailutils/tests * examples/encode2047.c: Move to libmailutils/tests * examples/mailcap.c: Likewise. * examples/url-parse.c: Likewise. * include/mailutils/Makefile.am: Minor changes. * libmailutils/Makefile.am (SUBDIRS): Replace testsuite with tests. * libmailutils/tests/Makefile.am: New file. * libmailutils/tests/addr.c: New file. * libmailutils/tests/address.at: New file. * libmailutils/tests/argcv.at: New file. * libmailutils/tests/atlocal.in: New file. * libmailutils/tests/base64d.at: New file. * libmailutils/tests/base64e.at: New file. * libmailutils/tests/decode2047.at: New file. * libmailutils/tests/encode2047.at: New file. * libmailutils/tests/fltst.c: New file. * libmailutils/tests/mailcap.at: New file. * libmailutils/tests/mime.at: New file. * libmailutils/tests/testsuite.at: New file. * libmailutils/tests/url.at: New file. * libmailutils/testsuite/: Delete. * frm/tests/Makefile.am: Prefix package.m4 creation commands with $(AM_V_GEN). * readmsg/tests/Makefile.am: Likewise. * sieve/tests/Makefile.am: Likewise. * frm/tests/testsuite.at: Minor changes. * readmsg/tests/testsuite.at: Include testsuite.inc. * sieve/tests/testsuite.at: Likewise. * sieve/tests/version.at: Comment out inclusion of testsuite.inc. * testsuite/testsuite.inc: Add m4_version_prereq.
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am17
-rw-r--r--examples/argcv.c60
-rw-r--r--examples/decode2047.c81
-rw-r--r--examples/encode2047.c206
-rw-r--r--examples/mailcap.c102
-rw-r--r--examples/mimetest.c296
-rw-r--r--examples/url-parse.c144
7 files changed, 1 insertions, 905 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 7e858d78a..c283d0db3 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -35,18 +35,13 @@ SUBDIRS = config $(CPP_DIR) python scheme
noinst_PROGRAMS = \
aclck\
addr\
- argcv\
base64\
- decode2047\
echosrv\
- encode2047\
header\
http\
iconv\
listop\
lsf\
- mailcap\
- mimetest\
msg-send\
mta\
mucat\
@@ -56,8 +51,7 @@ noinst_PROGRAMS = \
musocio\
$(NNTPCLIENT)\
$(POP3CLIENT)\
- sfrom\
- url-parse
+ sfrom
EXTRA_PROGRAMS = pop3client nntpclient
@@ -79,15 +73,6 @@ numaddr_la_SOURCES = numaddr.c
numaddr_la_LIBADD = ${MU_LIB_SIEVE}
numaddr_la_LDFLAGS = -module -avoid-version -no-undefined -rpath '$(moddir)'
-mimetest_LDADD =\
- ../lib/libmuaux.la\
- ${MU_LIB_MBOX}\
- ${MU_LIB_IMAP}\
- ${MU_LIB_POP}\
- ${MU_LIB_AUTH}\
- @MU_AUTHLIBS@\
- ${MU_LIB_MAILUTILS}
-
msg_send_LDADD =\
../lib/libmuaux.la\
${MU_LIB_MAILER}\
diff --git a/examples/argcv.c b/examples/argcv.c
deleted file mode 100644
index 3253feb70..000000000
--- a/examples/argcv.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 2005, 2007, 2009, 2010 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <mailutils/argcv.h>
-#include <mailutils/errno.h>
-
-int
-main (int argc, char **argv)
-{
- char *delim = "";
- char *comment = "#";
- char buf[512];
-
- while (fgets (buf, sizeof buf, stdin))
- {
- int status, c;
- char **v;
- char *s;
-
- status = mu_argcv_get (buf, delim, comment, &c, &v);
- if (status)
- {
- fprintf (stderr, "cannot parse: %s\n", mu_strerror (status));
- continue;
- }
- status = mu_argcv_string (c, v, &s);
- if (status)
- fprintf (stderr, "cannot create string: %s\n", mu_strerror (status));
- else
- {
- printf ("%d: %s\n", c, s);
- free (s);
- }
- mu_argcv_free (c, v);
- }
- exit (0);
-}
diff --git a/examples/decode2047.c b/examples/decode2047.c
deleted file mode 100644
index bdb1ca29d..000000000
--- a/examples/decode2047.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 2003, 2007, 2010 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-
-#include <mailutils/mailutils.h>
-
-#define ISPRINT(c) ((c)=='\t'||(c)==' '||(c)=='\n'||\
- ((unsigned char)(c)>' '&&(unsigned char)(c)<128))
-
-void
-print (char *p, int printable)
-{
- for (; *p; p++)
- {
- if (printable && *p != '\n' && !ISPRINT (*p))
- printf ("\\%03o", *(unsigned char *) p);
- else
- putchar (*p);
- }
-}
-
-int
-main (int argc, char *argv[])
-{
- char buf[256];
- int c, printable = 0;
- char *charset = "iso-8859-1";
-
- while ((c = getopt (argc, argv, "c:p")) != EOF)
- switch (c)
- {
- case 'c':
- charset = optarg;
- break;
- case 'p':
- printable = 1;
- break;
-
- default:
- exit (1);
- }
-
- while (fgets (buf, sizeof (buf), stdin))
- {
- char *p = NULL;
- int rc, len;
-
- len = strlen (buf);
- if (len > 0 && buf[len - 1] == '\n')
- buf[len - 1] = 0;
- rc = mu_rfc2047_decode (charset, buf, &p);
- printf ("%s=> %s\n", buf, mu_strerror (rc));
- if (p)
- print (p, printable);
- putchar ('\n');
- free (p);
- }
- return 0;
-}
diff --git a/examples/encode2047.c b/examples/encode2047.c
deleted file mode 100644
index b5b0dde36..000000000
--- a/examples/encode2047.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 2005, 2006, 2007, 2010 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-
-#include <mailutils/mailutils.h>
-
-/* Replace all octal escapes in BUF with the corresponding characters. */
-static void
-decode_octal (char *buf)
-{
- char *p;
- unsigned i, n;
-
- for (p = buf; *p;)
- {
- if (*buf == '\\')
- {
- buf++;
- switch (*buf)
- {
- case 'a':
- *p++ = '\a';
- buf++;
- break;
-
- case 'b':
- *p++ = '\b';
- buf++;
- break;
-
- case 'f':
- *p++ = '\f';
- buf++;
- break;
-
- case 'n':
- *p++ = '\n';
- buf++;
- break;
-
- case 'r':
- *p++ = '\r';
- buf++;
- break;
-
- case 't':
- *p++ = '\t';
- buf++;
- break;
-
- case '0': case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- n = 0;
- for (i = 0; i < 3; i++, buf++)
- {
- unsigned x = *(unsigned char*)buf - '0';
- if (x > 7)
- break;
- n <<= 3;
- n += x;
- }
- if (i != 3)
- {
- buf -= i;
- *p++ = '\\';
- }
- else
- *p++ = n;
- break;
-
- default:
- *p++ = '\\';
- *p++ = *buf++;
- break;
- }
- }
- else
- *p++ = *buf++;
- }
- *p = 0;
-}
-
-int
-main (int argc, char *argv[])
-{
- int c;
- char buf[256];
- char vbuf[256];
- char *charset = strdup ("iso-8859-1");
- char *encoding = strdup ("quoted-printable");
- int octal = 0;
-
- while ((c = getopt (argc, argv, "c:e:hot")) != EOF)
- switch (c)
- {
- case 'c':
- free (charset);
- charset = strdup (optarg);
- break;
-
- case 'e':
- free (encoding);
- encoding = strdup (optarg);
- break;
-
- case 'o':
- octal = 1;
- break;
-
- case 't':
- octal = 0;
- break;
-
- case 'h':
- printf ("usage: %s [-c charset] [-e encoding] [-ot]\n", argv[0]);
- exit (0);
-
- default:
- exit (1);
- }
-
- while (fgets (buf, sizeof (buf), stdin))
- {
- int len;
- char *p = NULL;
- char *cmd;
- int rc;
-
- len = strlen (buf);
- if (len > 0 && buf[len - 1] == '\n')
- buf[len - 1] = 0;
- strncpy(vbuf, buf, sizeof vbuf);
- cmd = vbuf;
- if (cmd[0] == '\\')
- {
- if (cmd[1] == 0)
- {
- fprintf (stderr, "Unfinished command\n");
- continue;
- }
-
- for (p = cmd + 2; *p && *p == ' '; p++)
- ;
- switch (cmd[1])
- {
- case 'c':
- free (charset);
- charset = strdup (p);
- continue;
-
- case 'e':
- free (encoding);
- encoding = strdup (p);
- continue;
-
- case 'o':
- octal = 1;
- continue;
-
- case 't':
- octal = 0;
- continue;
-
- case '\\':
- cmd++;
- break;
-
- default:
- fprintf (stderr, "Unknown command\n");
- continue;
- }
- }
-
- if (octal)
- decode_octal (cmd);
-
- rc = mu_rfc2047_encode (charset, encoding, cmd, &p);
- printf ("%s=> %s\n", buf, mu_strerror (rc));
- if (p)
- printf ("%s\n", p);
- free (p);
- }
- return 0;
-}
diff --git a/examples/mailcap.c b/examples/mailcap.c
deleted file mode 100644
index cacb752e9..000000000
--- a/examples/mailcap.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 1999, 2000, 2001, 2004, 2007, 2009, 2010 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <stdio.h>
-#include <mailutils/mailcap.h>
-#include <mailutils/stream.h>
-#include <mailutils/error.h>
-
-int
-main (int argc, char **argv)
-{
- mu_stream_t stream = NULL;
- int status = 0;
- char *file = argc == 1 ? "/etc/mailcap" : argv[1];
- mu_mailcap_t mailcap = NULL;
-
- status = mu_file_stream_create (&stream, file, MU_STREAM_READ);
- if (status)
- {
- mu_error ("cannot create file stream %s: %s",
- file, mu_strerror (status));
- exit (1);
- }
-
- status = mu_stream_open (stream);
- if (status)
- {
- mu_error ("cannot open file stream %s: %s",
- file, mu_strerror (status));
- exit (1);
- }
-
- status = mu_mailcap_create (&mailcap, stream);
- if (status == 0)
- {
- int i;
- size_t count = 0;
- char buffer[256];
-
- mu_mailcap_entries_count (mailcap, &count);
- for (i = 1; i <= count; i++)
- {
- size_t j;
- mu_mailcap_entry_t entry = NULL;
- size_t fields_count = 0;
-
- printf ("entry[%d]\n", i);
-
- mu_mailcap_get_entry (mailcap, i, &entry);
-
- /* typefield. */
- mu_mailcap_entry_get_typefield (entry, buffer,
- sizeof (buffer), NULL);
- printf ("\ttypefield: %s\n", buffer);
-
- /* view-command. */
- mu_mailcap_entry_get_viewcommand (entry, buffer,
- sizeof (buffer), NULL);
- printf ("\tview-command: %s\n", buffer);
-
- /* fields. */
- mu_mailcap_entry_fields_count (entry, &fields_count);
- for (j = 1; j <= fields_count; j++)
- {
- int status = mu_mailcap_entry_get_field (entry, j, buffer,
- sizeof (buffer), NULL);
- if (status)
- {
- mu_error ("cannot retrieve field %lu: %s",
- (unsigned long) j,
- mu_strerror (status));
- break;
- }
- printf ("\tfields[%lu]: %s\n", (unsigned long) j, buffer);
- }
- printf ("\n");
- }
- mu_mailcap_destroy (&mailcap);
- }
-
- return 0;
-}
diff --git a/examples/mimetest.c b/examples/mimetest.c
deleted file mode 100644
index e440b372e..000000000
--- a/examples/mimetest.c
+++ /dev/null
@@ -1,296 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 1999, 2000, 2001, 2005, 2007, 2009, 2010 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <strings.h>
-#include <unistd.h>
-
-#include <sys/types.h>
-
-#include <mailutils/mailutils.h>
-
-void message_display_parts(mu_message_t msg, int indent);
-
-const char *from;
-const char *subject;
-const char *charset;
-int print_attachments;
-int indent_level = 4;
-
-void
-print_file (const char *fname, int indent)
-{
- char buf[128];
- FILE *fp = fopen (fname, "r");
-
- if (!fp)
- {
- fprintf (stderr, "can't open file %s: %s", fname, strerror (errno));
- return;
- }
-
- while (fgets (buf, sizeof buf, fp))
- printf ("%*.*s%s", indent, indent, "", buf);
- fclose (fp);
- unlink (fname);
-}
-
-int
-main (int argc, char **argv)
-{
- mu_mailbox_t mbox = NULL;
- size_t i;
- size_t count = 0;
- char *mailbox_name;
- int debug = 0;
-
- for (i = 1; i < argc; i++)
- {
- if (strcmp (argv[i], "-d") == 0)
- debug = 1;
- else if (strcmp (argv[i], "-p") == 0)
- print_attachments = 1;
- else if (strcmp (argv[i], "-i") == 0)
- {
- if (++i == argc)
- {
- mu_error ("-i requires argument");
- exit (1);
- }
- indent_level = strtoul (argv[i], NULL, 0);
- }
- else if (strcmp (argv[i], "-c") == 0)
- {
- if (++i == argc)
- {
- mu_error ("-c requires argument");
- exit (1);
- }
- charset = argv[i];
- }
- else
- break;
- }
-
- mailbox_name = argv[i];
-
- /* Registration. */
- mu_registrar_record (mu_imap_record);
- mu_registrar_record (mu_pop_record);
- mu_registrar_record (mu_mbox_record);
- mu_registrar_set_default_record (mu_mbox_record);
-
- MU_ASSERT (mu_mailbox_create_default (&mbox, mailbox_name));
-
- /* Debugging trace. */
- if (debug)
- {
- mu_debug_t debug;
- mu_mailbox_get_debug (mbox, &debug);
- mu_debug_set_level (debug, MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
- }
-
- /* Open the mailbox for reading only. */
- MU_ASSERT (mu_mailbox_open (mbox, MU_STREAM_RDWR));
-
- /* Iterate through the entire message set. */
- MU_ASSERT (mu_mailbox_messages_count (mbox, &count));
-
- for (i = 1; i <= count; ++i)
- {
- mu_message_t msg;
- mu_header_t hdr;
- size_t nparts;
- size_t msize, nlines;
-
- MU_ASSERT (mu_mailbox_get_message (mbox, i, &msg));
- MU_ASSERT (mu_message_size (msg, &msize));
- MU_ASSERT (mu_message_lines (msg, &nlines));
- MU_ASSERT (mu_message_get_header (msg, &hdr));
- if (mu_header_sget_value (hdr, MU_HEADER_FROM, &from))
- from = "";
- if (mu_header_sget_value (hdr, MU_HEADER_SUBJECT, &subject))
- subject = "";
- printf ("Message: %lu\n", (unsigned long) i);
- printf ("From: %s\n", from);
- printf ("Subject: %s\n", subject);
-
- MU_ASSERT (mu_message_get_num_parts (msg, &nparts));
- printf ("Number of parts in message - %lu\n",
- (unsigned long) nparts);
- printf ("Total message size - %lu/%lu\n",
- (unsigned long) msize, (unsigned long) nlines);
- message_display_parts (msg, 0);
- }
- mu_mailbox_close (mbox);
- mu_mailbox_destroy (&mbox);
- return 0;
-}
-
-char buf[2048];
-
-static void
-print_message_part_sizes (mu_message_t part, int indent)
-{
- mu_body_t body;
- mu_header_t hdr;
- size_t msize, mlines, hsize, hlines, bsize, blines;
-
- MU_ASSERT (mu_message_size (part, &msize));
- MU_ASSERT (mu_message_lines (part, &mlines));
- MU_ASSERT (mu_message_get_header (part, &hdr));
- MU_ASSERT (mu_header_size (hdr, &hsize));
- MU_ASSERT (mu_header_lines (hdr, &hlines));
- MU_ASSERT (mu_message_get_body (part, &body));
- MU_ASSERT (mu_body_size (body, &bsize));
- MU_ASSERT (mu_body_lines (body, &blines));
- printf ("%*.*sMessage part size - %lu/%lu: %lu/%lu, %lu/%lu\n",
- indent, indent, "",
- (unsigned long) msize, (unsigned long) mlines,
- (unsigned long) hsize, (unsigned long) hlines,
- (unsigned long) bsize, (unsigned long) blines);
-}
-
-void
-message_display_parts (mu_message_t msg, int indent)
-{
- int ret, j;
- size_t nparts;
- mu_message_t part;
- mu_header_t hdr;
- mu_stream_t str;
- mu_body_t body;
- int ismulti;
- size_t nbytes;
-
- /* How many parts does the message has? */
- if ((ret = mu_message_get_num_parts (msg, &nparts)) != 0)
- {
- fprintf (stderr, "mu_message_get_num_parts - %s\n", mu_strerror (ret));
- exit (2);
- }
-
- /* Iterate through all the parts.
- Treat type "message/rfc822" differently, since it is a message of
- its own that can have other subparts(recursive). */
- 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,
- &hvalue);
- if (status == MU_ERR_NOENT)
- /* nothing */;
- else if (status != 0)
- mu_error ("Cannot get header value: %s", mu_strerror (status));
- else
- {
- 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 ? type : "");
- print_message_part_sizes (part, indent);
- if (mu_header_sget_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING,
- &encoding))
- encoding = "";
- ismulti = 0;
- if ((type
- && mu_c_strcasecmp (type, "message/rfc822") == 0)
- || (mu_message_is_multipart (part, &ismulti) == 0 && ismulti))
- {
- if (!ismulti)
- MU_ASSERT (mu_message_unencapsulate (part, &part, NULL));
-
- MU_ASSERT (mu_message_get_header (part, &hdr));
- if (mu_header_sget_value (hdr, MU_HEADER_FROM, &from))
- from = "";
- if (mu_header_sget_value (hdr, MU_HEADER_SUBJECT, &subject))
- subject = "";
- printf ("%*.*sEncapsulated message : %s\t%s\n",
- indent, indent, "", from, subject);
- printf ("%*.*sBegin\n", indent, indent, "");
- message_display_parts (part, indent + indent_level);
- mu_message_destroy (&part, NULL);
- }
- 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_streamref (body, &str);
- /* Make sure the original body stream is not closed when
- str gets destroyed */
- mu_filter_create (&str, str, encoding, MU_FILTER_DECODE,
- MU_STREAM_READ);
-
- while (mu_stream_readline (str, buf, sizeof (buf), &nbytes) == 0
- && nbytes)
- {
- printf ("%*.*s%s", indent, indent, "", buf);
- }
- mu_stream_destroy (&str);
- }
- else
- {
- /* Save the attachements. */
- char *fname = NULL;
-
- mu_message_aget_decoded_attachment_name (part, charset,
- &fname, NULL);
- if (fname == NULL)
- fname = mu_tempname (NULL);
-
- printf ("%*.*sAttachment - saving [%s]\n", indent, indent, "",
- fname);
- printf ("%*.*sBegin\n", indent, indent, "");
- 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);
- }
-}
-
diff --git a/examples/url-parse.c b/examples/url-parse.c
deleted file mode 100644
index 82541b5fb..000000000
--- a/examples/url-parse.c
+++ /dev/null
@@ -1,144 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 1999, 2000, 2001, 2007, 2009, 2010 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <mailutils/error.h>
-#include <mailutils/errno.h>
-#include <mailutils/url.h>
-#include <mailutils/secret.h>
-
-#define CAT2(a,b) a ## b
-
-#define GET_AND_PRINT(field,u,buf,status) \
- status = CAT2(mu_url_sget_,field) (u, &buf); \
- if (status == MU_ERR_NOENT) \
- buf = ""; \
- else if (status) \
- { \
- mu_error ("cannot get %s: %s", #field, mu_strerror (status)); \
- exit (1); \
- } \
- printf ("\t" #field " <%s>\n", buf)
-
-static void
-print_fvpairs (mu_url_t url)
-{
- size_t fvc, i;
- char **fvp;
- int rc = mu_url_sget_fvpairs (url, &fvc, &fvp);
- if (rc)
- {
- mu_error ("cannot get F/V pairs: %s", mu_strerror (rc));
- exit (1);
- }
- if (fvc == 0)
- return;
- for (i = 0; i < fvc; i++)
- printf ("\tparam[%lu] <%s>\n", (unsigned long) i, fvp[i]);
-}
-
-static void
-print_query (mu_url_t url)
-{
- size_t qargc, i;
- char **qargv;
- int rc = mu_url_sget_query (url, &qargc, &qargv);
- if (rc)
- {
- mu_error ("cannot get query: %s", mu_strerror (rc));
- exit (1);
- }
- if (qargc == 0)
- return;
- for (i = 0; i < qargc; i++)
- printf ("\tquery[%lu] <%s>\n", (unsigned long) i, qargv[i]);
-}
-
-int
-main ()
-{
- char str[1024];
- long port = 0;
- mu_url_t u = NULL;
-
- while (fgets (str, sizeof (str), stdin) != NULL)
- {
- int rc;
- const char *buf;
- mu_secret_t secret;
-
- str[strlen (str) - 1] = '\0'; /* chop newline */
- if (strspn (str, " \t") == strlen (str))
- continue; /* skip empty lines */
- if ((rc = mu_url_create (&u, str)) != 0)
- {
- fprintf (stderr, "mu_url_create %s ERROR: [%d] %s",
- str, rc, mu_strerror (rc));
- exit (1);
- }
- if ((rc = mu_url_parse (u)) != 0)
- {
- printf ("%s => FAILED: [%d] %s\n",
- str, rc, mu_strerror (rc));
- continue;
- }
- printf ("%s => SUCCESS\n", str);
-
- GET_AND_PRINT (scheme, u, buf, rc);
- GET_AND_PRINT (user, u, buf, rc);
-
- rc = mu_url_get_secret (u, &secret);
- if (rc == MU_ERR_NOENT)
- printf ("\tpasswd <>\n");
- else if (rc)
- {
- mu_error ("cannot get %s: %s", "passwd", mu_strerror (rc));
- exit (1);
- }
- else
- {
- printf ("\tpasswd <%s>\n", mu_secret_password (secret));
- mu_secret_password_unref (secret);
- }
-
- GET_AND_PRINT (auth, u, buf, rc);
- GET_AND_PRINT (host, u, buf, rc);
-
- rc = mu_url_get_port (u, &port);
- if (rc)
- {
- mu_error ("cannot get %s: %s", "port", mu_strerror (rc));
- exit (1);
- }
- printf ("\tport %ld\n", port);
-
- GET_AND_PRINT (path, u, buf, rc);
- print_fvpairs (u);
- print_query (u);
-
- mu_url_destroy (&u);
-
- }
- return 0;
-}

Return to:

Send suggestions and report system problems to the System administrator.