mirror of https://github.com/M66B/FairEmail.git
Improved body structure workaround
This commit is contained in:
parent
1cb7812581
commit
f30c26757a
|
@ -574,15 +574,23 @@ public class IMAPMessage extends MimeMessage implements ReadableMime {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
loadBODYSTRUCTURE();
|
loadBODYSTRUCTURE();
|
||||||
|
|
||||||
// Some servers report incorrectly text/plain in some situations
|
// Some servers, like Yandex, report an incorrect/incomplete BODYSTRUCTURE
|
||||||
if ("text".equalsIgnoreCase(bs.type) &&
|
if (("text".equalsIgnoreCase(bs.type) &&
|
||||||
"plain".equalsIgnoreCase(bs.subtype))
|
"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 {
|
try {
|
||||||
String[] c = getHeader("Content-type");
|
String[] c = getHeader("Content-type"); // Fetches header
|
||||||
if (c != null && c.length == 1) {
|
if (c != null && c.length == 1) {
|
||||||
ContentType ct = new ContentType(c[0]);
|
ContentType ct = new ContentType(c[0]);
|
||||||
if (!bs.type.equalsIgnoreCase(ct.getPrimaryType()) ||
|
if (!("text".equalsIgnoreCase(bs.type) &&
|
||||||
!bs.subtype.equalsIgnoreCase(ct.getSubType())) {
|
"plain".equalsIgnoreCase(bs.subtype)) ||
|
||||||
|
!(bs.type.equalsIgnoreCase(ct.getPrimaryType()) &&
|
||||||
|
bs.subtype.equalsIgnoreCase(ct.getSubType()))) {
|
||||||
eu.faircode.email.Log.e("Inconsistent" +
|
eu.faircode.email.Log.e("Inconsistent" +
|
||||||
" bs=" + bs.type + "/" + bs.subtype + "/" + bs.cParams + " header=" + ct);
|
" bs=" + bs.type + "/" + bs.subtype + "/" + bs.cParams + " header=" + ct);
|
||||||
type = ct.toString();
|
type = ct.toString();
|
||||||
|
|
|
@ -2645,32 +2645,9 @@ public class MessageHelper {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (imessage instanceof IMAPMessage) {
|
if (imessage instanceof IMAPMessage) {
|
||||||
if (structure) {
|
if (structure)
|
||||||
String contentType = imessage.getContentType(); // force loadBODYSTRUCTURE
|
imessage.getContentType(); // force loadBODYSTRUCTURE
|
||||||
|
else {
|
||||||
// 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 (headers)
|
if (headers)
|
||||||
imessage.getAllHeaders(); // force loadHeaders
|
imessage.getAllHeaders(); // force loadHeaders
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue