-- Import-Export Rules -- https://c-command.com/scripts/spamsieve/import-export-rules -- Summary: Demonstrates how to import and export SpamSieve’s rules via AppleScript. -- Requires: SpamSieve -- Install Location: wherever -- Last Modified: 2019-05-24 on run tell application "SpamSieve" set importScript to "tell application \"SpamSieve\"" & return set importScript to importScript & "tell blocklist" & return set importScript to importScript & my makeRules(blocklist, ends with style, "ends with style", from field, "from field") set importScript to importScript & my makeRules(blocklist, starts with style, "starts with style", from field, "from field") set importScript to importScript & my makeRules(blocklist, regex style, "regex style", from field, "from field") set importScript to importScript & "end tell" & return set importScript to importScript & "end tell" set the clipboard to importScript end tell end run on makeRules(theList, theStyle, theStyleText, theField, theFieldText) tell application "SpamSieve" tell theList set theResult to "" set theRules to get every rule whose match style is theStyle and match field is theField repeat with r in theRules set theResult to theResult & my makeRule(r's text to match, theStyleText, theFieldText) end repeat end tell end tell return theResult end makeRules on makeRule(theText, theStyle, theField) return "make rule with properties {text to match: " & my escape(theText) & ", match field: " & theField & ", match style: " & theStyle & "}" & return end makeRule on escape(theText) set bs to "\\" set q to "\"" set theText to my replace(theText, bs, bs & bs) set theText to my replace(theText, q, bs & q) return q & theText & q end escape on replace(theText, searchText, replaceText) set AppleScript's text item delimiters to searchText set i to text items of theText set AppleScript's text item delimiters to replaceText return i as string end replace