From d8724784dd20338dd7616b230f72285d53ffde1d Mon Sep 17 00:00:00 2001 From: Bao-Long Nguyen-Trong Date: Wed, 20 May 2009 04:39:51 +0000 Subject: [PATCH] . Minor memory usage optimization of how we HTMLize plain text emails --- .../android/email/mail/store/LocalStore.java | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/src/com/android/email/mail/store/LocalStore.java b/src/com/android/email/mail/store/LocalStore.java index e4a087e4f..754e84539 100644 --- a/src/com/android/email/mail/store/LocalStore.java +++ b/src/com/android/email/mail/store/LocalStore.java @@ -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);