. Minor memory usage optimization of how we HTMLize plain text emails

This commit is contained in:
Bao-Long Nguyen-Trong 2009-05-20 04:39:51 +00:00
parent 23797b62ee
commit d8724784dd
1 changed files with 19 additions and 26 deletions

View File

@ -1087,11 +1087,8 @@ public class LocalStore extends Store implements Serializable {
}
}
sbHtml = markupContent(sbText,sbHtml);
String text = sbText.toString();
String html = markupContent(text, sbHtml.toString());
try {
ContentValues cv = new ContentValues();
@ -1105,8 +1102,8 @@ public class LocalStore extends Store implements Serializable {
cv.put("to_list", Address.pack(message.getRecipients(RecipientType.TO)));
cv.put("cc_list", Address.pack(message.getRecipients(RecipientType.CC)));
cv.put("bcc_list", Address.pack(message.getRecipients(RecipientType.BCC)));
cv.put("html_content", sbHtml.length() > 0 ? sbHtml.toString() : null);
cv.put("text_content", sbText.length() > 0 ? sbText.toString() : null);
cv.put("html_content", html.length() > 0 ? html : null);
cv.put("text_content", text.length() > 0 ? text : null);
cv.put("reply_to_list", Address.pack(message.getReplyTo()));
cv.put("attachment_count", attachments.size());
cv.put("internal_date", message.getInternalDate() == null
@ -1163,8 +1160,8 @@ public class LocalStore extends Store implements Serializable {
}
}
sbHtml = markupContent(sbText,sbHtml);
String text = sbText.toString();
String html = markupContent(text, sbHtml.toString());
try {
mDb.execSQL("UPDATE messages SET "
@ -1187,8 +1184,8 @@ public class LocalStore extends Store implements Serializable {
.getRecipients(RecipientType.CC)),
Address.pack(message
.getRecipients(RecipientType.BCC)),
sbHtml.length() > 0 ? sbHtml.toString() : null,
sbText.length() > 0 ? sbText.toString() : null,
html.length() > 0 ? html : null,
text.length() > 0 ? text : null,
Address.pack(message.getReplyTo()),
attachments.size(),
message.mId
@ -1441,22 +1438,18 @@ public class LocalStore extends Store implements Serializable {
}
public StringBuffer markupContent(StringBuffer sbText, StringBuffer sbHtml) {
if (sbText.length() > 0 && sbHtml.length() == 0) {
sbHtml.append(htmlifyString(sbText.toString()));
}
String html = sbHtml.toString();
if (html.indexOf("cid:")!=-1) {
html = html.replaceAll("cid:", "http://cid/");
}
Spannable markup = new SpannableString(html);
Linkify.addLinks(markup, Linkify.ALL);
StringBuffer sb = new StringBuffer(markup.length());
sb.append(markup.toString());
return sb;
public String markupContent(String text, String html) {
if (text.length() > 0 && html.length() == 0) {
html = htmlifyString(text);
}
if (html.indexOf("cid:") != -1) {
return html.replaceAll("cid:", "http://cid/");
}
else {
return html;
}
}
public String htmlifyString(String text) {
StringReader reader = new StringReader(text);