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

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


The following commit(s) were added to refs/heads/camel-4.14.x by this push:
     new ccdeebc2ae37 [backport camel-4.14.x] CAMEL-23891: camel-mail - filter 
Camel internal headers in MimeMultipartDataFormat unmarshal (#24445)
ccdeebc2ae37 is described below

commit ccdeebc2ae378ba75e5563ddab508fc887527f0c
Author: Andrea Cosentino <[email protected]>
AuthorDate: Mon Jul 6 10:32:48 2026 +0200

    [backport camel-4.14.x] CAMEL-23891: camel-mail - filter Camel internal 
headers in MimeMultipartDataFormat unmarshal (#24445)
    
    CAMEL-23891: camel-mail - filter Camel internal headers in 
MimeMultipartDataFormat unmarshal (#24406)
    
    Signed-off-by: Andrea Cosentino <[email protected]>
    Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
---
 .../mime/multipart/MimeMultipartDataFormat.java     | 18 ++++++++++++++++++
 .../mime/multipart/MimeMultipartDataFormatTest.java | 21 +++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git 
a/components/camel-mail/src/main/java/org/apache/camel/dataformat/mime/multipart/MimeMultipartDataFormat.java
 
b/components/camel-mail/src/main/java/org/apache/camel/dataformat/mime/multipart/MimeMultipartDataFormat.java
index 6827f43cff5d..a4d611dfea44 100644
--- 
a/components/camel-mail/src/main/java/org/apache/camel/dataformat/mime/multipart/MimeMultipartDataFormat.java
+++ 
b/components/camel-mail/src/main/java/org/apache/camel/dataformat/mime/multipart/MimeMultipartDataFormat.java
@@ -50,8 +50,10 @@ import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.attachment.Attachment;
 import org.apache.camel.attachment.AttachmentMessage;
 import org.apache.camel.attachment.DefaultAttachment;
+import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.spi.annotations.Dataformat;
 import org.apache.camel.support.DefaultDataFormat;
+import org.apache.camel.support.DefaultHeaderFilterStrategy;
 import org.apache.camel.support.ExchangeHelper;
 import org.apache.camel.support.MessageHelper;
 import org.apache.camel.util.IOHelper;
@@ -72,11 +74,21 @@ public class MimeMultipartDataFormat extends 
DefaultDataFormat {
     private String includeHeaders;
     private Pattern includeHeadersPattern;
     private boolean binaryContent;
+    private final HeaderFilterStrategy headerFilterStrategy = 
createInboundHeaderFilterStrategy();
 
     public void setBinaryContent(boolean binaryContent) {
         this.binaryContent = binaryContent;
     }
 
+    private static HeaderFilterStrategy createInboundHeaderFilterStrategy() {
+        DefaultHeaderFilterStrategy strategy = new 
DefaultHeaderFilterStrategy();
+        // camel-4.14 DefaultHeaderFilterStrategy does not enable the Camel* 
in-filter by default (that
+        // default was introduced on a later branch), so configure it 
explicitly to filter the Camel*
+        // namespace on the inbound path, matching the mail consumer's 
HeaderFilterStrategy.
+        
strategy.setInFilterStartsWith(DefaultHeaderFilterStrategy.CAMEL_FILTER_STARTS_WITH);
+        return strategy;
+    }
+
     public void setHeadersInline(boolean headersInline) {
         this.headersInline = headersInline;
     }
@@ -219,6 +231,12 @@ public class MimeMultipartDataFormat extends 
DefaultDataFormat {
                 Object ho = headersEnum.nextElement();
                 if (ho instanceof Header) {
                     Header header = (Header) ho;
+                    // filter Camel internal headers (Camel*) instead of 
copying them verbatim from the external
+                    // MIME headers, consistent with the inbound 
HeaderFilterStrategy applied by the mail consumer
+                    if 
(headerFilterStrategy.applyFilterToExternalHeaders(header.getName(), 
header.getValue(),
+                            camelMessage.getExchange())) {
+                        continue;
+                    }
                     camelMessage.setHeader(header.getName(), 
header.getValue());
                 }
             }
diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/dataformat/mime/multipart/MimeMultipartDataFormatTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/dataformat/mime/multipart/MimeMultipartDataFormatTest.java
index f36acfed870a..56ae3d59f2d8 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/dataformat/mime/multipart/MimeMultipartDataFormatTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/dataformat/mime/multipart/MimeMultipartDataFormatTest.java
@@ -406,6 +406,27 @@ public class MimeMultipartDataFormatTest extends 
CamelTestSupport {
         assertEquals("also there", out.getMessage().getHeader("x-bar"));
     }
 
+    @Test
+    public void unmarshalInlineHeadersFiltersCamelInternalHeaders() {
+        // Camel-internal headers (Camel*, case-insensitive) present in the 
external MIME headers must not be
+        // copied onto the Camel message; ordinary application headers still 
pass through. This matches the
+        // inbound HeaderFilterStrategy applied by the mail consumer.
+        String mime = "CamelFoo: blocked\r\n"
+                      + "camelBar: blocked\r\n"
+                      + "CAMELBaz: blocked\r\n"
+                      + "X-Normal: keep-me\r\n"
+                      + "Content-Type: text/plain\r\n"
+                      + "\r\n"
+                      + "Body text";
+        in.setBody(mime);
+        Exchange out = template.send("direct:unmarshalonlyinlineheaders", 
exchange);
+        assertNotNull(out.getMessage());
+        assertEquals("keep-me", out.getMessage().getHeader("X-Normal"));
+        assertNull(out.getMessage().getHeader("CamelFoo"));
+        assertNull(out.getMessage().getHeader("camelBar"));
+        assertNull(out.getMessage().getHeader("CAMELBaz"));
+    }
+
     @Test
     public void unmarshalRelated() throws IOException {
         in.setBody(new File("src/test/resources/multipart-related.txt"));

Reply via email to