From aa423271d09b8022ef05df7df4f11390879f5a03 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 10 Jul 2020 17:26:07 +0200 Subject: [PATCH] Workaround protocol parameter missing --- .../java/eu/faircode/email/MessageHelper.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 4da9c637b2..3e3d8eb099 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -2145,9 +2145,32 @@ public class MessageHelper { try { if (imessage instanceof IMAPMessage) { - if (body) - imessage.getContentType(); // force loadBODYSTRUCTURE - else + if (body) { + String contentType = imessage.getContentType(); // force loadBODYSTRUCTURE + + // Workaround protocol parameter missing + // Happens with Yandex and possibly other providers + boolean load = false; + try { + ContentType ct = new ContentType(contentType); + if (ct.match("multipart/signed") || ct.match("multipart/encrypted")) { + String protocol = ct.getParameter("protocol"); + if (protocol == null) + load = true; + } else if (ct.match("application/pkcs7-mime") || ct.match("application/x-pkcs7-mime")) { + String smimeType = ct.getParameter("smime-type"); + if (smimeType == null) + load = true; + } + } catch (Throwable ex) { + Log.w(ex); + } + + if (load) { + Log.w("Protocol missing content-type=" + contentType); + throw new MessagingException("Failed to load IMAP envelope"); + } + } else imessage.getMessageID(); // force loadEnvelope } } catch (MessagingException ex) {