7

I have a Java Maven project and I use org.apache.camel to obtain mail and attachment information.

<dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-mail</artifactId>
        <version>2.17.0</version>
</dependency>

Given an Exchange object I use this code to get the attachments:

Message message = exchange.getIn().copy();
message.getAttachments()

Where messageCopy.getAttachments() returns a Map<String, DataHandler> that maps attachment-file-Name to DataHandler.

This code works when the mail has a single attachment or attachments that are named differently. When I have two attachments with the same name it follows that, due to the map structure, only one is returned (the other is simply overwritten).

Does anyone have the same problem and/or know another method to get two (or more) homonymous attachments?

Thanks

Ale
  • 946
  • 4
  • 17
  • 28
  • 3
    the problem is more upstream, when you retrive the `Exchange` object; I suggest looking at this class: `MailBinding.java` in `org.apache.camel.component.mail` package, between lines 331 and 342 – Nicomedes E. Jan 13 '18 at 12:57

1 Answers1

1

I remembered to have faced this problem in my previous project. I think the workaround was to split the original message into N separate messages so that you can handle each of them, even if having the same name.

Take a look at the Camel SplitAttachmentsExpression. An existing unit test can be found here.

TacheDeChoco
  • 3,683
  • 1
  • 14
  • 17