Finish the header parsing ...
This commit is contained in:
parent
cf47794df3
commit
e7747de9cc
2 changed files with 19 additions and 9 deletions
|
@ -21,6 +21,7 @@
|
|||
[ring/ring-defaults "0.1.5"]
|
||||
[ring "1.4.0" :exclusions [ring/ring-jetty-adapter]]
|
||||
[mount "0.1.5"]
|
||||
[clj-time "0.11.0"]
|
||||
[org.immutant/web "2.1.1" :exclusions [ch.qos.logback/logback-classic]]]
|
||||
|
||||
:min-lein-version "2.0.0"
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
(ns mailhead.parser
|
||||
(:require
|
||||
[clojure.reflect :as r])
|
||||
(:require [clojure.string :as st]
|
||||
[clj-time.core :as time]
|
||||
[clj-time.coerce :as timec])
|
||||
(:use [clojure.contrib.java-utils :only [as-properties]]
|
||||
[clojure.java.io :only [input-stream file]]
|
||||
[clojure.pprint :only [print-table]])
|
||||
[clojure.java.io :only [input-stream file]])
|
||||
(:import
|
||||
(javax.mail Session)
|
||||
(javax.mail.internet MimeMessage)
|
||||
|
@ -14,12 +14,21 @@
|
|||
(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)))
|
||||
(enumeration-seq (:allHeaders (bean message))))
|
||||
|
||||
(defn )
|
||||
(defn received-headers [all-headers]
|
||||
(map #(.getValue %) (filter (fn [header] (= "Received" (.getName header))) all-headers)))
|
||||
|
||||
(defn find-from-host [received-header]
|
||||
(let [datetime (str/trim (last (st/split received-header #";")))
|
||||
;; Hacky hacky, but no time to make this proper ...
|
||||
cleaned-date (st/trim (st/replace datetime #"(\(.*\)| )" " "))]
|
||||
{:sender (nth (re-find #"\s*from ([^ ]+)" received-header) 1)
|
||||
:receiver (nth (re-find #"\s*by ([^ ]+)" received-header) 1)
|
||||
:time (timec/from-string cleaned-date)}))
|
||||
|
||||
(defn parse-received-header [header]
|
||||
((insta/parser (slurp "received-header.parser")) header))
|
||||
|
||||
(defn parse-from-string [email-string]
|
||||
(let [email-stream (java.io.ByteArrayInputStream. (.getBytes email-string))]
|
||||
|
|
Loading…
Reference in a new issue