diff options
Diffstat (limited to 'org.eclipse.scout.rt.mail')
-rw-r--r-- | org.eclipse.scout.rt.mail/src/main/java/org/eclipse/scout/rt/mail/MailHelper.java | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/org.eclipse.scout.rt.mail/src/main/java/org/eclipse/scout/rt/mail/MailHelper.java b/org.eclipse.scout.rt.mail/src/main/java/org/eclipse/scout/rt/mail/MailHelper.java index 699adfef91..fae4f193a8 100644 --- a/org.eclipse.scout.rt.mail/src/main/java/org/eclipse/scout/rt/mail/MailHelper.java +++ b/org.eclipse.scout.rt.mail/src/main/java/org/eclipse/scout/rt/mail/MailHelper.java @@ -179,9 +179,10 @@ public class MailHelper { else if (part.isMimeType(CONTENT_TYPE_MESSAGE_RFC822) && part.getContent() instanceof MimeMessage) { // its a MIME message in rfc822 format as attachment therefore we have to set the filename for the attachment correctly. if (attachmentCollector != null) { - MimeMessage msg = (MimeMessage) part.getContent(); - String filteredSubjectText = StringUtility.filterText(msg.getSubject(), "a-zA-Z0-9_-", ""); - String fileName = (StringUtility.hasText(filteredSubjectText) ? filteredSubjectText : "originalMessage") + ".eml"; + String fileName = getFilenameFromRefc822Attachment(part); + if (StringUtility.isNullOrEmpty(fileName)) { + fileName = "originalMessage.eml"; + } RFCWrapperPart wrapperPart = new RFCWrapperPart(part, fileName); attachmentCollector.add(wrapperPart); } @@ -1013,6 +1014,20 @@ public class MailHelper { } } + public String getFilenameFromRefc822Attachment(Part part) throws MessagingException, IOException { + if (part.getContent() == null) { + return null; + } + String subject = ((MimeMessage) part.getContent()).getSubject(); + if (StringUtility.hasText(subject)) { + String name = FileUtility.toValidFilename(subject); + if (StringUtility.hasText(name)) { + return name + guessAttachmentFileExtension(part.getContentType()); + } + } + return null; + } + /** * Decodes an attachment filename. * <p> |