From 27b21d7e204cfa17723702d3c04c0ee6df603fbf Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Tue, 2 Aug 2016 16:13:25 +0200 Subject: rfc2045: import walk_mime --- rfc2045.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'rfc2045.c') diff --git a/rfc2045.c b/rfc2045.c index d225c73..14e222a 100644 --- a/rfc2045.c +++ b/rfc2045.c @@ -2,6 +2,7 @@ #include #include +#include #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; +} -- cgit 1.4.1