Skip to main content

How do I configure ENCS email delivery with SIEVE?

What is SIEVE?

SIEVE is a standards-compliant mail processing language (IETF RFC 5228) that you can use to specify how to file your mail, discard it, forward it, autorespond, and so on. The ENCS mail reading (IMAP) and delivery system, Dovecot, contains the Pigeonhole SIEVE interpreter.

Also, ManageSieve is a protocol that allows the management of user SIEVE scripts by software, and this protocol is supported by both Pigeonhole and by Horde Webmail using the Horde Ingo front end to manage SIEVE scripts.

Thus, it is possible (and recommended!) to manage your SIEVE mail filtering rules entirely via the user-friendly ENCS webmail interface.

If you'd rather edit your SIEVE rules manually, you can find a clear introduction to SIEVE syntax at:
http://help.altn.com/securitygateway/en/sieve_creating_scripts.html

Documentation

You can configure SIEVE in a user-friendly way using webmail; just select "Mail" from the top menubar, then "Filters" from the resulting drop-down menu, then you can edit your mail automation settings. There is online help within Webmail; simply select the question mark icon to access the help topics.

The listed rules are applied in order, though any rules that are marked "disabled" are skipped. You can enable and disable rules by selecting the "x" or checkmark next to the rule. You can edit the rules by first clicking on a rule's name, then changing the fields in the new page presented to you at that point.

Webmail supplies several standard rules, but you can create arbitrarily complex rules of your own by selecting "New Rule" at the top left.

If you need to change the order of the rules, you can drag them up and down. This is important, as rules are applied in order, and a "stop" command in one rule will prevent any subsequent rules from being invoked.

In Webmail, get into the mail filters editor via top menubar "Mail", then "Filters" from the drop-down menu. Select the "Spam Filter" rule if it is present, or select "Spam" from the left sidebar menu. Select a spam level (in our environment, a value between 5 and 8 makes the most sense), and tell the system which folder to put spam messages into.

If you prefer to delete messages tagged as spam instead of just refiling them (which we don't recommend, by the way), you can do it by setting up a custom rule which examines the header "X-CU-Score-Spam", looks for the text "********" (or however many asterisks you want based on the spam level, again 5 to 8 are best), and requesting action "Delete message completely".

Yes, you can temporarily disable your mail processing without losing the settings, and then enable it again later.

In Webmail, get into the mail filters editor via top menubar "Mail", then "Filters" from the drop-down menu. Then use the "x" or checkmark icon next to each rule to enable or disable each one as you wish.

Probably yes. Webmail defaults to setting up rules in this order:

  • whitelist
  • vacation
  • blacklist
  • spam filter
  • forward

but this doesn't always make sense, since filing whitelisted messages first prevents them from receiving your vacation message (which probably isn't what you meant), and filing blacklisted messages after vacation processing means that you may be sending your vacation message to addresses you probably don't want to communicate with.

We recommend this order instead:

  • blacklist: first, refile known unwanted messages
  • vacation: autorespond to anything else if appropriate
  • whitelist: now save your whitelisted people from the spam filter
  • spam filter: refile likely spam
  • forward: if forwarding, you probably want to avoid forwarding spam and blacklisted addresses, but turn off your whitelist, otherwise those messages won't be forwarded.

In any case, think about the action taken by each rule that you enable, and whether processing stops after that rule matches, and then organize your rules in the most logical order for you.

If you receive a lot of mail and tend to go over quota in your INBOX, you may want to change your mail delivery to another folder, as folders other than INBOX live on your home directory, and benefit from a larger quota.

To change which folder to deliver mail to: in Webmail, get into the mail filters editor via top menubar "Mail", then "Filters" from the drop-down menu. Click on "New Rule" in the left sidebar menu to create a custom rule (perhaps name it "Default Mailbox"), requesting that messages with "size" "greater than" "1" (in other words, all messages) be filed into (for example) "Incoming_mail".

This rule should be the last one in the list of rules; drag it if necessary.

Note that since the new Webmail doesn't have a concept of "default mailbox", then any rule that should file to your preferred mailbox will have to be set up to file into that folder explicitly ("Deliver to folder...") instead of into the regular inbox ("Deliver into my inbox").  Also, "forward with keep" will not work as you expect; please see the "Forwarding your mail" section below.

In Webmail, get into the mail filters editor via top menubar "Mail", then "Filters" from the drop-down menu. Select the rule called "Vacation", or, if not present, the "Vacation" item in the left sidebar menu.

Set up the subject line and body ("reason") for your vacation message. It's up to you whether or not you want to set start and end dates for autoresponses - if you don't, you can still enable and disable the vacation rule manually whenever you like. Be sure to set both start and end dates, or neither; if you set just one of them, things won't work correctly.

Don't forget to enable the rule once you're done (if you're ready to start autoresponses, or if you've set start and end dates).

In Webmail, get into the mail filters editor via top menubar "Mail", then "Filters" from the drop-down menu. Select the rule called "Blacklist", or, if not present, the "Blacklist" item in the left sidebar menu.

Into the text box, type in the addresses whose messages you no longer wish to receive. Select the appropriate action; we usually recommend "move message to folder" in case you make a mistake, or in case you later want to read the messages after all.

Don't forget to enable the rule if it's not already enabled.

In Webmail, get into the mail filters editor via top menubar "Mail", then "Filters" from the drop-down menu. Select the rule called "Whitelist", or, if not present, the "Whitelist" item in the left sidebar menu.

Into the text box, type in the addresses whose messages you want to immediately file into your INBOX.

Don't forget to enable the rule if it's not already enabled.

PLEASE NOTE: this rule always delivers to the standard INBOX. If you use a different default mail folder, don't use the whitelist rule. Instead, create a custom rule (perhaps call it "Special Whitelist") to match each address of interest, and file the messages into your preferred folder. See "Automatic refiling" below.

In Webmail, get into the mail filters editor via top menubar "Mail", then "Filters" from the drop-down menu. Select the rule called "Forward", or, if not present, the "Forward" item in the left sidebar menu.

Into the text box, type in the addresses where all of your mail (or all mail that has not been delivered by an earlier rule!) should be sent.

Don't forget to enable the rule if it's not already enabled.

IMPORTANT NOTE #1: this sets up forwarding all of your future new mail as it comes in. Do not use this if you're trying to send an existing message to another person!

IMPORTANT NOTE #2: You are given the option to "Keep a copy of messages in this account". Please don't do that unless you're very sure you know what you're doing. Too often, people select this option and then fail to clear out their ENCS INBOX regularly, so they go over mail quota, and chaos ensues.

IMPORTANT NOTE #3: "forward and keep local copy" is a problem for people who prefer to deliver to a custom mailbox, as that rule always "keeps" into the standard INBOX.  Therefore, in those cases you'll need a pair of rules, one to redirect the message (and not stop processing), and another to file the message into your custom mailbox (and stop processing).

In Webmail, get into the mail filters editor via top menubar "Mail", then "Filters" from the drop-down menu. Click on "New Rule" in the left sidebar menu to create a custom rule. Set up the parameters describing the messages you want to refile, and select the folder to file them into. Give the rule a name that describes what it's for.

Don't forget to enable your new rule if it's not already enabled.

You can have as many custom rules as you like, for filing messages from different sources into different folders, for example.

  • An explicit "keep" command always overrides an explicit "discard" command, even if the "discard" is executed later.
  • The (undocumented) character for a word boundary in a regular expression is "\\b", that is, two backslashes followed by lowercase b.

SIEVE cannot be used to file mail into MH-style folders. If you need to file into specific folders, you'll need to use procmail. Please see both ENCS mail delivery with procmail and interaction between SIEVE and procmail.

If you're filing only into (the regular, non-MH) INBOX, then you can use "inc" to incorporate new mail into MH as you do now.

Note that if you do not have a SIEVE configuration and you do have a ".procmailrc" file, then your mail will continue to be processed by procmail as it is now. Just make sure you don't use Webmail to set up filtering, unless you understand the interaction between SIEVE and procmail.

The actions of the SIEVE mail processor are controlled by the files in the subdirectory ".sieve" on your Unix home directory (your U: drive if using Windows). In particular, in that directory (create it if it is missing), you need to create a file called SOMETHING.sieve ("SOMETHING" is up to you, but please don't use either "ingo.sieve" or "munger.sieve", as automated systems could replace those), and then create a symbolic link called "ACTIVE" pointing to your new file.

(If you don't know how to do the above, you are urged to use Webmail to manage your SIEVE configuration.)

The first time you receive a mail message after you do the above (or after you change the file pointed to by the ACTIVE symlink), the mail processing system will compile (or re-compile) your script into binary form, placing the result in "ACTIVE.svbin".

Another file of interest is the one called "LOG", which may contain information about messages processed. We strongly recommend that you start your script with this text, which will ensure that at least minimal message delivery logging is performed:

require ["vnd.dovecot.debug"];

We've made it easy to add logging to your "LOG" file by supplying system-level scripts that you can include. Also, the command "debug_log" can log arbitrary text for you. Here's an example:

require ["vnd.dovecot.debug", "include", "variables" ];
# (Put additional requires here as needed by your script)

# Log message details:
include :once :global "set_message_basic_info"; # Get variables
include :once :global "log_message_details"; # Log details

debug_log "Start of script for message ${global.msgid} from ${global.envfrom}";

# (Insert your script actions here.)

debug_log "End of script for message ${global.msgid} from ${global.envfrom}";

Note that dovecot executes its storage actions at the end of the script, so the logged lines come out in a strange order, with all of the “debug_log” lines first, then the reports of message saves to mailboxes. This is weird but normal.

 

By default, the SIEVE processor doesn't create new mailboxes, and can file only into an existing mailbox. However, you can use the ":create" option to cause new mailboxes to be created as needed. Here's an example:

require ["fileinto", "mailbox"];

fileinto :create "my_new_mailbox";

We support all of the "dovecot standard" capabilities, except for "reject" (to avoid backscatter of spam to innocent parties). In addition, we support:

  • editheader
  • spamtest
  • vacation-seconds
  • vnd.dovecot.pipe
  • vnd.dovecot.filter
  • vnd.dovecot.execute
  • vnd.dovecot.debug
  • vnd.dovecot.environment

But please note that the "vnd.dovecot" extensions are limited in what they can do, and most are probably not of use to the end user. If you find yourself needing one of those, you may be better off punting to procmail.

Back to top

© Concordia University