Apple Mail - Move If Spam
Summary: Of the selected messages, moves the spam ones to the Spam mailbox.
Requires: SpamSieve, Apple Mail, Panther
Install Location: ~/Library/Scripts/Mail Scripts/ on Panther or ~/Library/Scripts/Applications/Mail on Tiger
Description
Normally, to re-apply SpamSieve to a bunch of selected messages, you would use the Apply Rules command. This script is for when you want to re-apply SpamSieve without applying all the other rules.
Download in Compiled Format · Download in Text Format
Script
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 getStringDefaultLast Modified: 2010-11-27