From adc27b3177b1d5ce4a3f21a710285d0ed6887cb5 Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Sun, 6 Dec 2015 14:58:48 +0100 Subject: [PATCH] Make the app usable --- resources/public/css/screen.css | 6 ++++++ resources/templates/about.html | 4 +++- resources/templates/base.html | 22 +++++++++++++++++----- resources/templates/home.html | 13 ++++++++++--- resources/templates/parser-error.html | 10 ++++++++++ src/mailhead/parser.clj | 8 ++++++-- src/mailhead/routes/home.clj | 17 ++++++++++------- 7 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 resources/templates/parser-error.html diff --git a/resources/public/css/screen.css b/resources/public/css/screen.css index 6343efe..4eb8248 100644 --- a/resources/public/css/screen.css +++ b/resources/public/css/screen.css @@ -9,6 +9,12 @@ textarea { height: 350px !important; } +#cc-logo { + float: left; + width: 200px; + margin-right: 30px; +} + {% if cljs %} @-moz-keyframes three-quarters-loader { 0% { diff --git a/resources/templates/about.html b/resources/templates/about.html index c78972c..aac3f0d 100644 --- a/resources/templates/about.html +++ b/resources/templates/about.html @@ -1,5 +1,7 @@ {% extends "base.html" %} {% block content %} -

This is my ClojureCup 2015 entry.

+ +

ClojureCup 2015 entry

You can find me on Twitter: @fu86

+

The cource code of this application is located at GitHub: f0086/clojurecup2015-mailhead

{% endblock %} diff --git a/resources/templates/base.html b/resources/templates/base.html index 9fa9fa9..5f8bae5 100644 --- a/resources/templates/base.html +++ b/resources/templates/base.html @@ -30,12 +30,24 @@ diff --git a/resources/templates/home.html b/resources/templates/home.html index dbb1133..cd91e1a 100644 --- a/resources/templates/home.html +++ b/resources/templates/home.html @@ -2,11 +2,18 @@ {% block content %}
-

Use this form to analyze a e-mail header. Just paste the whole e-mail in raw mode here and hit the analyze button. The e-mail will be analyzed and an visual representation will be generated. Use this tool o analyze e-mail problems or to see which servers, locations and companies the e-mail passed.

+

Use this form to analyze a e-mail. Just paste the whole e-mail + in raw mode here and hit the analyze button. The e-mail + will be analyzed and an visual representation will be generated. Use this + tool to find e-mail problems or to see which servers, locations and + companies the e-mail passed. This tool is intended for debugging e-mail + communication.

+
{% csrf-field %} -
- +
+
diff --git a/resources/templates/parser-error.html b/resources/templates/parser-error.html new file mode 100644 index 0000000..d70aaa9 --- /dev/null +++ b/resources/templates/parser-error.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} + +{% block content %} +
+
+

Can't parse the given email

+
{{ mailheader }}
+
+
+{% endblock %} diff --git a/src/mailhead/parser.clj b/src/mailhead/parser.clj index 6f2e44f..6a5af8d 100644 --- a/src/mailhead/parser.clj +++ b/src/mailhead/parser.clj @@ -26,10 +26,14 @@ input-stream (ByteArrayInputStream. (.getBytes string))] (MimeMessage. props input-stream))) -(defn parse [message-string] +(defn parse-all [message-string] (->> message-string string->message - read-message + read-message)) + +(defn parse [message-string] + (->> message-string + parse-all :headers received-headers (map parse-received-headers))) diff --git a/src/mailhead/routes/home.clj b/src/mailhead/routes/home.clj index 4d94bfb..2816804 100644 --- a/src/mailhead/routes/home.clj +++ b/src/mailhead/routes/home.clj @@ -3,6 +3,7 @@ [mailhead.visualize :as v] [mailhead.parser :as parser] [compojure.core :refer [defroutes GET POST]] + [ring.util.response :refer [redirect]] [ring.util.http-response :refer [ok content-type]] [clojure.java.io :as io])) @@ -13,17 +14,19 @@ (layout/render "about.html")) (defn show-sample [index] - (let [email-content (slurp (str "/home/aaron/workbench/clojurecup2015/sample-data/header" index ".eml"))] + (let [email-content (slurp (str "/home/aaron/workbench/clojurecup2015/sample-data/example" 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 message-string - :email parsed-email - :token token}))) + (if (empty? (parser/parse message-string)) + (layout/render "parser-error.html" {:mailheader message-string}) + (let [parsed-email (parser/parse message-string) + token (v/draw parsed-email)] + (layout/render "result.html" + {:mailheader message-string + :email parsed-email + :token token})))) (defn generated-image [token] (-> (clojure.java.io/input-stream (str "generated-images/" token ".svg"))