Filtering Email with Sieve

Sieve is a mail filtering language for our IMAP based mail. It allows you to delete, file, forward, etc email based on attributes such as sender or subject. It provides pretty much the same functionality as procmail, with the exception of "pipes". You cannot run arbitrary programs on the mail server from sieve. This restriction is in place to make the mail server more reliable.

To filter mail with sieve, edit the file /stage/sieve/YourUserName.

Our spam tagger tags email messages with stars if it thinks the message may be spam. The more stars, the more confident the system is that the message really is spam.

For this example to work, you must first use your email client to create the folders that the fileinto directives use.

###########################################################
require "fileinto";
require "reject";

# SpamAssassin is pretty confident this is spam: delete the message if header :contains "X-Spam-Level" "**********" { discard; stop; }

# SpamAssassin thinks this might be spam: file the message into # folder "spam" if header :contains "X-Spam-Level" "******" { fileinto "spam"; stop; }

# If the subject contains the word 'baby', file the message into # the folder 'ian'. if header :contains "Subject" "baby" { fileinto "ian"; stop; }

# File mail from someone@yahoo.com into folder 'friends': if header :is "From" "someone@yahoo.com" { fileinto "friends"; stop; }

# If mail is not specifically addressed to me, file the message # into the folder "junk" if anyof ( not address :all :contains ["To", "Cc", "Bcc"] "myname@cs.uchicago.edu" ) { fileinto "junk"; stop; }

# Here is a more complex example to demonstrate nesting: if header :contains "To" [ "joe@cs.uchicago.edu", "some_mail_list@cs.uchicago.edu" ] { if header :contains "Subject" [ "Undelivered Mail Returned to Sender", "Mail delivery failed: returning message to sender", "Returned mail: see transcript for details" ] { discard; stop; } }

# Any message that makes it to here goes into the IMAP INBOX ############################################################

Here are more sieve examples, and you can learn about sieve at the sieve RFC

As soon as you edit the /stage/sieve/YourUserName file, the IMAP server will begin using it. You can check the syntax of that file on our Linux machines:

sieve_checker -v /stage/sieve/YourUserName

Note: no output from this command means no errors were detected in your script.