SieveRecipes

From FastMailWiki

Jump to: navigation, search

All below recipes end with a 'stop;' which implies that the appropriate action (fileinto, reject, redirect) will be final and no further processing will take place. All recipes should be preceded with a require clause, e.g. (overkill but will work for all examples below):


require ["reject", "fileinto", "comparator-i;ascii-numeric", "relational", "imapflags"];


  • File all messages from a recipient into a folder
if address :is "From" "pal@mypals.org" {
  fileinto "INBOX.My Best Pal";
  stop;
}


  • File all messages from a domain into a folder
if address :domain :is "From" "mypals.org" {
  fileinto "INBOX.Pals";
  stop;
}


  • File all undefined addresses at a virtual domain into a folder

This recipe is useful when: you have defined a catch-all address, you only have a handful of "legitimate" addresses within your virtual domain, but nonetheless you want to preserve everything that comes there - just in case.

if allof(
  address :domain :is "X-Delivered-To" "mydomain.info",
  not address :localpart :is "X-Delivered-To" ["address1", "address2", "address3"] # these are valid addresses
) {
  fileinto "INBOX.Possible spam";
  stop;
}


  • File messages to some aliases into alias-dependent folders. We don't really read the mailing list that comes to alias2, hence, we'll be marking it as read right away. Redirect everything else to another account without keeping it in INBOX
if address :is "X-Delivered-To" "alias1@fastmail.fm" {
  fileinto "INBOX.alias1";
  stop;
} elsif address :is "X-Delivered-To" "alias2@sent.com" {
  setflag "\\Seen";
  fileinto "INBOX.alias2";
  stop;
} elsif address :is "X-Delivered-To" "alias3@eml.cc" {
  fileinto "INBOX.alias3";
  stop;
}

redirect "another@account.net";


  • Backup everything to a backup account. Keep the original messages at FM.
redirect "backup@gee-mail.com";
keep;


  1. The first line discards anything with a score >= 20 (canned spam).
  2. The second line puts anything with 20 > score >= 8 (fairly spam) into a subfolder of spam called spam.
  3. The third line puts anything with a score < 8 (potential Ham) into a subfolder of INBOX called spam.

Note the addition to the require statement.

require ~[..., "comparator-i;ascii-numeric"];

if  header :value "ge" :comparator "i;ascii-numeric" ["X-Spam-score"] ["20"]  {
  discard;
  stop;
}
if  header :value "ge" :comparator "i;ascii-numeric" ["X-Spam-score"] ["8"]  {
  fileinto "INBOX.spam.spam";
  stop;
}
if  header :value "ge" :comparator "i;ascii-numeric" ["X-Spam-score"] ["4"]  {
  fileinto "INBOX.spam";
  stop;
}


  • Discard messages containing potentially dangerous attachments
if header :contains "x-attached"
  [".exe",".bat",".js",".com",".cmd",".ini",".dll",".bas",".cpl",".drv",".inf",".sys",".pif"] {
  discard;
  stop;
}


  • filter messages addressed to sent@domain.com into "Sent Items" folder and mark them as "read". Useful if you want to save messages sent from outlook into your imap folder - just bcc all outgoing messages to sent@domain.com
require ["envelope", "fileinto", "reject", "vacation", "regex", "relational", "comparator-i;ascii-numeric", "imapflags"];

if header :is ["X-Delivered-to"] "sent@domain.com" {
  setflag "\\Seen";
  fileinto "INBOX.Sent Items";
}


if header :contains ["SPAM", "X-Spam-hits"] ["BAYES_40", 
                                             "BAYES_44", 
                                             "BAYES_50", 
                                             "BAYES_56", 
                                             "BAYES_60"]
{
  fileinto "INBOX.Junk Mail";
  stop;
}


  • Avoid filtering any messages that are from "known senders" (contacts that are in your address book) or from domains that you have decided are safe.
if not anyof(
  header :contains ["X-Spam-known-sender"] "yes",
  header :contains ["from"] ["amazon.co.uk", "myworkdomain.com"]
) {
  # ...filtering code goes here...
}
Personal tools