Greetings. I am using version. 3.1.1 on a Mac with system 15.4.1 and Mail Version 16.0. The mail filtering is working fine, but I would like to know if it is possible to filter spam with SpamSieve before applying my own rule which forwards the mail to a second account.
I don’t want the spam mail to reach that second account but right now, Mail sends the mail before SpamSieve filters it.
You could save this script in the folder ~/Library/Application Scripts/com.apple.mail and then change your rule’s action to Run AppleScript and select this script, and then it will forward only the good messages. You will need to specify the destination address towards the bottom of the script.
on run
tell application "Mail"
set _messages to the selection as list
my processMessages(_messages)
end tell
end run
using terms from application "Mail"
on perform mail action with messages _messages
-- This is executed when Mail runs the rule.
my processMessages(_messages)
end perform mail action with messages
end using terms from
on processMessages(_messages)
repeat with _message in _messages
try
my processMessage(_message)
on error _errorMessage
my logToSpamSieve("Error processing message: " & _errorMessage)
end try
end repeat
end processMessages
on processMessage(_message)
tell application "Mail"
set _source to source of _message
end tell
tell application "SpamSieve"
set _origin to {source identifier:"com.c-command.spamsieve.apple-mail.forward-good-messages"}
set _score to score message _source origin _origin with suppressing notification without auto training
end tell
if _score ≥ 50 then
return -- Stop processing
end if
my processGoodMessage(_message)
end processMessage
on processGoodMessage(_message)
tell application "Mail"
-- Seems to be macOS bug where it opens the window, anyway
set _newMessage to forward _message without opening window
tell _newMessage
make new to recipient with properties {address:"insert your destination address here"}
end tell
send _newMessage
end tell
end processGoodMessage
on logToSpamSieve(_string)
try
tell application "SpamSieve"
add log entry source "com.c-command.spamsieve.apple-mail.forward-good-messages" message _string
end tell
end try
end logToSpamSieve