This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-3.18.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.18.x by this push: new c78d3fa0f41 CAMEL-18379: camel-mail - Skip file attachments with empty file names. Thanks to Richard Vigniel for reporting. c78d3fa0f41 is described below commit c78d3fa0f415615bcf67f2243f5ec5a8b701ba3a Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Aug 11 14:19:53 2022 +0200 CAMEL-18379: camel-mail - Skip file attachments with empty file names. Thanks to Richard Vigniel for reporting. --- .../org/apache/camel/component/mail/MailBinding.java | 10 +++++++--- .../component/mail/MailBindingAttachmentFileTest.java | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java index d63989a8838..becccec0985 100644 --- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java +++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java @@ -340,6 +340,9 @@ public class MailBinding { if (fileName != null) { fileName = FileUtil.stripPath(fileName); } + if (fileName != null) { + fileName = fileName.trim(); + } if (LOG.isTraceEnabled()) { LOG.trace("Part #{}: Disposition: {}", i, disposition); @@ -350,8 +353,7 @@ public class MailBinding { LOG.trace("Part #{}: LineCount: {}", i, part.getLineCount()); } - if (validDisposition(disposition, fileName) - || fileName != null) { + if (validDisposition(disposition, fileName)) { LOG.debug("Mail contains file attachment: {}", fileName); if (!map.containsKey(fileName)) { // Parts marked with a disposition of Part.ATTACHMENT are clearly attachments @@ -376,8 +378,10 @@ public class MailBinding { } private boolean validDisposition(String disposition, String fileName) { + if (fileName == null || fileName.isEmpty()) { + return false; + } return disposition != null - && fileName != null && (disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition.equalsIgnoreCase(Part.INLINE)); } diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailBindingAttachmentFileTest.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailBindingAttachmentFileTest.java index 2aa7877985b..26c1e2440e5 100644 --- a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailBindingAttachmentFileTest.java +++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailBindingAttachmentFileTest.java @@ -32,6 +32,7 @@ import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import org.apache.camel.attachment.Attachment; +import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -65,4 +66,21 @@ public class MailBindingAttachmentFileTest { public static Iterable<String> fileNames() { return Arrays.asList("file.txt", "../file.txt", "..\\file.txt", "/absolute/file.txt", "c:\\absolute\\file.txt"); } + + @Test + public void testSkipEmptyName() throws MessagingException, IOException { + final Session session = Session.getInstance(new Properties()); + final Message message = new MimeMessage(session); + + final Multipart multipart = new MimeMultipart(); + final MimeBodyPart part = new MimeBodyPart(); + part.attachFile(""); + multipart.addBodyPart(part); + message.setContent(multipart); + + final Map<String, Attachment> attachments = new HashMap<>(); + binding.extractAttachmentsFromMail(message, attachments); + assertThat(attachments).isEmpty(); + } + }