Simplify getTextForDisplay() and fix a potential ClassCastException

This commit is contained in:
Jan Berkel 2011-02-19 16:35:11 +01:00 committed by Jesse Vincent
parent 685df0ff67
commit a7a690e6ff

View file

@ -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.