require "fileinto"; # Based on a script from http://blog.websitetodos.com . # Section 1 # --------- # Override the defaults to throw away mail to any addresses that have been abused. # If you have "reject" capability you could use this instead if you want to make # it clear you've blocked the address and give a reason. if header :contains ["Envelope-To", "Delivered-To", "X-Delivered-To", "X-Envelope-To", "X-SMTP-To", "X-RCPT", "X-RCPT-to", "X-Real-To", "X-Original-To", "X-Pop3-Rcpt", "Apparently-To"] ["spammed_add1@domain.tld", "sold_add1@domain.tld"] { discard; # Section 2 # --------- # Now set up the default rules for mail matching the form mainpart+suffix@anydomain.tld } elsif header :matches ["Envelope-To", "Delivered-To", "X-Delivered-To", "X-Envelope-To", "X-SMTP-To", "X-RCPT", "X-RCPT-to", "X-Real-To", "X-Original-To", "X-Pop3-Rcpt", "Apparently-To"] "*+abc@*" { # Keep any email whose localpart (part before "@") ends in "+abc" in the default folder (probably INBOX) keep; } elsif header :matches ["Envelope-To", "Delivered-To", "X-Delivered-To", "X-Envelope-To", "X-SMTP-To", "X-RCPT", "X-RCPT-to", "X-Real-To", "X-Original-To", "X-Pop3-Rcpt", "Apparently-To"] "*+def@*" { # File any email whose localpart ends in "+def" in the businesses folder. fileinto "Businesses"; } elsif header :matches ["Envelope-To", "Delivered-To", "X-Delivered-To", "X-Envelope-To", "X-SMTP-To", "X-RCPT", "X-RCPT-to", "X-Real-To", "X-Original-To", "X-Pop3-Rcpt", "Apparently-To"] "*+xyz@*" { # File any email whose localpart ends in "+xyz" in the mailing list folder. fileinto "Lists"; # Section 3 # --------- # Now set up rules for any preexisting or special address that do not match the above form. } elsif header :contains ["Envelope-To", "Delivered-To", "X-Delivered-To", "X-Envelope-To", "X-SMTP-To", "X-RCPT", "X-RCPT-to", "X-Real-To", "X-Original-To", "X-Pop3-Rcpt", "Apparently-To"] ["family_add1@domain.tld", "friends_add1@domain.tld"] { # File friends and family and preexisting personal addresses. keep; } elsif header :contains ["Envelope-To", "Delivered-To", "X-Delivered-To", "X-Envelope-To", "X-SMTP-To", "X-RCPT", "X-RCPT-to", "X-Real-To", "X-Original-To", "X-Pop3-Rcpt", "Apparently-To"] ["business1@domain.tld", "business2@domain.tld"] { # File preexisting addresses that have been given to businesses. fileinto "Businesses"; } elsif header :contains ["Envelope-To", "Delivered-To", "X-Delivered-To", "X-Envelope-To", "X-SMTP-To", "X-RCPT", "X-RCPT-to", "X-Real-To", "X-Original-To", "X-Pop3-Rcpt", "Apparently-To"] ["list1@domain.tld", "list2@domain.tld"] { # File preexisting addresses that have been given to mailing lists. fileinto "Lists"; # Section 4 # --------- # Anything else file into a suspect folder or discard depending on how suspicious/reliant on your email you are. } else { fileinto "Unfiltered"; # Check this regularly for valid email addresses that you have not included above. # discard; # Uncomment this line, and comment the line above, if you are happy to discard other mail. }