-- Downloaded From: http://c-command.com/scripts/spamsieve/apple-mail-move-if-spam -- Last Modified: 2008-10-03 property markSpamMessagesRead : false on run global spamFolderName set spamFolderName to getStringDefault("AppleMailTrainSpamName", "Spam") tell application "Mail" set l to the selection as list repeat with m in l my processMessage(m) end repeat end tell end run on perform_mail_action(info) global spamFolderName set spamFolderName to getStringDefault("AppleMailTrainSpamName", "Spam") tell application "Mail" set selectedMessages to |SelectedMessages| of info repeat with m in selectedMessages my processMessage(m) end repeat end tell end perform_mail_action on processMessage(m) tell application "Mail" set s to source of m tell application "SpamSieve" set isSpam to looks like spam message s end tell if isSpam then my moveToSpamFolder(m) end if end tell end processMessage on moveToSpamFolder(m) tell application "Mail" try set junk mail status of m to true end try if markSpamMessagesRead then try set read status of m to true end try end if try set theAccount to (account of mailbox of m) set mailbox of m to (mailbox spamFolderName of theAccount) on error e try if not (exists mailbox spamFolderName) then make new mailbox with properties {name:spamFolderName} end if set mailbox of m to mailbox spamFolderName on error e display dialog e end try end try end tell end moveToSpamFolder on getStringDefault(theKey, defaultValue) tell application "SpamSieve" set theKeys to {theKey} set theDefaults to {defaultValue} try set {theResult} to lookup keys theKeys default values theDefaults on error set {theResult} to theDefaults end try return theResult end tell end getStringDefault