You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2016/09/05 08:02:36 UTC

[2/2] incubator-ponymail git commit: convert links to HTML inside email body

convert links to HTML inside email body

also fix the float issue


Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/80707ed3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/80707ed3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/80707ed3

Branch: refs/heads/coffee-and-cake
Commit: 80707ed344551b8abb8a6c5fdbce9e277c83ed9f
Parents: 567d7d8
Author: Daniel Gruno <hu...@apache.org>
Authored: Mon Sep 5 10:02:19 2016 +0200
Committer: Daniel Gruno <hu...@apache.org>
Committed: Mon Sep 5 10:02:19 2016 +0200

----------------------------------------------------------------------
 site/css/ponymail2.css                    |  4 +++
 site/js/coffee/email_display_basic.coffee | 43 ++++++++++++++++++++++++--
 2 files changed, 45 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/80707ed3/site/css/ponymail2.css
----------------------------------------------------------------------
diff --git a/site/css/ponymail2.css b/site/css/ponymail2.css
index 7143356..bbae155 100644
--- a/site/css/ponymail2.css
+++ b/site/css/ponymail2.css
@@ -417,4 +417,8 @@ a {
     padding-top: 0px;
     width: calc(100% - 90px);
     float: left;
+}
+
+.email_body {
+    float: left;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/80707ed3/site/js/coffee/email_display_basic.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/email_display_basic.coffee b/site/js/coffee/email_display_basic.coffee
index b6fdb4e..11bdce2 100644
--- a/site/js/coffee/email_display_basic.coffee
+++ b/site/js/coffee/email_display_basic.coffee
@@ -45,7 +45,7 @@ readEmail = (obj) ->
         ponymail_current_email = new BasicEmailDisplay(parent, mid)
         ponymail_email_open.push(ponymail_current_email)
 
-    
+### Basic email display class ###
 class BasicEmailDisplay
     constructor: (@parent, @mid) ->
         @placeholder = get("placeholder_" + @mid) || new HTML('div', { class: "email_placeholder", id: "placeholder_" + @mid})
@@ -116,10 +116,49 @@ class BasicEmailDisplay
         
         @placeholder.inject(headers)
         
+        ### Convert links to HTML ###
+        @htmlbody = @parseBody(json.body)
+        
         ### Now inject the body ###
-        b = new HTML('pre', {}, json.body)
+        b = new HTML('pre', {class: "email_body"}, @htmlbody)
         @placeholder.inject(b)
+    
+    ### parseBody: find links and HTML'ify them ###
+    parseBody: (splicer) ->
+        ### Array holding text and links ###
+        textbits = []
+        
+        ### Find the first link, if any ###
+        i = splicer.search(ponymail_url_regex)
+        urls = 0
+        
+        ### While we have more links, ... ###
+        while i != -1
+            urls++
+            ### Only parse the first 50 URLs... srsly ###
+            if urls > 50
+                break
+            ### Text preceding the link? add it to textbits frst ###
+            if i > 0
+                t = splicer.substr(0, i)
+                textbits.push(t)
+                splicer = splicer.substr(i)
+                
+            ### Find the URL and cut it out as a link ###
+            m = splicer.match(ponymail_url_regex)
+            if m
+                url = m[1]
+                i = url.length
+                t = splicer.substr(0, i)
+                textbits.push(new HTML('a', {href: url}, url))
+                splicer = splicer.substr(i)
+            ### Find the next link ###
+            i = splicer.search(ponymail_url_regex)
+        
+        ### push the remaining text into textbits ###
+        textbits.push(splicer)
         
+        return textbits
         
     hide: () ->
         @placeholder.show(false)