Make it work for alle received heaer fields
This commit is contained in:
parent
e7747de9cc
commit
ba34e914cc
1 changed files with 8 additions and 5 deletions
|
@ -19,7 +19,7 @@
|
||||||
(defn received-headers [all-headers]
|
(defn received-headers [all-headers]
|
||||||
(map #(.getValue %) (filter (fn [header] (= "Received" (.getName header))) all-headers)))
|
(map #(.getValue %) (filter (fn [header] (= "Received" (.getName header))) all-headers)))
|
||||||
|
|
||||||
(defn find-from-host [received-header]
|
(defn parse-received-headers [received-header]
|
||||||
(let [datetime (str/trim (last (st/split received-header #";")))
|
(let [datetime (str/trim (last (st/split received-header #";")))
|
||||||
;; Hacky hacky, but no time to make this proper ...
|
;; Hacky hacky, but no time to make this proper ...
|
||||||
cleaned-date (st/trim (st/replace datetime #"(\(.*\)| )" " "))]
|
cleaned-date (st/trim (st/replace datetime #"(\(.*\)| )" " "))]
|
||||||
|
@ -27,12 +27,15 @@
|
||||||
:receiver (nth (re-find #"\s*by ([^ ]+)" received-header) 1)
|
:receiver (nth (re-find #"\s*by ([^ ]+)" received-header) 1)
|
||||||
:time (timec/from-string cleaned-date)}))
|
:time (timec/from-string cleaned-date)}))
|
||||||
|
|
||||||
(defn parse-received-header [header]
|
(defn extract-relevant-stuff [mime-message]
|
||||||
((insta/parser (slurp "received-header.parser")) header))
|
(->> mime-message
|
||||||
|
all-headers
|
||||||
|
received-headers
|
||||||
|
(map parse-received-headers)))
|
||||||
|
|
||||||
(defn parse-from-string [email-string]
|
(defn parse-from-string [email-string]
|
||||||
(let [email-stream (java.io.ByteArrayInputStream. (.getBytes email-string))]
|
(let [email-stream (java.io.ByteArrayInputStream. (.getBytes email-string))]
|
||||||
(all-headers (MimeMessage. session email-stream))))
|
(extract-relevant-stuff (MimeMessage. session email-stream))))
|
||||||
|
|
||||||
(defn parse-from-file [filename]
|
(defn parse-from-file [filename]
|
||||||
(all-headers (MimeMessage. session (input-stream filename))))
|
(extract-relevant-stuff (MimeMessage. session (input-stream filename))))
|
||||||
|
|
Loading…
Reference in a new issue