1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02: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,29 +1456,53 @@ 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 {
Matcher m = Regex.WEB_URL_PATTERN.matcher(text); while ((c = reader.read()) != -1) {
StringBuffer sb = new StringBuffer(text.length() + 512); switch (c) {
sb.append("<html><body>"); case '&':
while (m.find()) { buff.append("&amp;");
int start = m.start(); break;
if (start == 0 || (start != 0 && text.charAt(start - 1) != '@')) { case '<':
m.appendReplacement(sb, "<a href=\"$0\">$0</a>"); buff.append("&lt;");
} break;
else { case '>':
m.appendReplacement(sb, "$0"); buff.append("&gt;");
} break;
} case '\r':
m.appendTail(sb); break;
sb.append("</body></html>"); case '\n':
text = sb.toString(); 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);
StringBuffer sb = new StringBuffer(text.length() + 512);
sb.append("<html><body>");
while (m.find()) {
int start = m.start();
if (start == 0 || (start != 0 && text.charAt(start - 1) != '@')) {
m.appendReplacement(sb, "<a href=\"$0\">$0</a>");
} else {
m.appendReplacement(sb, "$0");
}
}
m.appendTail(sb);
sb.append("</body></html>");
text = sb.toString();
return text; return text;
} }
} }
public class LocalMessage extends MimeMessage { public class LocalMessage extends MimeMessage {