From: Carl Worth Date: Mon, 12 Oct 2009 22:50:02 +0000 (-0700) Subject: Initial commit of a test program to form the basis of notmuch. X-Git-Tag: 0.1~899 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=7d0886352cff30c5d79155d144f8ef2384b38829;ds=sidebyside Initial commit of a test program to form the basis of notmuch. Basically just playing with some simple code using libgmime to parse an email message. --- 7d0886352cff30c5d79155d144f8ef2384b38829 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 + */ + +#include +#include +#include +#include + +#include + +#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 \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; +}