
This is a known bug that has been reported for years over multiple OS X and MacOS versions. I should have been a bit clearer: the issue is related to obtaining and saving attachments to mail message via AppleScript. I am not convinced that the script quality is the issue. I hope this workflow is for the followup.
AUTOMATICALLY EMAIL NEW FILES IN A FOLDER PDF
I also take the mail pdf as “email”, the raw file as “rawemail” and each attachment as “attachment.” If there are attachments I also add a “hasattachment” tag to the mail pdf. Based on the account it came from I assign a tag to each file.

Check for the error codes and display error messages and quit.
AUTOMATICALLY EMAIL NEW FILES IN A FOLDER CODE
Return from the script the accountName found above (or an error code if there is a problem, like more than one message selected). Use AppleScript to find the current selected message (make sure there is only one) and write the entire message content to a file on the Desktop.I tie the entire thing together in a Keyboard Maestro macro (that I will likely post on the MPU forum once I have a bit of time. Where theMessage is the selected message in Mail.app. Set accountName to the name of the account of the mailbox of theMessage To be able to sort the email messages, from AppleScript I use: I name the files using the format YYYY-MMDD_MD5_filename where YYYY-MMDD is the date the mail was sent, MD5 is the MD5 hash of the entire mail content (that makes sure that all saved files are unique to the email message, and filename is the filename for the attachment. My approach is to save the entire email message (the raw content) to a file and run a python script that pulls out the attachments and saves them to disk. This problem has existed for years and never been fixed by Apple, and for that reason my workflow for saving emails is NOT based on using AppleScript to save the attachments. I have found that Mail.app’s AppleScript support is highly flakey, especially when it comes to saving attachments reliably.
