1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-24 02:12:15 -05:00

. Potential fix for issue 404: now doing all HTMLization in one pass to minimize the amount of String objects

This commit is contained in:
Bao-Long Nguyen-Trong 2009-05-10 07:05:24 +00:00
parent 5b0dee8cc0
commit bb8629abe8

View File

@ -25,13 +25,11 @@ import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.net.Uri; import android.net.Uri;
import android.util.Config;
import android.util.Log; import android.util.Log;
import android.text.util.Regex; import android.text.util.Regex;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import com.android.email.Email; import com.android.email.Email;
import com.android.email.Preferences; import com.android.email.Preferences;
@ -56,6 +54,7 @@ import com.android.email.mail.internet.MimeMultipart;
import com.android.email.mail.internet.MimeUtility; import com.android.email.mail.internet.MimeUtility;
import com.android.email.mail.internet.TextBody; import com.android.email.mail.internet.TextBody;
import com.android.email.provider.AttachmentProvider; import com.android.email.provider.AttachmentProvider;
import java.io.StringReader;
/** /**
* <pre> * <pre>
@ -1457,10 +1456,36 @@ public class LocalStore extends Store implements Serializable {
} }
public String htmlifyString(String text) { public String htmlifyString(String text) {
text = text.replaceAll("&", "&amp;"); StringReader reader = new StringReader(text);
text = text.replaceAll("<", "&lt;"); StringBuilder buff = new StringBuilder(text.length() + 512);
text = text.replaceAll(">", "&gt;"); int c = 0;
text = text.replaceAll("\r?\n", "<br/>"); try {
while ((c = reader.read()) != -1) {
switch (c) {
case '&':
buff.append("&amp;");
break;
case '<':
buff.append("&lt;");
break;
case '>':
buff.append("&gt;");
break;
case '\r':
break;
case '\n':
buff.append("<br/>");
break;
default:
buff.append((char)c);
}//switch
}
} catch (IOException e) {
//Should never happen
Log.e(Email.LOG_TAG, null, e);
}
text = buff.toString();
Matcher m = Regex.WEB_URL_PATTERN.matcher(text); Matcher m = Regex.WEB_URL_PATTERN.matcher(text);
StringBuffer sb = new StringBuffer(text.length() + 512); StringBuffer sb = new StringBuffer(text.length() + 512);
sb.append("<html><body>"); sb.append("<html><body>");
@ -1468,8 +1493,7 @@ public class LocalStore extends Store implements Serializable {
int start = m.start(); int start = m.start();
if (start == 0 || (start != 0 && text.charAt(start - 1) != '@')) { if (start == 0 || (start != 0 && text.charAt(start - 1) != '@')) {
m.appendReplacement(sb, "<a href=\"$0\">$0</a>"); m.appendReplacement(sb, "<a href=\"$0\">$0</a>");
} } else {
else {
m.appendReplacement(sb, "$0"); m.appendReplacement(sb, "$0");
} }
} }
@ -1479,7 +1503,6 @@ public class LocalStore extends Store implements Serializable {
return text; return text;
} }
} }
public class LocalMessage extends MimeMessage { public class LocalMessage extends MimeMessage {