TheThen save this script (assuming you are using 10.8 Mountain Lion. ) In the folder ~/Library/Application Scripts/com.apple.mail/
(assuming you are using 10.8 Mountain Lion. ) In the folder ~/Library/Application Scripts/com.apple.mail/
Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack ExchangeStack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Explore Stack InternalTheThen save this script (assuming you are using 10.8 Mountain Lion. ) In the folder ~/Library/Application Scripts/com.apple.mail/
(assuming you are using 10.8 Mountain Lion. ) In the folder ~/Library/Application Scripts/com.apple.mail/
The save this script
(assuming you are using 10.8 Mountain Lion. ) In the folder ~/Library/Application Scripts/com.apple.mail/
Then save this script (assuming you are using 10.8 Mountain Lion. ) In the folder ~/Library/Application Scripts/com.apple.mail/
First create a rule that looks for ANY of the Manifest in all of the variations or DSR
Like So:

The save this script
using terms from application "Mail" on perform mail action with messages theMessages for rule theRule set codeList to {"CV", "VS", "SAA", "TK", "DHV", "LH"} set subFolder to "" set theDate to do shell script "date +%Y_%m_%d_%H%M%S" --set ruleName to name of theRule -- The folder to save the attachments in (must already exist) tell application "Finder" to set attachmentsFolder to ((path to home folder as text) & "Dropbox:DSR") as text tell application "Mail" repeat with eachMessage in theMessages set theSubject to subject of eachMessage repeat with i from 1 to number of items in codeList set this_item to item i of codeList if theSubject contains this_item then set subFolder to this_item end if end repeat if (count of (eachMessage's mail attachments)) > 0 then try tell application "Finder" if not (exists folder subFolder of folder attachmentsFolder) then make new folder at attachmentsFolder with properties {name:subFolder} end if end tell -- Save the attachment repeat with theAttachment in eachMessage's mail attachments set originalName to name of theAttachment set savePath to attachmentsFolder & ":" & subFolder & ":" & originalName tell application "Finder" if (exists file originalName of folder subFolder of folder attachmentsFolder) then set savePath to attachmentsFolder & ":" & subFolder & ":" & theDate & "_" & originalName end if end tell try save theAttachment in file (savePath) end try end repeat end try end if end repeat end tell end perform mail action with messages end using terms from (assuming you are using 10.8 Mountain Lion. ) In the folder ~/Library/Application Scripts/com.apple.mail/
And point the Run Applescript at it.
If you are using an earlier Mac OS. Then you should be able to place the script where ever you want.
Thats it.
My tests all have worked. But it is late here and I should be in bed. So let me know if any issues and I will try and sort. :-)
The one thing to note is I have added a time stamp instead of a number for same named files. It is more reliable.