Import Blocklist Regex Rules

Summary: Creates blocklist rules from a file containing regular expressions.
Requires: SpamSieve


Given a file containing one regular expression per line (e.g. exported from another spam filter), this script creates blocklist rules for SpamSieve that match those regexes against the message body and subject. SpamSieve uses PCRE regular expressions.

Download in Compiled Format · Download in Text Format


set _file to my promptForFile()
set _regexes to my linesFromFile(_file)
repeat with _regex in _regexes
my makeBlocklistRulesForRegex(_regex)
end repeat

on promptForFile()
set _types to {"public.plain-text"}
set _prompt to "Choose a text file with one blocklist regex per line."
return choose file of type _types with prompt _prompt
end promptForFile

on linesFromFile(_file)
set _fd to open for access _file
set _result to read _fd using delimiter {return, ASCII character 13}
close access _fd
return _result
end linesFromFile

on makeBlocklistRulesForRegex(_regex)
tell application "SpamSieve"
set _regex to "(?-i)" & _regex -- Make case-sensitive
tell blocklist
repeat with _field in {body, subject}
set _properties to {match field:_field, match style:regex style, text to match:_regex}
make new rule with properties _properties
end repeat
end tell
end tell
end makeBlocklistRulesForRegex

Last Modified: 2013-10-23

Running the Script

You can use AppleScript Editor (AppleScript Utility prior to Mac OS X 10.6) to enable Mac OS X’s built-in Script menu. Download the compiled script file and install it in the Install Location recommended above, creating any necessary folders. To run the script, just select it from the menu. FastScripts provides a similar menu that supports keyboard shortcuts and other features.