From 4ea6c1603bf6850121f77afc765c9265ebdef325 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sat, 23 Oct 2010 17:33:08 +0000 Subject: [PATCH] We've been seeing a lot of FCs on htmlifcation of large messages due to running out of memory during our heavy HTMLification. Try to be a bit lighter on the poor RAM if a plain text message is big. --- src/com/fsck/k9/mail/store/LocalStore.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index 595c3624c..2733614a5 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -48,6 +48,8 @@ public class LocalStore extends Store implements Serializable private static final int DB_VERSION = 39; private static final Flag[] PERMANENT_FLAGS = { Flag.DELETED, Flag.X_DESTROYED, Flag.SEEN, Flag.FLAGGED }; + private static final int MAX_SMART_HTMLIFY_MESSAGE_LENGTH = 1024 * 256 ; + private String mPath; private SQLiteDatabase mDb; private File mAttachmentsDir; @@ -2433,6 +2435,18 @@ public class LocalStore extends Store implements Serializable public String htmlifyString(String text) { + // Our HTMLification code is somewhat memory intensive + // and was causing lots of OOM errors on the market + // if the message is big and plain text, just do + // a trivial htmlification + if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) + { + return "" + + htmlifyMessageHeader() + + text + + htmlifyMessageFooter() + + ""; + } StringReader reader = new StringReader(text); StringBuilder buff = new StringBuilder(text.length() + 512); int c = 0;