From b066c0681397e4c69489a36f2bac160122c2d29f Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 20 Feb 2021 13:58:57 +0100 Subject: [PATCH] Workaround inconsistent message content type --- .../java/com/sun/mail/imap/IMAPMessage.java | 20 +++++++++++++++++++ .../java/eu/faircode/email/MessageHelper.java | 16 --------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/sun/mail/imap/IMAPMessage.java b/app/src/main/java/com/sun/mail/imap/IMAPMessage.java index 64b68415e4..4f92211b4d 100644 --- a/app/src/main/java/com/sun/mail/imap/IMAPMessage.java +++ b/app/src/main/java/com/sun/mail/imap/IMAPMessage.java @@ -573,6 +573,26 @@ public class IMAPMessage extends MimeMessage implements ReadableMime { // If we haven't cached the type yet .. if (type == null) { loadBODYSTRUCTURE(); + + // Some servers report incorrectly text/plain in some situations + if ("text".equalsIgnoreCase(bs.type) && + "plain".equalsIgnoreCase(bs.subtype)) + try { + String[] c = getHeader("Content-type"); + if (c != null && c.length == 1) { + ContentType ct = new ContentType(c[0]); + if (!bs.type.equalsIgnoreCase(ct.getPrimaryType()) || + !bs.subtype.equalsIgnoreCase(ct.getSubType())) { + eu.faircode.email.Log.e("Inconsistent" + + " bs=" + bs.type + "/" + bs.subtype + "/" + bs.cParams + " header=" + ct); + type = ct.toString(); + return type; + } + } + } catch (MessagingException ex) { + eu.faircode.email.Log.e(ex); + } + // generate content-type from BODYSTRUCTURE ContentType ct = new ContentType(bs.type, bs.subtype, bs.cParams); type = ct.toString(); diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index e8a7c591f2..57f9684bb8 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -2545,22 +2545,6 @@ public class MessageHelper { try { // From the body structure contentType = new ContentType(part.getContentType()); - - // Workaround bodystructure not matching header - if (part instanceof MimeMessage && - "text/plain".equalsIgnoreCase(contentType.getBaseType())) - try { - String[] c = part.getHeader("Content-type"); - if (c != null && c.length > 0) { - ContentType ct = new ContentType(c[0]); - if ("text/html".equalsIgnoreCase(ct.getBaseType())) { - Log.e("Inconsistent bs=" + contentType + " header=" + ct); - contentType = ct; - } - } - } catch (MessagingException ex) { - Log.w(ex); - } } catch (ParseException ex) { if (part instanceof MimeMessage) Log.w("MimeMessage content type=" + ex.getMessage());