about summary refs log tree commit diff
path: root/unmime.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-07-13 15:53:27 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-07-13 15:53:27 +0200
commit01c1c0d9707d2ac859a77d0b95c66fbfac1c07bd (patch)
treef454de8c7aa702740222d9378178e4ae16490566 /unmime.c
parent0e892a5d833ff0552d3000dcae7a4ee1e573b679 (diff)
downloadmblaze-01c1c0d9707d2ac859a77d0b95c66fbfac1c07bd.tar.gz
mblaze-01c1c0d9707d2ac859a77d0b95c66fbfac1c07bd.tar.xz
mblaze-01c1c0d9707d2ac859a77d0b95c66fbfac1c07bd.zip
add rfc2045 and multipart decoding
Diffstat (limited to 'unmime.c')
-rw-r--r--unmime.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/unmime.c b/unmime.c
new file mode 100644
index 0000000..68ee514
--- /dev/null
+++ b/unmime.c
@@ -0,0 +1,61 @@
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <wchar.h>
+
+#include "blaze822.h"
+
+void
+recmime(struct message *msg, int depth)
+{
+	struct message *imsg = 0;
+	char *ct, *body;
+	size_t bodylen;
+
+	if (blaze822_mime_body(msg, &ct, &body, &bodylen)) {
+		printf("%*.sbody %s len %d\n", depth*2, "", ct, bodylen);
+		if (strncmp(ct, "multipart/", 10) == 0)
+			while (blaze822_multipart(msg, &imsg))
+				recmime(imsg, depth+1);
+		else if (strncmp(ct, "text/", 5) == 0) {
+			printf("---\n");
+			fwrite(body, bodylen, 1, stdout);
+			printf("---\n");
+		}
+	}
+}
+
+void
+unmime(char *file)
+{
+	struct message *msg;
+
+	msg = blaze822_file(file);
+	if (!msg)
+		return;
+
+	if (blaze822_check_mime(msg))
+		printf("a mime message\n");
+	else
+		return;
+
+	recmime(msg, 0);
+}
+
+int
+main(int argc, char *argv[])
+{
+	blaze822_loop(argc-1, argv+1, unmime);
+
+	return 0;
+}