From 28212bc04f76d9045a4eb2251acc7a6f4b4184b6 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Wed, 27 Feb 2013 16:04:02 -0500 Subject: [PATCH 1/7] Issue 4019 -- Fix inability to zoom out. Thanks to davidgca...@gmail.com for references in his comments 80 & 81. --- src/com/fsck/k9/view/MessageWebView.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/fsck/k9/view/MessageWebView.java b/src/com/fsck/k9/view/MessageWebView.java index 26215646a..6ca802b7f 100644 --- a/src/com/fsck/k9/view/MessageWebView.java +++ b/src/com/fsck/k9/view/MessageWebView.java @@ -106,6 +106,7 @@ public class MessageWebView extends TitleBarWebView { webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true); + webSettings.setUseWideViewPort(true); disableDisplayZoomControls(); From 731022339d8961ad74634b5cab9c2c0f21a41c94 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Fri, 1 Mar 2013 12:55:51 -0500 Subject: [PATCH 2/7] Improve MessageWebView display. Now that MessageWebView has 'setUseWideViewPort(true)', the wide view port is excessively wide. It turns out Android is using a fixed width of 980 px, so that even plain text messages (which are already wrapped to fit the screen) have a large empty area beside them when scrolled to the left. Injecting a meta tag in the html header fixes the problem. --- src/com/fsck/k9/helper/HtmlConverter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/com/fsck/k9/helper/HtmlConverter.java b/src/com/fsck/k9/helper/HtmlConverter.java index 54eb34faf..3c6f3c2ed 100644 --- a/src/com/fsck/k9/helper/HtmlConverter.java +++ b/src/com/fsck/k9/helper/HtmlConverter.java @@ -127,7 +127,8 @@ public class HtmlConverter { private static final int MAX_SMART_HTMLIFY_MESSAGE_LENGTH = 1024 * 256 ; public static final String getHtmlHeader() { - return ""; + // Include a meta tag so the MessageWebView will not use a fixed viewport width of 980 px + return ""; } public static final String getHtmlFooter() { From e2c5229e854e2ef62585f919a15660cba2489b04 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Fri, 1 Mar 2013 12:59:59 -0500 Subject: [PATCH 3/7] Change when tags are applied to messages. Previously, , , & tags were attached to messages before they were stored locally. But now that the element also needs to include a element (for proper MessageWebView display), it seems unecesary to store all these tags with each message. Now the tags are no longer stored with the messages. Instead, MessageWebView applies the tags before displaying the message. This also eliminates the need to upgrade an older message database where all the old messages would have otherwise needed to be wrapped with the new tags. --- src/com/fsck/k9/activity/MessageCompose.java | 2 +- src/com/fsck/k9/mail/internet/MimeUtility.java | 3 --- src/com/fsck/k9/view/MessageWebView.java | 11 +++++------ src/com/fsck/k9/view/SingleMessageView.java | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 0c1c60dd3..af92695fa 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -3047,7 +3047,7 @@ public class MessageCompose extends K9Activity implements OnClickListener { if (part != null) { if (K9.DEBUG) Log.d(K9.LOG_TAG, "getBodyTextFromMessage: HTML requested, text found."); - return HtmlConverter.textToHtml(MimeUtility.getTextFromPart(part), true); + return HtmlConverter.textToHtml(MimeUtility.getTextFromPart(part), false); } } else if (format == SimpleMessageFormat.TEXT) { // Text takes precedence, then html. diff --git a/src/com/fsck/k9/mail/internet/MimeUtility.java b/src/com/fsck/k9/mail/internet/MimeUtility.java index fcdb2e3ce..4fea487be 100644 --- a/src/com/fsck/k9/mail/internet/MimeUtility.java +++ b/src/com/fsck/k9/mail/internet/MimeUtility.java @@ -1376,7 +1376,6 @@ public class MimeUtility { StringBuilder text = new StringBuilder(); StringBuilder html = new StringBuilder(); - html.append(HtmlConverter.getHtmlHeader()); for (Viewable viewable : viewables) { if (viewable instanceof Textual) { @@ -1428,8 +1427,6 @@ public class MimeUtility { } } - html.append(HtmlConverter.getHtmlFooter()); - return new ViewableContainer(text.toString(), html.toString(), attachments); } catch (Exception e) { throw new MessagingException("Couldn't extract viewable parts", e); diff --git a/src/com/fsck/k9/view/MessageWebView.java b/src/com/fsck/k9/view/MessageWebView.java index 6ca802b7f..394c0aa9e 100644 --- a/src/com/fsck/k9/view/MessageWebView.java +++ b/src/com/fsck/k9/view/MessageWebView.java @@ -152,15 +152,14 @@ public class MessageWebView extends TitleBarWebView { } public void setText(String text, String contentType) { - String content = text; + String content = ""; if (K9.getK9MessageViewTheme() == K9.Theme.DARK) { - // It's a little wrong to just throw in the " - + content; + ":visited, :visited * { color: #551A8B !important } "; } + content += "" + text + ""; loadDataWithBaseURL("http://", content, contentType, "utf-8", null); } diff --git a/src/com/fsck/k9/view/SingleMessageView.java b/src/com/fsck/k9/view/SingleMessageView.java index dd13fcde6..ae0534f10 100644 --- a/src/com/fsck/k9/view/SingleMessageView.java +++ b/src/com/fsck/k9/view/SingleMessageView.java @@ -551,7 +551,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener, if (pgpData != null) { text = pgpData.getDecryptedData(); if (text != null) { - text = HtmlConverter.textToHtml(text, true); + text = HtmlConverter.textToHtml(text, false); } } From 6a844a255349ca2d7b94454516c469e3579d5199 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Fri, 1 Mar 2013 07:13:48 -0500 Subject: [PATCH 4/7] Remove unused code in HtmlConverter. HtmlConverter.getHtmlHeader() and getHtmlFooter() are no longer used. Remove them and other related code. --- src/com/fsck/k9/activity/MessageCompose.java | 2 +- src/com/fsck/k9/helper/HtmlConverter.java | 52 +++++-------------- .../fsck/k9/mail/internet/MimeUtility.java | 6 +-- src/com/fsck/k9/view/SingleMessageView.java | 2 +- 4 files changed, 18 insertions(+), 44 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index af92695fa..b2fb4e3f9 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -3047,7 +3047,7 @@ public class MessageCompose extends K9Activity implements OnClickListener { if (part != null) { if (K9.DEBUG) Log.d(K9.LOG_TAG, "getBodyTextFromMessage: HTML requested, text found."); - return HtmlConverter.textToHtml(MimeUtility.getTextFromPart(part), false); + return HtmlConverter.textToHtml(MimeUtility.getTextFromPart(part)); } } else if (format == SimpleMessageFormat.TEXT) { // Text takes precedence, then html. diff --git a/src/com/fsck/k9/helper/HtmlConverter.java b/src/com/fsck/k9/helper/HtmlConverter.java index 3c6f3c2ed..5478f2e25 100644 --- a/src/com/fsck/k9/helper/HtmlConverter.java +++ b/src/com/fsck/k9/helper/HtmlConverter.java @@ -126,41 +126,27 @@ public class HtmlConverter { private static final int MAX_SMART_HTMLIFY_MESSAGE_LENGTH = 1024 * 256 ; - public static final String getHtmlHeader() { - // Include a meta tag so the MessageWebView will not use a fixed viewport width of 980 px - return ""; - } - - public static final String getHtmlFooter() { - return ""; - } - /** * Naively convert a text string into an HTML document. * *

* This method avoids using regular expressions on the entire message body to save memory. *

+ *

+ * No HTML headers or footers are added to the result. + *

* * @param text * Plain text string. - * @param useHtmlTag - * If {@code true} this method adds headers and footers to create a proper HTML - * document. - * * @return HTML string. */ - private static String simpleTextToHtml(String text, boolean useHtmlTag) { + private static String simpleTextToHtml(String text) { // Encode HTML entities to make sure we don't display something evil. text = TextUtils.htmlEncode(text); StringReader reader = new StringReader(text); StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); - if (useHtmlTag) { - buff.append(getHtmlHeader()); - } - buff.append(htmlifyMessageHeader()); int c; @@ -185,10 +171,6 @@ public class HtmlConverter { buff.append(htmlifyMessageFooter()); - if (useHtmlTag) { - buff.append(getHtmlFooter()); - } - return buff.toString(); } @@ -202,26 +184,26 @@ public class HtmlConverter { * Convert a text string into an HTML document. * *

- * Attempts to do smart replacement for large documents to prevent OOM errors. This method - * optionally adds headers and footers to create a proper HTML document. To convert to a - * fragment, use {@link #textToHtmlFragment(String)}. + * Attempts to do smart replacement for large documents to prevent OOM + * errors. + *

+ * No HTML headers or footers are added to the result. + *

+ *

+ * To convert to a fragment, use {@link #textToHtmlFragment(String)} . *

* * @param text * Plain text string. - * @param useHtmlTag - * If {@code true} this method adds headers and footers to create a proper HTML - * document. - * * @return HTML string. */ - public static String textToHtml(String text, boolean useHtmlTag) { + public static String textToHtml(String text) { // Our HTMLification code is somewhat memory intensive // and was causing lots of OOM errors on the market // if the message is big and plain text, just do // a trivial htmlification if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { - return simpleTextToHtml(text, useHtmlTag); + return simpleTextToHtml(text); } StringReader reader = new StringReader(text); StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); @@ -313,18 +295,10 @@ public class HtmlConverter { StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); - if (useHtmlTag) { - sb.append(getHtmlHeader()); - } - sb.append(htmlifyMessageHeader()); linkifyText(text, sb); sb.append(htmlifyMessageFooter()); - if (useHtmlTag) { - sb.append(getHtmlFooter()); - } - text = sb.toString(); // Above we replaced > with , now make it > diff --git a/src/com/fsck/k9/mail/internet/MimeUtility.java b/src/com/fsck/k9/mail/internet/MimeUtility.java index 4fea487be..efece2af5 100644 --- a/src/com/fsck/k9/mail/internet/MimeUtility.java +++ b/src/com/fsck/k9/mail/internet/MimeUtility.java @@ -1920,7 +1920,7 @@ public class MimeUtility { * Use the contents of a {@link Viewable} to create the HTML to be displayed. * *

- * This will use {@link HtmlConverter#textToHtml(String, boolean)} to convert plain text parts + * This will use {@link HtmlConverter#textToHtml(String)} to convert plain text parts * to HTML if necessary. *

* @@ -1943,7 +1943,7 @@ public class MimeUtility { if (t == null) { t = ""; } else if (viewable instanceof Text) { - t = HtmlConverter.textToHtml(t, false); + t = HtmlConverter.textToHtml(t); } html.append(t); } else if (viewable instanceof Alternative) { @@ -3352,7 +3352,7 @@ public class MimeUtility { String bodyText = getTextFromPart(part); if (bodyText != null) { text = fixDraftTextBody(bodyText); - html = HtmlConverter.textToHtml(text, false); + html = HtmlConverter.textToHtml(text); } } else if (part.isMimeType("multipart/alternative") && firstBody instanceof MimeMultipart) { diff --git a/src/com/fsck/k9/view/SingleMessageView.java b/src/com/fsck/k9/view/SingleMessageView.java index ae0534f10..40b6ba68c 100644 --- a/src/com/fsck/k9/view/SingleMessageView.java +++ b/src/com/fsck/k9/view/SingleMessageView.java @@ -551,7 +551,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener, if (pgpData != null) { text = pgpData.getDecryptedData(); if (text != null) { - text = HtmlConverter.textToHtml(text, false); + text = HtmlConverter.textToHtml(text); } } From 548b8e07a6f8ae10246914952712b2565fdde6c7 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Fri, 1 Mar 2013 11:26:52 -0500 Subject: [PATCH 5/7] Refactor code for MessageWebView.setText() The MIME type for the supplied text was always text/html, so there is no need to pass that as a parameter. Furthermore, we are relying on it being text/html because we are wrapping it with HTML code. Likewise, change/simplify/rename AccessibleWebView.loadDataWithBaseURL(). --- src/com/fsck/k9/activity/MessageCompose.java | 6 +++--- src/com/fsck/k9/helper/HtmlConverter.java | 8 ++++++-- src/com/fsck/k9/view/AccessibleWebView.java | 6 ++---- src/com/fsck/k9/view/MessageWebView.java | 16 ++++++++++++++-- src/com/fsck/k9/view/SingleMessageView.java | 14 +++++++------- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index b2fb4e3f9..f592ff03a 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -1126,7 +1126,7 @@ public class MessageCompose extends K9Activity implements OnClickListener { mQuotedHtmlContent = (InsertableHtmlContent) savedInstanceState.getSerializable(STATE_KEY_HTML_QUOTE); if (mQuotedHtmlContent != null && mQuotedHtmlContent.getQuotedContent() != null) { - mQuotedHTML.setText(mQuotedHtmlContent.getQuotedContent(), "text/html"); + mQuotedHTML.setText(mQuotedHtmlContent.getQuotedContent()); } mDraftId = savedInstanceState.getLong(STATE_KEY_DRAFT_ID); @@ -2815,7 +2815,7 @@ public class MessageCompose extends K9Activity implements OnClickListener { } else { mQuotedHtmlContent.setFooterInsertionPoint(bodyOffset); } - mQuotedHTML.setText(mQuotedHtmlContent.getQuotedContent(), "text/html"); + mQuotedHTML.setText(mQuotedHtmlContent.getQuotedContent()); } } if (bodyPlainOffset != null && bodyPlainLength != null) { @@ -2999,7 +2999,7 @@ public class MessageCompose extends K9Activity implements OnClickListener { mQuotedHtmlContent = quoteOriginalHtmlMessage(mSourceMessage, content, mQuoteStyle); // Load the message with the reply header. - mQuotedHTML.setText(mQuotedHtmlContent.getQuotedContent(), "text/html"); + mQuotedHTML.setText(mQuotedHtmlContent.getQuotedContent()); // TODO: Also strip the signature from the text/plain part mQuotedText.setText(quoteOriginalTextMessage(mSourceMessage, diff --git a/src/com/fsck/k9/helper/HtmlConverter.java b/src/com/fsck/k9/helper/HtmlConverter.java index 5478f2e25..e5ab099bd 100644 --- a/src/com/fsck/k9/helper/HtmlConverter.java +++ b/src/com/fsck/k9/helper/HtmlConverter.java @@ -133,7 +133,9 @@ public class HtmlConverter { * This method avoids using regular expressions on the entire message body to save memory. *

*

- * No HTML headers or footers are added to the result. + * No HTML headers or footers are added to the result. Headers and footers + * are added at display time in + * {@link com.fsck.k9.view#MessageWebView.setText(String) MessageWebView.setText()} *

* * @param text @@ -187,7 +189,9 @@ public class HtmlConverter { * Attempts to do smart replacement for large documents to prevent OOM * errors. *

- * No HTML headers or footers are added to the result. + * No HTML headers or footers are added to the result. Headers and footers + * are added at display time in + * {@link com.fsck.k9.view#MessageWebView.setText(String) MessageWebView.setText()} *

*

* To convert to a fragment, use {@link #textToHtmlFragment(String)} . diff --git a/src/com/fsck/k9/view/AccessibleWebView.java b/src/com/fsck/k9/view/AccessibleWebView.java index 5dd8bb9a8..323833d26 100644 --- a/src/com/fsck/k9/view/AccessibleWebView.java +++ b/src/com/fsck/k9/view/AccessibleWebView.java @@ -68,10 +68,8 @@ public class AccessibleWebView extends TextView { return mDummyWebView.getSettings(); } - public void loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, - String historyUrl) { - mHtmlSource = data; - this.setText(Html.fromHtml(mHtmlSource, null, null)); + public void setText(String text) { + this.setText(Html.fromHtml(text, null, null)); // Let everyone know that loading has finished. if (mListeners != null) { diff --git a/src/com/fsck/k9/view/MessageWebView.java b/src/com/fsck/k9/view/MessageWebView.java index 394c0aa9e..e673f4134 100644 --- a/src/com/fsck/k9/view/MessageWebView.java +++ b/src/com/fsck/k9/view/MessageWebView.java @@ -151,7 +151,19 @@ public class MessageWebView extends TitleBarWebView { } } - public void setText(String text, String contentType) { + /** + * Load a message body into a {@code MessageWebView} + * + *

+ * Before loading, the text is wrapped in an HTML header and footer + * so that it displays properly. + *

+ * + * @param text + * The message body to display. Assumed to be MIME type text/html. + */ + public void setText(String text) { + // Include a meta tag so the WebView will not use a fixed viewport width of 980 px String content = ""; if (K9.getK9MessageViewTheme() == K9.Theme.DARK) { content += " "; } content += "" + text + ""; - loadDataWithBaseURL("http://", content, contentType, "utf-8", null); + loadDataWithBaseURL("http://", content, "text/html", "utf-8", null); } /* diff --git a/src/com/fsck/k9/view/SingleMessageView.java b/src/com/fsck/k9/view/SingleMessageView.java index 40b6ba68c..b9b982422 100644 --- a/src/com/fsck/k9/view/SingleMessageView.java +++ b/src/com/fsck/k9/view/SingleMessageView.java @@ -400,7 +400,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener, // Allow network access first... setLoadPictures(true); // ...then re-populate the WebView with the message text - loadBodyFromText(mText, "text/html"); + loadBodyFromText(mText); break; } } @@ -611,7 +611,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener, } if (text != null) { - loadBodyFromText(text, "text/html"); + loadBodyFromText(text); updateCryptoLayout(account.getCryptoProvider(), pgpData, message); } else { showStatusMessage(getContext().getString(R.string.webview_empty_message)); @@ -622,15 +622,15 @@ public class SingleMessageView extends LinearLayout implements OnClickListener, String text = "
" + status + "
"; - loadBodyFromText(text, "text/html"); + loadBodyFromText(text); mCryptoView.hide(); } - private void loadBodyFromText(String emailText, String contentType) { + private void loadBodyFromText(String emailText) { if (mScreenReaderEnabled) { - mAccessibleMessageContentView.loadDataWithBaseURL("http://", emailText, contentType, "utf-8", null); + mAccessibleMessageContentView.setText(emailText); } else { - mMessageContentView.setText(emailText, contentType); + mMessageContentView.setText(emailText); } } @@ -734,7 +734,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener, * its size because the button to download the complete message was previously shown and * is now hidden. */ - loadBodyFromText("", "text/plain"); + loadBodyFromText(""); } public void resetHeaderView() { From c21ea14af185d725d819e8dfb1cb52ff39c72e46 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Fri, 1 Mar 2013 12:30:25 -0500 Subject: [PATCH 6/7] Fix unit tests. --- .../com/fsck/k9/helper/HtmlConverterTest.java | 6 +++--- .../com/fsck/k9/mail/internet/ViewablesTest.java | 16 ++++------------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/tests/src/com/fsck/k9/helper/HtmlConverterTest.java b/tests/src/com/fsck/k9/helper/HtmlConverterTest.java index a930fc94b..36deacd06 100644 --- a/tests/src/com/fsck/k9/helper/HtmlConverterTest.java +++ b/tests/src/com/fsck/k9/helper/HtmlConverterTest.java @@ -23,7 +23,7 @@ public class HtmlConverterTest extends TestCase { "\n" + "Nice job :)\n" + ">> Guess!"; - String result = HtmlConverter.textToHtml(message, false); + String result = HtmlConverter.textToHtml(message); writeToFile(result); assertEquals("
Panama!

Bob Barker <bob@aol.com> wrote:
a canal

Dorothy Jo Gideon <dorothy@aol.com> espoused:
A man, a plan...
Too easy!

Nice job :)
Guess!
", result); } @@ -37,7 +37,7 @@ public class HtmlConverterTest extends TestCase { "> LOL F1RST!!!!!\n" + ">\n" + "> :)"; - String result = HtmlConverter.textToHtml(message, false); + String result = HtmlConverter.textToHtml(message); writeToFile(result); assertEquals("
*facepalm*

Bob Barker <bob@aol.com> wrote:
A wise man once said...

LOL F1RST!!!!!

:)
", result); } @@ -60,7 +60,7 @@ public class HtmlConverterTest extends TestCase { ">>>> four\n" + ">>>>> five\n" + ">>>>>> six"; - String result = HtmlConverter.textToHtml(message, false); + String result = HtmlConverter.textToHtml(message); writeToFile(result); assertEquals("
zero
one
two
three
four
five
six
", result); } diff --git a/tests/src/com/fsck/k9/mail/internet/ViewablesTest.java b/tests/src/com/fsck/k9/mail/internet/ViewablesTest.java index 4aae4531f..e0ed3125f 100644 --- a/tests/src/com/fsck/k9/mail/internet/ViewablesTest.java +++ b/tests/src/com/fsck/k9/mail/internet/ViewablesTest.java @@ -29,12 +29,10 @@ public class ViewablesTest extends AndroidTestCase { String expectedText = bodyText; String expectedHtml = - "" + "
" +
                 "K-9 Mail rocks :>" +
-                "
" + - ""; + ""; assertEquals(expectedText, container.text); assertEquals(expectedHtml, container.html); @@ -56,9 +54,7 @@ public class ViewablesTest extends AndroidTestCase { String expectedText = "K-9 Mail rocks :>"; String expectedHtml = - "" + - bodyText + - ""; + bodyText; assertEquals(expectedText, container.text); assertEquals(expectedHtml, container.html); @@ -91,7 +87,6 @@ public class ViewablesTest extends AndroidTestCase { "------------------------------------------------------------------------\n\n" + bodyText2; String expectedHtml = - "" + "
" +
                 bodyText1 +
@@ -101,8 +96,7 @@ public class ViewablesTest extends AndroidTestCase {
                 "
" +
                 bodyText2 +
-                "
" + - ""; + "
"; assertEquals(expectedText, container.text); @@ -158,7 +152,6 @@ public class ViewablesTest extends AndroidTestCase { "\n" + innerBodyText; String expectedHtml = - "" + "
" +
                 bodyText +
@@ -183,8 +176,7 @@ public class ViewablesTest extends AndroidTestCase {
                 "
" +
                 innerBodyText +
-                "
" + - ""; + "
"; assertEquals(expectedText, container.text); assertEquals(expectedHtml, container.html); From c790fa73c189a2724c56594384a7bc5dbe5c78b0 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Fri, 1 Mar 2013 18:48:46 -0500 Subject: [PATCH 7/7] Don't store the font-family preference with plain text messages. Dynamically generate the CSS style for
 elements
for inclusion in the HTML  element when messages
are displayed.

This permits a user to change their font-family preference
for plain text messages and see the results immediately.

Obviously any old locally-stored messages that had their
font-family stored with them will continue to display using
that font-family, irrespective of the user's current
preference setting.
---
 src/com/fsck/k9/helper/HtmlConverter.java     | 27 ++++++++++++++++---
 src/com/fsck/k9/view/MessageWebView.java      |  3 +++
 .../com/fsck/k9/helper/HtmlConverterTest.java |  6 ++---
 .../fsck/k9/mail/internet/ViewablesTest.java  | 15 ++++-------
 4 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/src/com/fsck/k9/helper/HtmlConverter.java b/src/com/fsck/k9/helper/HtmlConverter.java
index e5ab099bd..42382d206 100644
--- a/src/com/fsck/k9/helper/HtmlConverter.java
+++ b/src/com/fsck/k9/helper/HtmlConverter.java
@@ -317,6 +317,7 @@ public class HtmlConverter {
     protected static final String QUOTE_COLOR_LEVEL_3 = "#8ae234";
     protected static final String QUOTE_COLOR_LEVEL_4 = "#fcaf3e";
     protected static final String QUOTE_COLOR_LEVEL_5 = "#e9b96e";
+    private static final String K9MAIL_CSS_CLASS = "k9mail";
 
     /**
      * Return an HTML hex color string for a given quote level.
@@ -1230,16 +1231,34 @@ public class HtmlConverter {
     }
 
     private static String htmlifyMessageHeader() {
-        final String font = K9.messageViewFixedWidthFont()
-                            ? "monospace"
-                            : "sans-serif";
-        return "
";
+        return "
";
     }
 
     private static String htmlifyMessageFooter() {
         return "
"; } + /** + * Dynamically generate a CSS style for {@code
} elements.
+     *
+     *  

+ * The style incorporates the user's current preference + * setting for the font family used for plain text messages. + *

+ * + * @return + * A {@code "; + } + /** * Convert a plain text string into an HTML fragment. * @param text Plain text. diff --git a/src/com/fsck/k9/view/MessageWebView.java b/src/com/fsck/k9/view/MessageWebView.java index e673f4134..a70a1c3e1 100644 --- a/src/com/fsck/k9/view/MessageWebView.java +++ b/src/com/fsck/k9/view/MessageWebView.java @@ -11,6 +11,8 @@ import android.webkit.WebSettings; import android.widget.Toast; import com.fsck.k9.K9; import com.fsck.k9.R; +import com.fsck.k9.helper.HtmlConverter; + import java.lang.reflect.Method; import com.nobu_games.android.view.web.TitleBarWebView; @@ -171,6 +173,7 @@ public class MessageWebView extends TitleBarWebView { ":link, :link * { color: #CCFF33 !important }" + ":visited, :visited * { color: #551A8B !important } "; } + content += HtmlConverter.cssStylePre(); content += "" + text + ""; loadDataWithBaseURL("http://", content, "text/html", "utf-8", null); } diff --git a/tests/src/com/fsck/k9/helper/HtmlConverterTest.java b/tests/src/com/fsck/k9/helper/HtmlConverterTest.java index 36deacd06..1b24da791 100644 --- a/tests/src/com/fsck/k9/helper/HtmlConverterTest.java +++ b/tests/src/com/fsck/k9/helper/HtmlConverterTest.java @@ -25,7 +25,7 @@ public class HtmlConverterTest extends TestCase { ">> Guess!"; String result = HtmlConverter.textToHtml(message); writeToFile(result); - assertEquals("
Panama!

Bob Barker <bob@aol.com> wrote:
a canal

Dorothy Jo Gideon <dorothy@aol.com> espoused:
A man, a plan...
Too easy!

Nice job :)
Guess!
", result); + assertEquals("
Panama!

Bob Barker <bob@aol.com> wrote:
a canal

Dorothy Jo Gideon <dorothy@aol.com> espoused:
A man, a plan...
Too easy!

Nice job :)
Guess!
", result); } public void testTextQuoteToHtmlBlockquoteIndented() { @@ -39,7 +39,7 @@ public class HtmlConverterTest extends TestCase { "> :)"; String result = HtmlConverter.textToHtml(message); writeToFile(result); - assertEquals("
*facepalm*

Bob Barker <bob@aol.com> wrote:
A wise man once said...

LOL F1RST!!!!!

:)
", result); + assertEquals("
*facepalm*

Bob Barker <bob@aol.com> wrote:
A wise man once said...

LOL F1RST!!!!!

:)
", result); } public void testQuoteDepthColor() { @@ -62,7 +62,7 @@ public class HtmlConverterTest extends TestCase { ">>>>>> six"; String result = HtmlConverter.textToHtml(message); writeToFile(result); - assertEquals("
zero
one
two
three
four
five
six
", result); + assertEquals("
zero
one
two
three
four
five
six
", result); } private void writeToFile(final String content) { diff --git a/tests/src/com/fsck/k9/mail/internet/ViewablesTest.java b/tests/src/com/fsck/k9/mail/internet/ViewablesTest.java index e0ed3125f..b99340e0c 100644 --- a/tests/src/com/fsck/k9/mail/internet/ViewablesTest.java +++ b/tests/src/com/fsck/k9/mail/internet/ViewablesTest.java @@ -29,8 +29,7 @@ public class ViewablesTest extends AndroidTestCase { String expectedText = bodyText; String expectedHtml = - "
" +
+                "
" +
                 "K-9 Mail rocks :>" +
                 "
"; @@ -87,14 +86,12 @@ public class ViewablesTest extends AndroidTestCase { "------------------------------------------------------------------------\n\n" + bodyText2; String expectedHtml = - "
" +
+                "
" +
                 bodyText1 +
                 "
" + "

" + - "
" +
+                "
" +
                 bodyText2 +
                 "
"; @@ -152,8 +149,7 @@ public class ViewablesTest extends AndroidTestCase { "\n" + innerBodyText; String expectedHtml = - "
" +
+                "
" +
                 bodyText +
                 "
" + "

Subject" + "" + "" + - "

" +
+                "
" +
                 innerBodyText +
                 "
";