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
menu on the right side of the field. If a file with the same name as an attachment already exists in the folder, a digit is appended to the attachment name. If no folder is selected, the attachments are saved to the project folder.
At the top of the message list, you'll see a box that says Search Current Mailbox. Click to place your cursor in that box, type hasattachments:yes, and then click Enter.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With