From b3360dde2b7fb0b7df5c18db596a3b0f4f23ba5d Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 16 Feb 2023 10:43:15 +0100 Subject: [PATCH] Improved raw fetch --- .../java/eu/faircode/email/MessageHelper.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 13f5d82f3a..9cd8a90c38 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -1998,9 +1998,12 @@ public class MessageHelper { try { // Workaround reformatted headers (Content-Type) // This will do a BODY.PEEK[] to fetch the headers and message body - Properties props = MessageHelper.getSessionProperties(true); - Session isession = Session.getInstance(props, null); - MimeMessage amessage = new MimeMessage(isession, ((ReadableMime) imessage).getMimeStream()); + MimeMessage amessage = imessage; + if (imessage instanceof ReadableMime) { + Properties props = MessageHelper.getSessionProperties(true); + Session isession = Session.getInstance(props, null); + amessage = new MimeMessage(isession, ((ReadableMime) imessage).getMimeStream()); + } // https://datatracker.ietf.org/doc/html/rfc6376/ String[] headers = amessage.getHeader("DKIM-Signature"); @@ -4810,8 +4813,11 @@ public class MessageHelper { try { if (imessage instanceof IMAPMessage) { - if (Boolean.parseBoolean(imessage.getSession().getProperty("fairemail.rawfetch"))) - throw new MessagingException("Unable to load BODYSTRUCTURE"); + if (Boolean.parseBoolean(imessage.getSession().getProperty("fairemail.rawfetch"))) { + Properties props = MessageHelper.getSessionProperties(true); + Session isession = Session.getInstance(props, null); + imessage = new MimeMessage(isession, ((ReadableMime) imessage).getMimeStream()); + } if (structure) imessage.getContentType(); // force loadBODYSTRUCTURE