diff --git a/resources/public/css/screen.css b/resources/public/css/screen.css
index 549c172..cfa7788 100644
--- a/resources/public/css/screen.css
+++ b/resources/public/css/screen.css
@@ -10,9 +10,7 @@ textarea {
}
#cc-logo {
- float: left;
- width: 200px;
- margin-right: 30px;
+ width: 60px;
}
#head {
@@ -21,6 +19,12 @@ textarea {
margin-top: 20px;
}
+#graph {
+ display: inherit;
+ margin: auto;
+ margin-top: 20px;
+}
+
{% if cljs %}
@-moz-keyframes three-quarters-loader {
diff --git a/resources/templates/about.html b/resources/templates/about.html
index aac3f0d..461146e 100644
--- a/resources/templates/about.html
+++ b/resources/templates/about.html
@@ -1,7 +1,38 @@
{% extends "base.html" %}
{% block content %}
-
-
ClojureCup 2015 entry
- You can find me on Twitter: @fu86
- The cource code of this application is located at GitHub: f0086/clojurecup2015-mailhead
+
+
+
+
+
+
ClojureCup 2015 submission
+
You can find me on Twitter: @fu86
+
The sourcecode of this application is located at GitHub: f0086/clojurecup2015-mailhead
+
+ Please keep in mind that this application is written in 48 hours during a
+ programming competition. The e-mail parser is still somehow unstable,
+ complex or not wellformed headers may not work. There are some e-mail
+ parsing libraries out there, but
none of them work
+ properly. I've tried a lot, and after several hours of frustration I
+ decided to
fix
+ one lib and move on. The parser is still not very resilient and
+ malformed dates or broken "Received" header fields canot be handled
+ correct. This is an issue I am aware of, but don't had the time to write a
+ proper parser in this short amount of time.
+
+
Ideas for future versions
+
+ - Add a language flag to each server box, so the user sees exactly where
+ the e-mail crosses borders.
+ - Ping the hosts and use the IP to query
+ the ARIN REST
+ Service to display company names.
+ - Show the MTA if given
+ - Indicate servers which do spam-checks and antivirus-checks
+ - Display how much time passes between sending the e-mail from one
+ server to tne next.
+
+
+
{% endblock %}
+
diff --git a/resources/templates/base.html b/resources/templates/base.html
index 5f8bae5..2ed81b1 100644
--- a/resources/templates/base.html
+++ b/resources/templates/base.html
@@ -3,7 +3,7 @@
- Welcome to mailhead
+ mailhead -- make e-mail header visible
{% style "/assets/bootstrap/css/bootstrap.min.css" %}
@@ -30,12 +30,15 @@
diff --git a/resources/templates/home.html b/resources/templates/home.html
index ca18b79..d0ac231 100644
--- a/resources/templates/home.html
+++ b/resources/templates/home.html
@@ -5,18 +5,19 @@
-
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.
+
Use this form to analyze e-mail headers. 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. The e-mail will not be stored on the server,
+ but please don't paste sensible information here, just leave out the body
+ of the e-mail.
diff --git a/resources/templates/parser-error.html b/resources/templates/parser-error.html
index d70aaa9..d6a09aa 100644
--- a/resources/templates/parser-error.html
+++ b/resources/templates/parser-error.html
@@ -3,8 +3,14 @@
{% block content %}
-
Can't parse the given email
+ {% if mailheader %}
+
Can't parse the given e-mail header
+
Want to try some examples instead (choose from the menu above)?
{{ mailheader }}
+ {% else %}
+
Sorry, no data to analyze given.
+
Please insert a header into the form and try again.
+ {% endif %}
{% endblock %}
diff --git a/resources/templates/result.html b/resources/templates/result.html
index 16cdfa1..a585556 100644
--- a/resources/templates/result.html
+++ b/resources/templates/result.html
@@ -3,11 +3,52 @@
{% block content %}
-
Results
-
+
Result
+
The following diagram shows the different
+ servers as boxes. The arrows represent the communication between the
+ those servers. Below are some usefull details like the travel time of
+ the e-mail, software used and so on.
+
-
The analyzed email
+
+
Some interesting details about this e-mail
+
+
+
+
+ Sender |
+ {{ from }} |
+
+
+ Receiver |
+ {{ to }} |
+
+
+ Travel time |
+
+ {% if traveltime %}
+ {{ traveltime }} seconds
+ {% else %}
+ Timing is not accurate enough for measurement
+ {% endif %}
+
+ |
+
+ {% if mailer %}
+
+ Sender software |
+ {{ mailer }} |
+
+ {% endif %}
+
+
+
+
+
+
+
The analyzed e-mail header
{{ mailheader }}
diff --git a/sample-data/example1.eml b/sample-data/example1.eml
index 55c2137..2e08dfa 100644
--- a/sample-data/example1.eml
+++ b/sample-data/example1.eml
@@ -2,7 +2,7 @@ Return-Path:
X-Original-To: aaron@gridbag.net
Delivered-To: aaron@gridbag.net
Received: by remote.gridbag.net (Postfix, from userid 5001)
- id 7CCDA132244DF; Mon, 13 Apr 2015 22:09:59 +0200 (CEST)
+ id 7CCDA132244DF; Mon, 13 Apr 2015 22:09:59 +0200
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on
lvps83-169-3-141.dedicated.hosteurope.de
X-Spam-Level:
diff --git a/sample-data/example2.eml b/sample-data/example2.eml
index 0d1bab7..0ec1ffd 100644
--- a/sample-data/example2.eml
+++ b/sample-data/example2.eml
@@ -2,7 +2,7 @@ Return-Path:
X-Original-To: aaron@gridbag.net
Delivered-To: aaron@gridbag.net
Received: by remote.gridbag.net (Postfix, from userid 5001)
- id 220624E0B3B; Mon, 5 Oct 2015 11:00:57 +0200 (CEST)
+ id 220624E0B3B; Mon, 5 Oct 2015 11:00:57 +0200
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on
lvps83-169-3-141.dedicated.hosteurope.de
X-Spam-Level:
diff --git a/sample-data/example3.eml b/sample-data/example3.eml
index 8862eae..87371a3 100644
--- a/sample-data/example3.eml
+++ b/sample-data/example3.eml
@@ -2,7 +2,7 @@ Return-Path:
X-Original-To: aaron@gridbag.net
Delivered-To: aaron@gridbag.net
Received: by remote.gridbag.net (Postfix, user 5001)
- id 8BD7C132244E1; Tue, 2 Sep 2014 22:28:09 +0200 (CEST)
+ id 8BD7C132244E1; Tue, 2 Sep 2014 22:28:09 +0200
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on
lvps83-169-3-141.dedicated.hosteurope.de
X-Spam-Level:
diff --git a/src/mailhead/parser.clj b/src/mailhead/parser.clj
index 6a5af8d..a0ba061 100644
--- a/src/mailhead/parser.clj
+++ b/src/mailhead/parser.clj
@@ -9,9 +9,12 @@
[javax.mail.internet MimeMessage]
[javax.mail Session]))
-(defn received-headers [all-headers]
+(defn find-headers [all-headers needle]
(map #(first (vals %))
- (filter (fn [header] (= "Received" (first (keys header)))) all-headers)))
+ (filter (fn [header] (= needle (first (keys header)))) all-headers)))
+
+(defn received-headers [all-headers]
+ (find-headers all-headers "Received"))
(defn parse-received-headers [received-header]
(let [datetime (st/trim (last (st/split received-header #";")))
diff --git a/src/mailhead/routes/home.clj b/src/mailhead/routes/home.clj
index a925eba..8a1dcec 100644
--- a/src/mailhead/routes/home.clj
+++ b/src/mailhead/routes/home.clj
@@ -2,6 +2,7 @@
(:require [mailhead.layout :as layout]
[mailhead.visualize :as v]
[mailhead.parser :as parser]
+ [clj-time.core :as time]
[compojure.core :refer [defroutes GET POST]]
[ring.util.response :refer [redirect]]
[ring.util.http-response :refer [ok content-type]]
@@ -13,15 +14,29 @@
(defn about-page []
(layout/render "about.html"))
-;; TODO: Show more information (mail round trip time, ...)
+(defn find-header [parsed-email header]
+ (let [headers (:headers parsed-email)]
+ (first (parser/find-headers headers header))))
+
+(defn calculate-travel-time [parsed-email-headers]
+ (let [start-date (:time (first (reverse parsed-email-headers)))
+ end-date (:time (last (reverse parsed-email-headers)))]
+ (if (time/after? end-date start-date)
+ (time/in-seconds (time/interval start-date end-date))
+ nil)))
+
(defn show-result [message-string]
(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)]
+ (let [parsed-email (parser/parse-all message-string)
+ parsed-email-headers (parser/parse message-string)
+ token (v/draw parsed-email-headers)]
(layout/render "result.html"
{:mailheader message-string
- :email parsed-email
+ :from (:address (first (:from parsed-email)))
+ :to (:address (first (:to parsed-email)))
+ :mailer (find-header parsed-email "X-Mailer")
+ :traveltime (calculate-travel-time parsed-email-headers)
:token token}))))
(defn show-sample [index]