Add the samples and switch to string based parsing (no files eny more)
This commit is contained in:
parent
0786d3492a
commit
03842ae9ab
3 changed files with 30 additions and 15 deletions
|
@ -3,7 +3,11 @@
|
|||
[clj-time.core :as time]
|
||||
[clj-time.coerce :as timec]
|
||||
[clojure-mail.core :refer :all]
|
||||
[clojure-mail.message :refer :all]))
|
||||
[clojure-mail.message :refer :all])
|
||||
(:import [java.util Properties]
|
||||
[java.io ByteArrayInputStream IOException]
|
||||
[javax.mail.internet MimeMessage]
|
||||
[javax.mail Session]))
|
||||
|
||||
(defn received-headers [all-headers]
|
||||
(map #(first (vals %))
|
||||
|
@ -17,9 +21,14 @@
|
|||
:receiver (nth (re-find #"\s*by ([^ ]+)" received-header) 1)
|
||||
:time (timec/from-string cleaned-date)}))
|
||||
|
||||
(defn parse-from-file [filename]
|
||||
(->> filename
|
||||
file->message
|
||||
(defn string->message [string]
|
||||
(let [props (Session/getDefaultInstance (Properties.))
|
||||
input-stream (ByteArrayInputStream. (.getBytes string))]
|
||||
(MimeMessage. props input-stream)))
|
||||
|
||||
(defn parse [message-string]
|
||||
(->> message-string
|
||||
string->message
|
||||
read-message
|
||||
:headers
|
||||
received-headers
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(ns mailhead.routes.home
|
||||
(:require [mailhead.layout :as layout]
|
||||
[mailhead.visualize :as v]
|
||||
[mailhead.parser :as parser]
|
||||
[compojure.core :refer [defroutes GET POST]]
|
||||
[ring.util.http-response :refer [ok content-type]]
|
||||
[clojure.java.io :as io]))
|
||||
|
@ -11,11 +12,17 @@
|
|||
(defn about-page []
|
||||
(layout/render "about.html"))
|
||||
|
||||
(defn analyze-mailheader [mailheader]
|
||||
(let [token (v/draw mailheader)]
|
||||
;; TODO: Show image and other data on result.html
|
||||
(defn show-sample [index]
|
||||
(let [email-content (slurp (str "/home/aaron/workbench/clojurecup2015/sample-data/header" index ".eml"))]
|
||||
(show-result email-content)))
|
||||
|
||||
;; TODO: Show more information (mail round trip time, ...)
|
||||
(defn show-result [message-string]
|
||||
(let [parsed-email (parser/parse message-string)
|
||||
token (v/draw parsed-email)]
|
||||
(layout/render "result.html"
|
||||
{:mailheader mailheader
|
||||
{:mailheader message-string
|
||||
:email parsed-email
|
||||
:token token})))
|
||||
|
||||
(defn generated-image [token]
|
||||
|
@ -26,5 +33,6 @@
|
|||
(defroutes home-routes
|
||||
(GET "/" [] (home-page))
|
||||
(GET "/image/:token" [token] (generated-image token))
|
||||
(POST "/analyze" [mailheader] (analyze-mailheader mailheader))
|
||||
(POST "/analyze" [mailheader] (show-result mailheader))
|
||||
(GET "/example/:index" [index] (show-sample index))
|
||||
(GET "/about" [] (about-page)))
|
||||
|
|
|
@ -38,9 +38,7 @@
|
|||
(defn next-token []
|
||||
(str (java.util.UUID/randomUUID)))
|
||||
|
||||
;; TODO: Make it work with strings
|
||||
(defn draw [mailheader]
|
||||
(let [filename "/home/aaron/workbench/clojurecup2015/sample-data/header1.eml"
|
||||
token (next-token)]
|
||||
(save-image (draw-path (parser/parse-from-file filename)) token)
|
||||
(defn draw [parsed-email]
|
||||
(let [token (next-token)]
|
||||
(save-image (draw-path parsed-email) token)
|
||||
token))
|
||||
|
|
Loading…
Reference in a new issue