Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A zipper for multi part mime parsing mht and mhtml files. Does not support updating
(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