/* Example: "real-sieve" This example illustrates a possible real-world script that utilizes many SIEVE language features. */ sieve { /* Open the sieve block */ /* Enable some of the extended capabilities used in this script. */ require [ "fileinto", "editheader", "dnsbl" ]; require [ "relational", "comparator-i;ascii-numeric" ]; /* Why not start out with this false test so all the other "real" tests can be added with "elsif" */ if false { keep; } /* If you are subscribed to mailing lists, it's STRONGLY recommended that you "whitelist" them all. You don't want to be checking mail that you subscribed to and possibly missing some messages as a result. Some mailing list mail we file into separate folders, and some we just file into the inbox. */ /* Some "entertainment" lists */ elsif anyof ( header :contains ["to", "cc"] "BoneheadOfTheDayAward@yahoogroups.com", header :contains "from" ["Aiken@AikensLaughs.com", "twisted@verbose.twistedhistory.com"], address :is "Sender" "TheCameronColumn@letters.webvalence.com" ) { fileinto "Entertainment"; } /* "slashzot" into its own folder */ elsif header :contains "X-Mailing-List" "slashzot@delorie.com" { fileinto "slashzot"; } /* "inet-access" into its own folder */ elsif header :contains ["to", "cc"] "inet-access" { fileinto "inet-access"; } /* We want these mailing lists delivered right into the inbox */ elsif anyof ( header :contains "List-Post" ["bsdi-users@mailinglists.org", "bugtraq@securityfocus.com", "cisco-nsp@puck.nether.net"], header :is "Sender" "owner-nanog@merit.edu" ) { keep; } /* It's also a great idea to "whitelist" mail matching some other criteria too. This would include mail from known senders and mail to important addresses. */ elsif anyof ( address :localpart :is "From" [ "fred", "barney" ], address :is "from" "betty@example.com", address :localpart :is "To" ["abuse", "mvmf-bug", "postmaster"] ) { keep; } /* Discard some known bad mail. For example, I keep getting mail addressed to old domain names like "granite.mv.net" -- domain names used by spammers. Some other patterns should be self-explanatory. */ elsif anyof ( address :domain :is "Delivered-To" [ "granite.mv.net", "gold.mv.net" ], address :is "From" "big@boss.com", header :matches "Subject" [ "*v?agra*", "adv:*" ] ) { discard; } /* We can now test this message against various DNSBLs. It's filed into a "dnsbl" folder for review, but this could be simply discarded as well. */ elsif anyof ( dnsbl ["spamcop", "spamhaus"] "std", dnsbl "njabl" "*") { addheader "X-Spam-Reason" "dnsbl"; fileinto "Caught Spam"; } /* Mail without a "To" line is probably spam, but file it for later checking. */ elsif not exists "To" { addheader "X-Spam-Reason" "No TO line"; fileinto "Caught Spam"; } /* I'm not fond of people agreeing to send me advertisements in their mail just so they can get a free mailbox. Delete some of these sources (note that you can still whitelist some known sources before getting to this step). */ elsif address :domain :is "From" ["hotmail.com", "yahoo.com"] { addheader "X-Spam-Reason" "advbox"; fileinto "Caught Spam"; } /* Mail with a humungous number of recipients is also likely spam, but we'll file it and have a look at it. */ elsif address :comparator "i;ascii-numeric" :count "gt" ["to", "cc"] "20" { addheader "X-Spam-Reason" "Too many recipients"; fileinto "Caught Spam"; } /* Let "implicit keep" deal with mail not otherwise filtered. */ }