Improved body structure workaround

pull/194/head
M66B 4 years ago
parent 1cb7812581
commit f30c26757a

@ -574,15 +574,23 @@ public class IMAPMessage extends MimeMessage implements ReadableMime {
if (type == null) {
loadBODYSTRUCTURE();
// Some servers report incorrectly text/plain in some situations
if ("text".equalsIgnoreCase(bs.type) &&
"plain".equalsIgnoreCase(bs.subtype))
// Some servers, like Yandex, report an incorrect/incomplete BODYSTRUCTURE
if (("text".equalsIgnoreCase(bs.type) &&
"plain".equalsIgnoreCase(bs.subtype)) ||
("multipart".equalsIgnoreCase(bs.type) &&
("signed".equalsIgnoreCase(bs.subtype) || "encrypted".equalsIgnoreCase(bs.subtype)) &&
(bs.cParams == null || bs.cParams.get("protocol") == null)) ||
("application".equalsIgnoreCase(bs.type) &&
("pkcs7-mime".equalsIgnoreCase(bs.subtype) || "x-pkcs7-mime".equalsIgnoreCase(bs.subtype)) &&
(bs.cParams == null || bs.cParams.get("smime-type") == null)))
try {
String[] c = getHeader("Content-type");
String[] c = getHeader("Content-type"); // Fetches header
if (c != null && c.length == 1) {
ContentType ct = new ContentType(c[0]);
if (!bs.type.equalsIgnoreCase(ct.getPrimaryType()) ||
!bs.subtype.equalsIgnoreCase(ct.getSubType())) {
if (!("text".equalsIgnoreCase(bs.type) &&
"plain".equalsIgnoreCase(bs.subtype)) ||
!(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();

@ -2645,32 +2645,9 @@ public class MessageHelper {
try {
if (imessage instanceof IMAPMessage) {
if (structure) {
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 {
if (structure)
imessage.getContentType(); // force loadBODYSTRUCTURE
else {
if (headers)
imessage.getAllHeaders(); // force loadHeaders
else

Loading…
Cancel
Save