Continue after multipart error

pull/207/head
M66B 4 years ago
parent e1e268c389
commit 46a9127785

@ -3728,24 +3728,6 @@ class Core {
IMAPStore istore, IMAPFolder ifolder, MimeMessage imessage, IMAPStore istore, IMAPFolder ifolder, MimeMessage imessage,
boolean browsed, boolean download, boolean browsed, boolean download,
List<EntityRule> rules, State state, SyncStats stats) throws MessagingException, IOException { List<EntityRule> rules, State state, SyncStats stats) throws MessagingException, IOException {
try {
return _synchronizeMessage(context, account, folder,
istore, ifolder, imessage,
browsed, download, rules, state, stats);
} catch (MessageHelper.MessagingStructureException ex) {
Log.e(ex);
long uid = ifolder.getUID(imessage);
EntityOperation.queue(context, folder, EntityOperation.FETCH, uid);
return null;
}
}
private static EntityMessage _synchronizeMessage(
Context context,
EntityAccount account, EntityFolder folder,
IMAPStore istore, IMAPFolder ifolder, MimeMessage imessage,
boolean browsed, boolean download,
List<EntityRule> rules, State state, SyncStats stats) throws MessagingException, IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean download_headers = prefs.getBoolean("download_headers", false); boolean download_headers = prefs.getBoolean("download_headers", false);

@ -3806,8 +3806,11 @@ public class MessageHelper {
break; break;
} }
} }
} else } else {
throw new MessagingStructureException(content, "multipart/mixed"); String msg = "Expected multipart/mixed got " + content.getClass().getName();
Log.e(msg);
parts.warnings.add(msg);
}
} }
if (part.isMimeType("multipart/signed")) { if (part.isMimeType("multipart/signed")) {
@ -3851,8 +3854,11 @@ public class MessageHelper {
sb.append(' ').append(i).append('=').append(multipart.getBodyPart(i).getContentType()); sb.append(' ').append(i).append('=').append(multipart.getBodyPart(i).getContentType());
Log.e(sb.toString()); Log.e(sb.toString());
} }
} else } else {
throw new MessagingStructureException(content, "multipart/signed"); String msg = "Expected multipart/signed got " + content.getClass().getName();
Log.e(msg);
parts.warnings.add(msg);
}
} else } else
Log.e(ct.toString()); Log.e(ct.toString());
} else if (part.isMimeType("multipart/encrypted")) { } else if (part.isMimeType("multipart/encrypted")) {
@ -3873,8 +3879,12 @@ public class MessageHelper {
sb.append(' ').append(i).append('=').append(multipart.getBodyPart(i).getContentType()); sb.append(' ').append(i).append('=').append(multipart.getBodyPart(i).getContentType());
Log.e(sb.toString()); Log.e(sb.toString());
} }
} else } else {
throw new MessagingStructureException(content, "multipart/encrypted"); String msg = "Expected multipart/encrypted got " + content.getClass().getName();
Log.e(msg);
parts.warnings.add(msg);
}
} else } else
Log.e(ct.toString()); Log.e(ct.toString());
} else if (part.isMimeType("application/pkcs7-mime") || } else if (part.isMimeType("application/pkcs7-mime") ||
@ -3954,11 +3964,8 @@ public class MessageHelper {
if (part.isMimeType("multipart/*")) { if (part.isMimeType("multipart/*")) {
Multipart multipart; Multipart multipart;
Object content = part.getContent(); // Should always be Multipart Object content = part.getContent(); // Should always be Multipart
if (content instanceof Multipart) if (content instanceof Multipart) {
multipart = (Multipart) part.getContent(); multipart = (Multipart) part.getContent();
else
throw new MessagingStructureException(content, "multipart/*");
int count = multipart.getCount(); int count = multipart.getCount();
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
try { try {
@ -3970,7 +3977,14 @@ public class MessageHelper {
Log.w(ex); Log.w(ex);
parts.warnings.add(Log.formatThrowable(ex, false)); parts.warnings.add(Log.formatThrowable(ex, false));
} }
return;
} else { } else {
String msg = "Expected multipart/* got " + content.getClass().getName();
Log.e(msg);
parts.warnings.add(msg);
}
}
// https://www.iana.org/assignments/cont-disp/cont-disp.xhtml // https://www.iana.org/assignments/cont-disp/cont-disp.xhtml
String disposition; String disposition;
try { try {
@ -4093,7 +4107,6 @@ public class MessageHelper {
parts.attachments.add(apart); parts.attachments.add(apart);
} }
}
} catch (FolderClosedException ex) { } catch (FolderClosedException ex) {
throw ex; throw ex;
} catch (MessagingException ex) { } catch (MessagingException ex) {
@ -4435,24 +4448,6 @@ public class MessageHelper {
return values; return values;
} }
static class MessagingStructureException extends MessagingException {
private String className;
private String expected;
MessagingStructureException(Object content, String expected) {
super();
if (content != null)
this.className = content.getClass().getName();
this.expected = expected;
}
@Nullable
@Override
public String getMessage() {
return className + " expected: " + expected;
}
}
static class Report { static class Report {
String type; String type;
String reporter; String reporter;

Loading…
Cancel
Save