From fd8613a89acc52f2e491ff1aa40848f8fcbf9105 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 3 Oct 2019 13:32:52 +0200 Subject: [PATCH] Fixed handling missing content types --- .../java/eu/faircode/email/MessageHelper.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 653ad35100..023f357ed9 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -1024,7 +1024,7 @@ public class MessageHelper { // Prevent Jsoup throwing an exception result = result.replace("\0", ""); - if (plain != null) { + if (part == plain) { StringBuilder sb = new StringBuilder(); sb.append(""); @@ -1293,13 +1293,18 @@ public class MessageHelper { filename = null; } - ContentType contentType = new ContentType(part.getContentType()); + String pct = part.getContentType(); + if (TextUtils.isEmpty(pct)) + pct = "text/plain"; + ContentType contentType = new ContentType(pct); if (part instanceof MimeMessage) { String header = ((MimeMessage) part).getHeader("Content-Type", null); - ContentType ct = new ContentType(header); - if (!ct.getBaseType().equalsIgnoreCase(contentType.getBaseType())) { - Log.w("Content type message=" + ct + " part=" + contentType); - contentType = ct; + if (!TextUtils.isEmpty(header)) { + ContentType messageContentType = new ContentType(header); + if (!messageContentType.getBaseType().equalsIgnoreCase(contentType.getBaseType())) { + Log.w("Content type message=" + messageContentType + " part=" + contentType); + contentType = messageContentType; + } } } @@ -1307,10 +1312,10 @@ public class MessageHelper { TextUtils.isEmpty(filename) && ((parts.plain == null && "text/plain".equalsIgnoreCase(contentType.getBaseType())) || (parts.html == null && "text/html".equalsIgnoreCase(contentType.getBaseType())))) { - if ("text/plain".equalsIgnoreCase(contentType.getBaseType())) - parts.plain = part; - else + if ("text/html".equalsIgnoreCase(contentType.getBaseType())) parts.html = part; + else + parts.plain = part; } else { AttachmentPart apart = new AttachmentPart(); apart.disposition = disposition;