Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Applescript to delete Spam' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Applescript to delete Spam
Authored by: stormy on Apr 07, '04 07:32:13AM

Just a couple days ago, I wrote my very first Applescript just to empty spam mailboxes.

Besides using SpamSieve, I also use SpamAssasin on the server (and IMAP accounts), so all my "Spam" folders quickly get filled up with junk.

My script checks for messages on every "SPAM" mailbox" of every account and deletes them. Then checks for messages on the "Spam" mailbox "In my Mac" and deletes them. Lastly, it empties the Trash by performing the keyboard shortcut (I searched the whole Mail dictionary and couldn't find an "empty trash" command).

I'm sure the code could be greatly improved, so I welcome your suggestions!



try
	tell application "Mail"
		activate
		-- delete messages from spam mailboxes
		set theAccounts to every account
		repeat with theAccount in theAccounts
			if exists messages in mailbox "SPAM" of theAccount then
				delete messages of mailbox "SPAM" of theAccount
			end if
		end repeat
		
		if exists messages in mailbox "Spam" then
			delete messages of mailbox "Spam"
		end if
		
	end tell
	delay 3
	-- empty trash for all accounts
	tell application "System Events"
		tell process "Mail"
			set frontmost to true
		end tell
		keystroke "k" using command down
		keystroke return
	end tell
end try


[ Reply to This | # ]