Import Blocklist Regex Rules
Summary: Creates blocklist rules from a file containing regular expressions.
Requires: SpamSieve
Last Modified: 2019-10-02
Description
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.
Installation Instructions · Download in Compiled Format · Download in Text Format
Script
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