aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Makefile9
-rw-r--r--g_mime_test.c96
2 files changed, 105 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000..0f50a434
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,9 @@
+PROGS=g_mime_test
+
+all: $(PROGS)
+
+g_mime_test: g_mime_test.c
+ $(CC) g_mime_test.c `pkg-config --cflags --libs gmime-2.4` -o g_mime_test
+
+clean:
+ rm -f $(PROGS)
diff --git a/g_mime_test.c b/g_mime_test.c
new file mode 100644
index 00000000..eb624b69
--- /dev/null
+++ b/g_mime_test.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright © 2009 Carl Worth
+ *
+ * This program 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 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program. If not, see http://www.gnu.org/licenses/ .
+ *
+ * Author: Carl Worth <cworth@cworth.org>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <gmime/gmime.h>
+
+#define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
+
+static void
+print_header (const char *name, const char *value)
+{
+ printf ("%s:", name);
+ if (value)
+ printf ("\t%s", value);
+ printf ("\n");
+}
+
+int
+main (int argc, char **argv)
+{
+ GMimeStream *stream;
+ GMimeParser *parser;
+ GMimeMessage *message;
+
+ const char *filename;
+ FILE *file;
+
+ const char *sup_entry_headers[] = {
+ "From",
+ "Subject",
+ "Date",
+ "References",
+ "CC",
+ "To",
+ "In-Reply-To"
+ };
+ const char *value;
+ int i;
+
+ if (argc < 2) {
+ fprintf (stderr, "Usage: %s <mail-message>\n",
+ argv[0]);
+ exit (1);
+ }
+
+ filename = argv[1];
+
+ file = fopen (filename, "r");
+ if (! file) {
+ fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));
+ exit (1);
+ }
+
+ g_mime_init (0);
+
+ stream = g_mime_stream_file_new (file);
+
+ parser = g_mime_parser_new_with_stream (stream);
+
+ message = g_mime_parser_construct_message (parser);
+
+ value = g_mime_message_get_message_id (message);
+ print_header ("message_id", value);
+
+ for (i = 0; i < ARRAY_SIZE (sup_entry_headers); i++) {
+ value = g_mime_object_get_header (GMIME_OBJECT (message),
+ sup_entry_headers[i]);
+ print_header (sup_entry_headers[i], value);
+ }
+
+ g_object_unref (message);
+ g_object_unref (parser);
+ g_object_unref (stream);
+
+ return 0;
+}