Created
March 8, 2012 17:03
-
-
Save m0smith/2002085 to your computer and use it in GitHub Desktop.
A zipper for multi part mime parsing mht and mhtml files. Does not support updating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns gist.multipartmime-zip | |
(:require [clojure.zip :as zip]) | |
(:import [javax.mail.util ByteArrayDataSource] | |
[javax.mail.internet MimeMultipart])) | |
(defn multipart? [part] | |
(.startsWith (.getContentType part) "multipart")) | |
(defn zip-children [mime-multi-part] | |
(let [count (.getCount mime-multi-part)] | |
(for [part (map #(.getBodyPart mime-multi-part %) (range count))] | |
(if (multipart? part) | |
(.getContent part) | |
part)))) | |
(defn multi-part-mime-zipper | |
"root is a MimeMultipart instance" | |
[root] | |
(zip/zipper multipart? | |
zip-children | |
(fn [a b] nil) | |
root)) | |
(defn p-zip [file] | |
(let [ ds (ByteArrayDataSource. (slurp file) "multipart/alternative") | |
mime-part (MimeMultipart. ds)] | |
(multi-part-mime-zipper mime-part))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment