diff options
Diffstat (limited to 'rfc2045.c')
-rw-r--r-- | rfc2045.c | 34 |
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; +} |