AppleScript to Send Mail to spam@uce.gov, Move to Spam-Learning Folder

Okay, the title of this is pretty darn long, but I’m writing for Google. 🙂

Back some time ago, I saw this AppleScript to forward spam to the FTC via Mail and liked the concept. It makes me at least feel like I’m doing something, you know? [Probably not much; I’m a government contractor, so I know what government might not do well.] I adapted it to report PayPal phishing attempts to spoof@paypal.com, and well, that was really it. My main change was in deleting the email after sending the mail on forward.

Now that Fastmail provides a spam-learning option for folders, I’m wanting to improve its spam filters. It already does a solid job—most of the spam I get goes into Junk Mail. However, I do get false positives, so I didn’t want Junk Mail to become the spam-learning folder. I then devised this concept:

  1. Create a folder called ConfirmedJunk and set it in Fastmail’s Web interface to be a spam-learning folder. I also set this folder to auto-purge every month to keep my quota use down.
  2. Rework my AppleScripts to go from deleting the junk mail to putting in ConfirmedJunk.
  3. There is no step 3.

Well, it took a little while banging my head on this tonight, but here’s what I came up with:

tell application "Mail"
	set theMessages to the selection
	repeat with thisMessage in theMessages
		set newMessage to make new outgoing message at end of outgoing messages
		tell newMessage
			set content to thisMessage's source
			set subject to thisMessage's subject
			make new to recipient with properties {address:"spam@uce.gov"}
		end tell
		send newMessage
		set read status of thisMessage to true
		move thisMessage to mailbox "INBOX/ConfirmedJunk" of account "[$account]"
	end repeat
end tell

The above is “spam_uce_gov.scpt“.

tell application "Mail"
	set theMessages to the selection
	repeat with thisMessage in theMessages
		set newMessage to make new outgoing message at end of outgoing messages
		tell newMessage
			set content to thisMessage's source
			set subject to thisMessage's subject
			make new to recipient with properties {address:"spoof@paypal.com"}
		end tell
		send newMessage
		set read status of thisMessage to true
		move thisMessage to mailbox "INBOX/ConfirmedJunk" of account "[$account]"
	end repeat
end tell

That’s “spam_paypal_com.scpt“.

Use ’em if you can. Be sure to put the name of the account in there as Mail knows it and change the folder name as appropriate. I will not know the specifics of your setup unless you mirror mine. This script is provided free of charge and is unsupported.

6 Jun 2010: The scripts shown in this post have been superseded by a more recent update.