Repository: thundernest/k-9
Issue: 5.301 plain-text body rendering issues

It appears that somewhere between 5.208 and 5.301 some issues were
introduced in the rendering the body of (single-part) plain-text messages. 

For instance, a message that ends with:

     Davide

     ------------------------------------------------------------------------------
     Check out the vibrant tech community on one of the world's most
     engaging tech sites, Slashdot.org! http://sdm.link/slashdot
     _______________________________________________
     Bacula-users mailing list
     Bacula-users@lists.sourceforge.net
     https://lists.sourceforge.net/lists/listinfo/bacula-users

is displayed in 5.301 as:

     DavideCheck out the vibrant tech community on one of the world's most
     engaging tech sites, Slashdot.org! http://sdm.link/slashdotBacula-users mailing list
     Bacula-users@lists.sourceforge.net
     https://lists.sourceforge.net/lists/listinfo/bacula-users

If I forward the message from a 5.301 client the bottom text block is displayed correctly in the draft.

There additionally appears to be a problem with hyperlinking. If the "http://" or "https://"" starts in column one it is not hyperlinked. If it starts in column 2+ it is.

In 5.208 the message renders correctly and all "http://" and "https://" urls are hyperlinked regardless of their column start position.



Changed files:
k9mail/src/main/java/com/fsck/k9/message/html/HtmlSanitizer.java, k9mail/src/test/java/com/fsck/k9/message/html/HtmlSanitizerTest.java

diff --git a/k9mail/src/main/java/com/fsck/k9/message/html/HtmlSanitizer.java b/k9mail/src/main/java/com/fsck/k9/message/html/HtmlSanitizer.java
index 1b9cbf737..fc74be844 100644
--- a/k9mail/src/main/java/com/fsck/k9/message/html/HtmlSanitizer.java
+++ b/k9mail/src/main/java/com/fsck/k9/message/html/HtmlSanitizer.java
@@ -13,7 +13,7 @@ public class HtmlSanitizer {
 
     HtmlSanitizer() {
         Whitelist whitelist = Whitelist.relaxed()
-                .addTags("font")
+                .addTags("font", "hr")
                 .addAttributes("table", "align", "bgcolor", "border", "cellpadding", "cellspacing", "width")
                 .addAttributes(":all", "class", "style", "id")
                 .addProtocols("img", "src", "http", "https", "cid", "data");
diff --git a/k9mail/src/test/java/com/fsck/k9/message/html/HtmlSanitizerTest.java b/k9mail/src/test/java/com/fsck/k9/message/html/HtmlSanitizerTest.java
index 23714a4e8..f4b86c2a1 100644
--- a/k9mail/src/test/java/com/fsck/k9/message/html/HtmlSanitizerTest.java
+++ b/k9mail/src/test/java/com/fsck/k9/message/html/HtmlSanitizerTest.java
@@ -158,4 +158,13 @@ public class HtmlSanitizerTest {
                 "<tr><td>Hmailserver service shutdown:</td><td>Ok</td></tr>" +
                 "</tbody></table></body></html>", toCompactString(result));
     }
+
+    @Test
+    public void shouldKeepHrTags() throws Exception {
+        String html = "<html><head></head><body>one<hr>two<hr />three</body></html>";
+
+        Document result = htmlSanitizer.sanitize(html);
+
+        assertEquals("<html><head></head><body>one<hr>two<hr>three</body></html>", toCompactString(result));
+    }
 }