Catch TNEF attachment errors

pull/190/head
M66B 5 years ago
parent fc80a35ef2
commit 6c9d0bb938

@ -2165,32 +2165,36 @@ public class MessageHelper {
db.attachment().setDownloaded(attachment.id, (long) body.length()); db.attachment().setDownloaded(attachment.id, (long) body.length());
} }
for (org.apache.poi.hmef.Attachment at : msg.getAttachments()) { for (org.apache.poi.hmef.Attachment at : msg.getAttachments())
String filename = at.getLongFilename(); try {
if (filename == null) String filename = at.getLongFilename();
filename = at.getFilename(); if (filename == null)
if (filename == null) { filename = at.getFilename();
String ext = at.getExtension(); if (filename == null) {
if (ext != null) String ext = at.getExtension();
filename = "document." + ext; if (ext != null)
} filename = "document." + ext;
}
EntityAttachment attachment = new EntityAttachment(); EntityAttachment attachment = new EntityAttachment();
attachment.message = local.message; attachment.message = local.message;
attachment.sequence = local.sequence; attachment.sequence = local.sequence;
attachment.subsequence = ++subsequence; attachment.subsequence = ++subsequence;
attachment.name = filename; attachment.name = filename;
attachment.type = Helper.guessMimeType(attachment.name); attachment.type = Helper.guessMimeType(attachment.name);
attachment.disposition = Part.ATTACHMENT; attachment.disposition = Part.ATTACHMENT;
attachment.id = db.attachment().insertAttachment(attachment); attachment.id = db.attachment().insertAttachment(attachment);
byte[] data = at.getContents(); byte[] data = at.getContents();
try (OutputStream os = new FileOutputStream(attachment.getFile(context))) { try (OutputStream os = new FileOutputStream(attachment.getFile(context))) {
os.write(data); os.write(data);
} }
db.attachment().setDownloaded(attachment.id, (long) data.length); db.attachment().setDownloaded(attachment.id, (long) data.length);
} } catch (Throwable ex) {
// java.lang.IllegalArgumentException: Attachment corrupt - no Data section
Log.e(ex);
}
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (org.apache.poi.hmef.attribute.TNEFAttribute attr : msg.getMessageAttributes()) for (org.apache.poi.hmef.attribute.TNEFAttribute attr : msg.getMessageAttributes())

Loading…
Cancel
Save