From a7a690e6ff5eaddd3ed03df78a76af0bb67cea0f Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Sat, 19 Feb 2011 16:35:11 +0100 Subject: [PATCH] Simplify getTextForDisplay() and fix a potential ClassCastException --- src/com/fsck/k9/mail/store/LocalStore.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index d316c4d5a..e90e5a64e 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -2928,24 +2928,17 @@ public class LocalStore extends Store implements Serializable { /** * Fetch the message text for display. This always returns an HTML-ified version of the * message, even if it was originally a text-only message. - * @return HTML version of message for display purposes. + * @return HTML version of message for display purposes or null. * @throws MessagingException */ public String getTextForDisplay() throws MessagingException { - String text; // First try and fetch an HTML part. + String text = null; // First try and fetch an HTML part. Part part = MimeUtility.findFirstPartByMimeType(this, "text/html"); if (part == null) { // If that fails, try and get a text part. part = MimeUtility.findFirstPartByMimeType(this, "text/plain"); - if (part == null) { - text = null; - } else { - LocalStore.LocalTextBody body = (LocalStore.LocalTextBody) part.getBody(); - if (body == null) { - text = null; - } else { - text = body.getBodyForDisplay(); - } + if (part != null && part.getBody() instanceof LocalStore.LocalTextBody) { + text = ((LocalStore.LocalTextBody) part.getBody()).getBodyForDisplay(); } } else { // We successfully found an HTML part; do the necessary character set decoding.