From 2806c267c923cd763b5fe7e004760f08d050ea51 Mon Sep 17 00:00:00 2001 From: Andrew Chen Date: Thu, 23 Dec 2010 23:16:54 +0000 Subject: [PATCH] Remove unreadable characters from message previews. --- src/com/fsck/k9/mail/store/LocalStore.java | 24 ++++++++++------------ 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index 9199dd130..78ada0624 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -1,16 +1,7 @@ package com.fsck.k9.mail.store; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Serializable; -import java.io.StringReader; -import java.io.UnsupportedEncodingException; +import java.io.*; import java.net.URLEncoder; import java.util.ArrayList; import java.util.Arrays; @@ -107,6 +98,14 @@ public class LocalStore extends Store implements Serializable "subject, sender_list, date, uid, flags, id, to_list, cc_list, " + "bcc_list, reply_to_list, attachment_count, internal_date, message_id, folder_id, preview "; + /** + * When generating previews, Spannable objects that can't be converted into a String are + * represented as 0xfffc. When displayed, these show up as undisplayed squares. These constants + * define the object character and the replacement character. + */ + private static final char PREVIEW_OBJECT_CHARACTER = (char)0xfffc; + private static final char PREVIEW_OBJECT_REPLACEMENT = (char)0x20; // space + protected static final int DB_VERSION = 39; protected String uUid = null; @@ -2362,7 +2361,7 @@ public class LocalStore extends Store implements Serializable // If we couldn't generate a reasonable preview from the text part, try doing it with the HTML part. if (preview == null || preview.length() == 0) { - preview = calculateContentPreview(Html.fromHtml(html).toString()); + preview = calculateContentPreview(Html.fromHtml(html).toString().replace(PREVIEW_OBJECT_CHARACTER, PREVIEW_OBJECT_REPLACEMENT)); } try @@ -2490,7 +2489,7 @@ public class LocalStore extends Store implements Serializable // If we couldn't generate a reasonable preview from the text part, try doing it with the HTML part. if (preview == null || preview.length() == 0) { - preview = calculateContentPreview(Html.fromHtml(html).toString()); + preview = calculateContentPreview(Html.fromHtml(html).toString().replace(PREVIEW_OBJECT_CHARACTER, PREVIEW_OBJECT_REPLACEMENT)); } try { @@ -2618,7 +2617,6 @@ public class LocalStore extends Store implements Serializable /** * @param messageId * @param attachment - * @param saveAsNew * @throws IOException * @throws MessagingException */