|
|
|||
Mit GMime E-Mails parsenHabt ihr schon mal versucht mit C E-Mails zu parsen? Das kann ziemlich ekelhaft werden.
#include <stdio.h> #include <fcntl.h> #include <glib.h> #include <gmime/gmime.h> int main (int argc, char const *argv[]) { gboolean is_html; GMimeMessage *message; GMimeParser *parser; GMimeStream *stream; char *body; int fd, i = 1; if (argc < 2) return 0; g_mime_init (0); if ((fd = open (argv[i], O_RDONLY)) == -1) return 0; stream = g_mime_stream_fs_new (fd); parser = g_mime_parser_new_with_stream (stream); g_object_unref (stream); message = g_mime_parser_construct_message (parser); body = g_mime_message_get_body (message, FALSE, &is_html); fprintf (stdout, "Testing get_body (looking for html...%s)\n\n%s\n\n", body && is_html ? "found" : "not found", body ? body : "No message body found"); g_free (body); return 0; } Kompiliert wird das Programm mit gcc -g -Wall `pkg-config --cflags gmime-2.0 glib-2.0` `pkg-config --libs gmime-2.0 glib-2.0` test.c -o test Als erstes Argument muss der Pfad zur E-Mail angegeben werden. Bei der Verwendung von GMime bin ich aber leider auch über einen Bug gestolpert. Will man die Absender Aber grundsätzlich kann man sagen, dass GMime eine hervorragende Library ist, um in C E-Mails |
|||
Copyright © 2009 treibsand.com. All Rights Reserved |
|||
Kommentar hinzufügen