You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/08/11 12:20:51 UTC

[camel] branch camel-3.14.x updated: CAMEL-18379: camel-mail - Skip file attachments with empty file names. Thanks to Richard Vigniel for reporting.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.14.x by this push:
     new e0fa71d8052 CAMEL-18379: camel-mail - Skip file attachments with empty file names. Thanks to Richard Vigniel for reporting.
e0fa71d8052 is described below

commit e0fa71d805253869d1d37e1752ba94d1d4d434f9
Author: Claus Ibsen <cl...@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 936dd05fcaa..d664094e918 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();
+    }
+
 }