Start with the email parser
This commit is contained in:
parent
edbc2d432d
commit
cf47794df3
1 changed files with 29 additions and 0 deletions
29
src/mailhead/parser.clj
Normal file
29
src/mailhead/parser.clj
Normal file
|
@ -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))))
|
Loading…
Reference in a new issue