I recently switched to a Mac and I wanted a way to report spam to the spam filter from Mail.app, and then delete it from the spam folder. After a lot of research, and trial and error, I developed the attached script.
What it does:
Whenever the script is run, it sends all of the messages in the global Junk folder as attachments to the listed spam account. Each message is saved to a temporary folder in your home folder, attached to the reporting message, and then sent. This folder is deleted at the end. (It only sends one message per run of the script.)
After the message is sent, the original junk messages are deleted (permanently - not sent to the Trash). The spam training sent message is also deleted.
If for some reason the message cannot be sent, or the sent message cannot be deleted, the script will notify the user. Sometimes (I haven't figured out why) the sent message isn't deleted, and there is no message. This is pretty rare, however. The message should automatically be deleted the next time the script is run.
Also included is a variation that marks false-positives as not-spam, sends them off to Zimbra, and moves them to the inbox. You have to select individual messages for this one to work.
How to install it
- It's best if you have the AppleScript menu bar item visible. Start the AppleScript Utility (Applications/AppleScript/AppleScript Utility) and check the "Show Script menu in menu bar" option. ( I also recommend unchecking "Show Computer scripts".)
- Now, start Mail, and click on the new Script icon in the menubar.
- Choose Open Scripts Folder > Open Mail Scripts Folder.
- Uncompress the attached file into this folder. It should create two files.
- Open up the Empty Junk Mail script, and edit the first line to match your spam account.
- Repeat with the Mark as not Junk Mail script, but using your ham/not-spam account.
How to use it
Simply have Mail as the foreground app, and click on the Script menu, and Empty Junk Mail.
As an option, I recommend installing Butler, which will allow you to assign a shortcut to the script. I leave this as an exercise for you. It's a bit involved, but it is nice to be able to type Command+J and have the junk mail emptied.
Let me know if this is useful for you!
(Note: this is designed so that once you edit the accounts, you can easily copy this script to multiple computers, as long as they use the same Zimbra account. It doesn't ever need the username, etc.)