Mail applescript not working

I ran into the exact same problems as the OP. I just bought DEVONthink 3 Pro to automate my incoming emails to be sent to DEVONthinks inbox so I have all my incoming (electronic) mail in one place. But first, I got confused by the names starting with “Add” and “File” like the OP – it seems they both mean “Add”, they just create different file types. I think the wording could be improved here.

Next, I ran into an issue with Apple Mail itself (where we have to blame Apple) where when I was trying to apply a rule that both moved a message to a specific folder and ran a DEVONthink script, the script seemed not to work. I’m guessing because Apple mail did the “move” first (even though I didn’t set up to be first) and then the paths were broken. But I found an easy workaround (which is the main reason I’m writing this message), let me share:

Instead of relying on an Apple rule to do both actions (send to DEVONthink & move/delete email), you can simply do both in the AppleScript. To do that, open the folder containing the AppleScript files from DEVONthink – Apple provides a neat shortcut button “Open in Finder” in the dropdown, see screenshot:

Then duplicate the AppleScript you would like to adjust, rename it (I called it Send to DEVONthink Inbox & move to @DEVONthink mailbox), double-press to open the Script Editor and add the following line right before the closing end repeat of the repeat with theMessage in theMessages body (it’s the last end repeat in my case):

set mailbox of theMessage to mailbox "<YOUR_FOLDER_NAME>" of account "<YOUR_ACCOUNT_NAME>"

Don’t forget to replace <YOUR_FOLDER_NAME> and <YOUR_ACCOUNT_NAME> with the proper names in your case, e.g. with the folder named @DEVONthink and an account names Gmail it would be:

set mailbox of theMessage to mailbox "@DEVONthink" of account "Gmail"

Here’s a screenshot of what it looks like in full:

If you simply want to delete the email, you might want to use the delete command, but @Blanc strongly recommends against this here below. Instead, it’s safer to move mails you want to delete to some “Trash” folder with the above method.

Hope it helps.