diff options
author | Michael Rudolf | 2020-01-28 12:37:44 +0000 |
---|---|---|
committer | Michael Rudolf | 2020-01-28 16:06:53 +0000 |
commit | 2a5fdb224bfabc06d950d56973988ce24ab429f5 (patch) | |
tree | 7b529ba3851aafbef7474cc91ae5d510bfe64d1d /org.eclipse.scout.rt.mail | |
parent | 165f59bd22a784887888ac3f05293f76d79beefe (diff) | |
download | org.eclipse.scout.rt-2a5fdb224bfabc06d950d56973988ce24ab429f5.tar.gz org.eclipse.scout.rt-2a5fdb224bfabc06d950d56973988ce24ab429f5.tar.xz org.eclipse.scout.rt-2a5fdb224bfabc06d950d56973988ce24ab429f5.zip |
refactor attachment filename from mail subject generation
Change-Id: I4b1de92e308241c05cff77e22fd28d7daa9753b2
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> |