diff --git a/src/mailhead/parser.clj b/src/mailhead/parser.clj new file mode 100644 index 0000000..7baff6d --- /dev/null +++ b/src/mailhead/parser.clj @@ -0,0 +1,29 @@ +(ns mailhead.parser + (:require + [clojure.reflect :as r]) + (:use [clojure.contrib.java-utils :only [as-properties]] + [clojure.java.io :only [input-stream file]] + [clojure.pprint :only [print-table]]) + (:import + (javax.mail Session) + (javax.mail.internet MimeMessage) + (javax.mail.internet InternetHeaders))) + +(def session + (Session/getDefaultInstance + (as-properties [["mail.store.protocol" "imaps"]]))) + +(defn all-headers [message] + (let [headers (enumeration-seq (:allHeaders (bean message)))] + (map (fn [header] + (assoc {} (.getName header) (.getValue header))) + headers))) + +(defn ) + +(defn parse-from-string [email-string] + (let [email-stream (java.io.ByteArrayInputStream. (.getBytes email-string))] + (all-headers (MimeMessage. session email-stream)))) + +(defn parse-from-file [filename] + (all-headers (MimeMessage. session (input-stream filename))))