Skip to content

Commit

Permalink
#396: ignore error in case attached nested Outlook message actually c…
Browse files Browse the repository at this point in the history
…ontains no content
  • Loading branch information
bbottema committed Jul 13, 2022
1 parent 3f03c0f commit d981f27
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.simplejavamail.internal.outlooksupport.converter;

import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
import jakarta.mail.util.ByteArrayDataSource;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -108,8 +109,15 @@ private static EmailFromOutlookMessage buildEmailFromOutlookMessage(
final Email email = buildEmailFromOutlookMessage(builderFactory.create(), nestedMsg, builderFactory, internalEmailConverter)
.getEmailBuilder().buildEmail();
final MimeMessage message = internalEmailConverter.emailToMimeMessage(email);
final byte[] mimedata = internalEmailConverter.mimeMessageToEMLByteArray(message);
builder.withAttachment(nestedMsg.getSubject() + ".eml", new ByteArrayDataSource(mimedata, "message/rfc822"));
try {
final byte[] mimedata = internalEmailConverter.mimeMessageToEMLByteArray(message);
builder.withAttachment(nestedMsg.getSubject() + ".eml", new ByteArrayDataSource(mimedata, "message/rfc822"));
} catch (IllegalStateException e) {
boolean reasonIsEmptyMessage = e.getCause() instanceof MessagingException && e.getCause().getMessage().equals("No MimeMessage content");
if (!reasonIsEmptyMessage) throw e;
// :sadface: nested message attachment is actually invalid (possibly empty because of #396),
// so we're justgoing to ignore it
}
}
}

Expand Down

0 comments on commit d981f27

Please sign in to comment.