This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-3.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.x by this push: new 1a335163ac6 CAMEL-20028: camel-mail - Make disposition optional if filename is non empty (#11814) 1a335163ac6 is described below commit 1a335163ac65d0136caa8636a7361340005efc6b Author: Benjamin Graf <gra...@users.noreply.github.com> AuthorDate: Mon Oct 23 20:18:35 2023 +0200 CAMEL-20028: camel-mail - Make disposition optional if filename is non empty (#11814) --- .../apache/camel/component/mail/MailBinding.java | 2 +- .../component/mail/MailAttachmentNamesTest.java | 12 ++++++++++ .../src/test/resources/disposition_none.txt | 26 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) 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 709daa7b46b..5d82587d07d 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 @@ -399,7 +399,7 @@ public class MailBinding { LOG.trace("Part #{}: LineCount: {}", i, part.getLineCount()); } - if (validDisposition(disposition, fileName)) { + if (validDisposition(disposition, fileName) || fileName != null && !fileName.isEmpty()) { LOG.debug("Mail contains file attachment: {}", fileName); if (handleDuplicateAttachmentNames != null) { if (handleDuplicateAttachmentNames diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailAttachmentNamesTest.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailAttachmentNamesTest.java index abef665626a..0d6a11dcbbe 100644 --- a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailAttachmentNamesTest.java +++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailAttachmentNamesTest.java @@ -239,6 +239,18 @@ public class MailAttachmentNamesTest extends CamelTestSupport { } } + @Test + public void testAttachmentWithNoDisposition() throws Exception { + sendTestMessage("disposition_none.txt", "default@localhost"); + + resultDefaultEndpoint.assertIsSatisfied(); + Exchange exchange = resultDefaultEndpoint.getReceivedExchanges().get(0); + assertEquals(1, exchange.getIn(AttachmentMessage.class).getAttachmentObjects().entrySet().size()); + + Map<String, Attachment> attachments = exchange.getIn(AttachmentMessage.class).getAttachmentObjects(); + assertNotNull(attachments.get("test.jpg")); + } + private void sendTestMessage(String filename, String recipient) throws MessagingException, FileNotFoundException { MimeMessage message = populateMimeMessage(session, filename); message.setRecipients(Message.RecipientType.TO, recipient); diff --git a/components/camel-mail/src/test/resources/disposition_none.txt b/components/camel-mail/src/test/resources/disposition_none.txt new file mode 100644 index 00000000000..848cd75b4a8 --- /dev/null +++ b/components/camel-mail/src/test/resources/disposition_none.txt @@ -0,0 +1,26 @@ +Date: Fri, 25 Feb 2022 20:55:29 +0100 (CET) +From: recei...@test.com +To: recei...@test.com +Message-ID: <510113906.1.1645818929577@host.docker.internal> +Subject: This is the mail subject +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="----=_Part_0_932607259.1645818929513" + +------=_Part_0_932607259.1645818929513 +Content-Type: text/plain; charset=us-ascii +Content-Transfer-Encoding: 7bit + +This is the message body +------=_Part_0_932607259.1645818929513 +Content-Type: image/jpeg; name="test.jpg" +Content-Transfer-Encoding: base64 + +/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEP +ERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4e +Hh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCAFhAWMDASIA +AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA +AAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3 +ODk6Q0RFRkdISUpTVFVWV1hZWmNkZ +------=_Part_0_932607259.1645818929513-- +