Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@
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;
Expand All @@ -72,6 +74,7 @@ public class MimeMultipartDataFormat extends DefaultDataFormat {
private String includeHeaders;
private Pattern includeHeadersPattern;
private boolean binaryContent;
private final HeaderFilterStrategy headerFilterStrategy = new DefaultHeaderFilterStrategy();

public String getMultipartSubType() {
return multipartSubType;
Expand Down Expand Up @@ -282,6 +285,12 @@ private void copyNonStandardHeaders(MimeBodyPart mimeMessage, Message camelMessa
while (headersEnum.hasMoreElements()) {
Object ho = headersEnum.nextElement();
if (ho instanceof Header header) {
// 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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,27 @@ public void marhsalUnmarshalInlineHeaders() throws IOException {
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"));
Expand Down
Loading