about summary refs log tree commit diff
path: root/rfc2045.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-08-02 16:13:25 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-08-02 16:13:25 +0200
commit27b21d7e204cfa17723702d3c04c0ee6df603fbf (patch)
treed5bd50d721c2eabde8ec7f09fb40d59cdb9f3105 /rfc2045.c
parent56e89c9a557cd1182001a8b1130d7f10f40cc96a (diff)
downloadmblaze-27b21d7e204cfa17723702d3c04c0ee6df603fbf.tar.gz
mblaze-27b21d7e204cfa17723702d3c04c0ee6df603fbf.tar.xz
mblaze-27b21d7e204cfa17723702d3c04c0ee6df603fbf.zip
rfc2045: import walk_mime
Diffstat (limited to 'rfc2045.c')
-rw-r--r--rfc2045.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/rfc2045.c b/rfc2045.c
index d225c73..14e222a 100644
--- a/rfc2045.c
+++ b/rfc2045.c
@@ -2,6 +2,7 @@
 
 #include <strings.h>
 #include <string.h>
+#include <stdlib.h>
 
 #include "blaze822.h"
 #include "blaze822_priv.h"
@@ -165,3 +166,36 @@ blaze822_multipart(struct message *msg, struct message **imsg)
 
 	return 1;
 }
+
+blaze822_mime_action
+blaze822_walk_mime(struct message *msg, int depth, blaze822_mime_callback visit)
+{
+	char *ct, *body, *bodychunk;
+	size_t bodylen;
+
+	blaze822_mime_action r = MIME_CONTINUE;
+
+	if (blaze822_mime_body(msg, &ct, &body, &bodylen, &bodychunk)) {
+
+		r = visit(depth, msg, body, bodylen);
+
+		if (r == MIME_CONTINUE) {
+			if (strncmp(ct, "multipart/", 10) == 0) {
+				struct message *imsg = 0;
+				while (blaze822_multipart(msg, &imsg)) {
+					r = blaze822_walk_mime(imsg, depth+1, visit);
+					if (r == MIME_STOP)
+						break;
+				}
+			} else if (strncmp(ct, "message/rfc822", 14) == 0) {
+				struct message *imsg = blaze822_mem(body, bodylen);
+				if (imsg)
+					blaze822_walk_mime(imsg, depth+1, visit);
+			}
+		}
+
+		free(bodychunk);
+	}
+
+	return r;
+}