Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read multiple attachments with same file name

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

like image 553
Ale Avatar asked Jan 11 '18 13:01

Ale


People also ask

What happens if the files saved in the specified folder have the same name as the email attachments in Uipath?

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.

Can you view all attachments in Outlook at once?

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.


1 Answers

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.

like image 191
TacheDeChoco Avatar answered Oct 20 '22 23:10

TacheDeChoco