summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2003-02-24 10:34:16 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2003-02-24 10:34:16 +0000
commit5e3869578b5259eac979a377256c1858d2c4cbde (patch)
tree04b7c6b7648fb593bbc549711ac5e978a4735df8
parent577e475312e614c8985a2fb14240eb9329e56d99 (diff)
downloadmailutils-5e3869578b5259eac979a377256c1858d2c4cbde.tar.gz
mailutils-5e3869578b5259eac979a377256c1858d2c4cbde.tar.bz2
Added to the repository
-rw-r--r--examples/mailcap.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/examples/mailcap.c b/examples/mailcap.c
new file mode 100644
index 000000000..f5586104d
--- /dev/null
+++ b/examples/mailcap.c
@@ -0,0 +1,89 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 1999, 2000, 2001 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 2, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#include <stdio.h>
+#include <mailutils/mailcap.h>
+#include <mailutils/stream.h>
+#include <mailutils/error.h>
+
+int
+main(int argc, char **argv)
+{
+ stream_t stream = NULL;
+ int status = 0;
+ char *file = argc == 1 ? "/etc/mailcap" : argv[1];
+ mu_mailcap_t mailcap = NULL;
+
+ status = 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 = 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++)
+ {
+ int j;
+ mu_mailcap_entry_t entry = NULL;
+ int 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++)
+ {
+ mu_mailcap_entry_get_field (entry, j, buffer,
+ sizeof (buffer), NULL);
+ printf ("\tfields[%d]: %s\n", j, buffer);
+ }
+ printf ("\n");
+ }
+ mu_mailcap_destroy (&mailcap);
+ }
+
+ return 0;
+}

Return to:

Send suggestions and report system problems to the System administrator.