1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 09:52:16 -05:00

Merge pull request #719 from dougsparling/master

Don't use StringReader in HtmlConverter as calls to read have unneces…
This commit is contained in:
Jan Berkel 2015-07-24 11:23:31 +01:00
commit 8de2ec7f27

View File

@ -2,13 +2,10 @@ package com.fsck.k9.helper;
import android.text.*; import android.text.*;
import android.text.Html.TagHandler; import android.text.Html.TagHandler;
import android.util.Log;
import com.fsck.k9.K9; import com.fsck.k9.K9;
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
@ -211,14 +208,12 @@ public class HtmlConverter {
// Encode HTML entities to make sure we don't display something evil. // Encode HTML entities to make sure we don't display something evil.
text = TextUtils.htmlEncode(text); text = TextUtils.htmlEncode(text);
StringReader reader = new StringReader(text);
StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH);
buff.append(htmlifyMessageHeader()); buff.append(htmlifyMessageHeader());
int c; for (int index = 0; index < text.length(); index++) {
try { char c = text.charAt(index);
while ((c = reader.read()) != -1) {
switch (c) { switch (c) {
case '\n': case '\n':
// pine treats <br> as two newlines, but <br/> as one newline. Use <br/> so our messages aren't // pine treats <br> as two newlines, but <br/> as one newline. Use <br/> so our messages aren't
@ -228,13 +223,9 @@ public class HtmlConverter {
case '\r': case '\r':
break; break;
default: default:
buff.append((char)c); buff.append(c);
}//switch }//switch
} }
} catch (IOException e) {
//Should never happen
Log.e(K9.LOG_TAG, "Could not read string to convert text to HTML:", e);
}
buff.append(htmlifyMessageFooter()); buff.append(htmlifyMessageFooter());
@ -274,15 +265,13 @@ public class HtmlConverter {
if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) {
return simpleTextToHtml(text); return simpleTextToHtml(text);
} }
StringReader reader = new StringReader(text);
StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH);
boolean isStartOfLine = true; // Are we currently at the start of a line? boolean isStartOfLine = true; // Are we currently at the start of a line?
int spaces = 0; int spaces = 0;
int quoteDepth = 0; // Number of DIVs deep we are. int quoteDepth = 0; // Number of DIVs deep we are.
int quotesThisLine = 0; // How deep we should be quoting for this line. int quotesThisLine = 0; // How deep we should be quoting for this line.
try { for (int index = 0; index < text.length(); index++) {
int c; char c = text.charAt(index);
while ((c = reader.read()) != -1) {
if (isStartOfLine) { if (isStartOfLine) {
switch (c) { switch (c) {
case ' ': case ' ':
@ -325,10 +314,6 @@ public class HtmlConverter {
} }
} }
} }
} catch (IOException e) {
//Should never happen
Log.e(K9.LOG_TAG, "Could not read string to convert text to HTML:", e);
}
// Close off any quotes we may have opened. // Close off any quotes we may have opened.
if (quoteDepth > 0) { if (quoteDepth > 0) {
for (int i = quoteDepth; i > 0; i--) { for (int i = quoteDepth; i > 0; i--) {