Rules Scripting Sample

Summary: Demonstrates how to control SpamSieve’s rules using AppleScript.
Requires: SpamSieve
Install Location: ~/Library/Scripts/SpamSieve Scripts/
Last Modified: 2020-07-16

Description

This script demonstrates how to control SpamSieve’s blocklist and whitelist using AppleScript.

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

Script

tell application "SpamSieve"
    
    
-- Prune unused blocklist rules; this will be very slow if there
    
-- are lots of rules, so you might want to use a "with timeout" block.
    
-- It would be faster to do this using the the Blocklist window.
    
tell blocklist
        
delete (every rule whose hits is 0)
    
end tell
    
    
-- Look up a rule by its text and enable it
    
tell whitelist
        
-- there may be more than one rule with this text
        
set l to every rule whose text to match is "foo@bar.com"
        
set r to item 1 of l
        
set r's isEnabled to true
    
end tell
    
    
-- Makes a new blocklist rule that matches messages with zip
    
-- attachments.
    
tell blocklist
        
make rule with properties {text to match:".zip", match field:any attachment name, match style:ends with style}
    
end tell
    
    
-- Easily make blocklist rules that match the From address.
    
tell blocklist
        
add sender rules for addresses {"foo@bar.com", "foo@baz.com"}
    
end tell
    
end tell