Apple Mail - Block Reply-To

Summary: Adds a rule to SpamSieve’s blocklist for the selected message’s Reply-To.
Requires: SpamSieve, Apple Mail
Install Location: ~/Library/Scripts/Applications/Mail
Last Modified: 2025-02-25

Description

This script is not intended for most customers because the “Train as Spam” command already blocks senders.

Normally, when you train a message as spam, SpamSieve will create blocklist rules for the sender name and address and also train SpamSieve’s Bayesian classifier. This script is for blocking messages based on the Reply-To header, which can be useful if the message is generated by a Web form on your own server where the From address is fixed and the Reply-To is set based on information entered into the form. It is not a substitute for training spammy messages as spam.

Installation Instructions · Download in Compiled Format · Download in Text Format

Script

on run
    tell
application "Mail"
        set
_messages to the selection as list
        my
processMessages(_messages)
    end tell
end
run

on
processMessages(_messages)
    try
        repeat with
_message in _messages
            my
processMessage(_message)
        end repeat
    on error
_errorMessage number _errorNumber
        tell
application "SpamSieve"
            
add log entry source "com.c-command.spamsieve.apple-mail.script.block-reply-to" error number _errorNumber message _errorMessage
        end tell
    end try
end
processMessages

on
processMessage(_message)
    tell
application "Mail"
        set
_address to extract address from _message's reply to
    end tell
    tell
application "SpamSieve"
        tell
blocklist
            
-- SpamSieve automatically prevents duplicate rules
            
make rule with properties {text to match:_address, match field:reply to field, match style:exact style}
        end tell
    end tell
end
processMessage