February 25, 2014

The
save attachments action replaces the existing file if another one with the same name is found. This may be an advantage for some set ups but if you process email attachments that come from different senders this is probably something you don’t like. For example, the file photo.jpg attached in an email from john@gmail.com and the file photo.jpg from eva@gmail.com must be separately processed because they are indeed different photos. We do not want Eva to replace the photo previously sent by John.
To solve this issue the most simple way is to create a different folder for each sender and save the attached file there. The left panel configuration you see on the top of this blog post briefly shows how to do it. This is step-by-step what is done:
1.- Download all the new emails from test@emailparser.com
2.- Remove from the sender address any characters that may not be suitable for a folder name. These characters are: /|<>:?*. The sender email address probably will not contain any of them but just in case it happens we filter them.
3.- Then we create a folder with the email address name. If the folder already exists it is not a problem. The process will continue normally.
4.- We save the attachments of the email to the created folder.
5.- And finally, for each attached file in an email, we will create a database row containing the sender address and the file path. This database operation will fire the processing of the file but this is not something that Email Parser does in this example.
The result looks like this:

If you need more details of the specific configuration of each item of the left panel here are the screenshot for your reference:

Removing invalid characters from the email address

Creating a new folder for the attached files

Saving the attachments from a received email

Repeat the following actions from each value at the attachment field

Updating the database with the attached file path