Mail Filtering Tips

Table of Contents

  1. Introduction
  2. Getting started
  3. Filtering spam
  4. Organizing mail into folders
  5. Forwarding mail
  6. Setting up auto-reply/vacation
  7. Creating filter rules on the fly
  8. Putting it all together
  9. For brave souls: Writing sieve scripts directly

1. Introduction

The math department's email server is being phased out and replaced by a so-called IMAP server. The new server is more secure, more reliable, and easier to maintain, but since it is a sealed unit on which normal unix programs cannot be run, the standard mechanism of mail filtering and processing with the procmail, forward, and vacation programs cannot be used. In its place, the server provides an easy-to-use web-based tool with a functionality similar to these programs. This page explains how to use this tool. First, two important notes:

2. Getting started

  1. Go to the webmail address, https://webmail.math.uiuc.edu, log in with your AD (Active Directory) username and password. (See ??? for help with the AD authentication.)
  2. Click on "Filters" at the top of the main window.
  3. Click on the button "Add a New Rule" near the bottom of the screen. This will bring up the form in which you specify the rules for your filter. The following sections show how to do this for various common scenarios.

3. Filtering spam

Messages with a CITES spam score of 80 (on a 0 - 100 scale) are deleted systemwide. This takes care of the vast majority of incoming spam, but it is a rather conservative policy, and you might want to be more aggressive and "quarantine" messages with lower spam scores (e.g., above 50, or above 10) by filing them away onto spam folders. This prevents the messages from showing up in your INBOX, but you can still examine them, and check for false positives, by going to the spam/quarantine folders. Here is how to do this:
  1. Follow the steps in the "Getting started" section to get to the fill-out form for a new filter.
  2. From the drop-down menus in the "Condition" section, pick "Header", "X-Spam-Score", and "is greater or equal to". In the text field specify a value for the spam score above which you want to filter away spam, say "50".
  3. In the "Action" section, pick "Move messages into". This pops up a submenu; pick "a new folder, named", and choose a name for the folder, say "spam50", to indicate spam with a score of at least 50. This folder will be a subfolder of the main folder, INBOX.
  4. In the "Additional Actions" section, check the "Stop" box. This prevents messages from being processed by other rules you might have set up. When dealing with likely spam, this is a good thing to do.
  5. Click on "Add New Rule" at the bottom of the screen. This activates the filter.
Additional tips and notes:

4. Organizing mail into folders

A second way to use the webmail filtering tool is to organize mail into folders according to certain criteria. The following examples show to do this under some common scenarios.

Note: All examples assume that you are already at the page where you can enter a new filter rule. The "Getting started" section above shows how to get to this page.

5. Forwarding mail

You can have mail matching certain criteria automatically forwarded to another address by specifying the matching patterns in the "Condition" section, choosing "Redirect to the following email address" as Action, entering the forwarding address in the text field provided, and, optionally, checking a box to have the message kept locally as well. The following examples illustrate some common scenarios. These example assume that you have followed the steps in the "Getting started" section above and are at the page where you enter a filter rule.

6. Setting up auto-reply/vacation

The ordinary (unix) vacation program does not work under the new mail server, but webmail allows one to set up a vacation message quite easily. Here is how:
  1. Follow the steps in the "Getting started" section to get to the fill-out form for a new filter. The form has three sections, "Condition", "Action", "Additional Action".
  2. In the first section, "Condition", you must specify a condition that needs to be met in order for the vacation reply to be triggered. The program will complain if you leave this section completely blank, so you must fill something in. You could select "All Messages" as condition (pick "All" from the drop-down list under "Headers", then click on "Less" until only the single condition "All" is left). However, this is generally a bad idea as then vacation replies will be sent in response to spam email and to auto-generated commercial email (e.g., travel confirmations, newsletters, special offers), where vacation replies are not appropriate. Thus, you might want to restrict the vacation mechanism at least somewhat. Here are two examples;
  3. In the next section, "Action", click on "Vacation". This pops up several pre-filled text fields:
  4. You can ignore the final section, "Additional Actions". It allows one to specify optional additional actions, such as having the program send an email notification of any incoming email to an alternate address.
  5. When you are done, click on "Add Rule". This brings you back to the main Filters screen, and you should see a description/summary of the vacation rule in your list of rules. The vacation program is now active.
  6. To be sure the program is working as expected, have some friends send you email and check their mailboxes for any vacation replies. Note: When testing out the recipe, be aware that, after the initial vacation reply is sent out to a given address, there is a blackout interval before the next reply is sent out to that address. Thus, you cannot use the same address for more than one test.
  7. To deactivate the vacation program, click on "Filters" from the main screen to display the filtering rules that you have defined. Check the box next to the vacation rule, and click on "Disable" to disable it. (There is also a "delete" option, but "disable" keeps the rule in the system and makes it easy to re-activate the vacation program with a simple mouse click.)

7. Creating filter rules on the fly

Another way to create a filter rule is while reading a message with webmail. When displaying a message, right below the usual message headers, there is an extra header, "Create Filter:", with clickable options "Automatically", "From", "To", "Subject". If you click on one of these options, an abbreviated version of the filter rule set-up page appears, with the "Condition" pre-filled with data extracted from the headers. To create a rule based on this condition, choose an appropriate action, and click on "Add rule".

8. Putting it all together

When you are done setting up filter rules, click on "Filters" to display a list of the rules you have created. You can change the way these rules are displayed from "verbose" to "terse" to "tech" to "source". (I find the "terse" format to be the most useful.) You can deactivate any given rule by checking the box next to it and clicking on "Disable"; clicking on "Enable" will re-activate the rule.

You can edit a rule by clicking on the first icon in the options column. The second icon creates a copy of the rule, which can then be edited to form another rule. The triangular icons allow you to move rules up and down the chain.

If you have set up multiple rules, perhaps with overlapping conditions, it is important to understand how these rules are processed. Unfortunately, the available documentation on this is very spotty, and the "Help" button doesn't help in this case - there is no section in the Help manual discussing filtering. What follows are some general principles that I have been able to piece together from various sources and which I could confirm with trial and error.

9. For brave souls: Writing sieve scripts directly

The mailfiltering tool described here is, in fact, a very user-friendly frontend to a very unuser-friendly language/program called "sieve" that generates a script in this language (which is an ordinary text file, named "phpscript.siv"), places it in the appropriate location on the imap server, and activates the script so that it is being applied to any incoming piece of mail. It is this script that does the actual filtering of mail.

Instead of having the script generated automatically via this frontend, one can instead create a sieve script with a text editor and upload it to the server. This is, in fact, what I have been doing, partly because it allowed me to access the full power of the sieve language (the filtering tool is more limited in its capabilities), and also in part because I am a bit of geek at heart, I prefer hand-coding things on the keyboard rather than pointing-and-clicking, and I like the challenges, and don't mind the frustrations, that this presents.

If you want to go down this road, be prepared for a very bumpy road, lots of frustration along the way, and no help available (sieve scripts are not officially supported by our system administration). You will be largely on your own (but see my "imap.notes" diary below). The main problem is that the "sieve" language is relatively new, very poorly documented (the only official piece of documentation is the technical description of the language in the form of a nearly inscrutable "RFC" document), and is very much dependent on the particular imap implementation; what may work at other places may not work here, and vice versa.

That said, if you want to give it a try, my own experiences might be helpful; I have recorded these in the file "imap.notes" under my public directory "/home/users/hildebr/pub" (this is intended for local users only). The same directory also contains a file "main.siv", the sieve script I am currently using. You will, however, be on your own, and I won't be able to help with any problems you run in. I simply don't know enough to be of much help; although I eventually managed to get things to work for me, it was a long and frustrating road, involving a lot of trial and error, and stumbling in the dark, and in many cases I didn't know why something worked one way, but not another way.


Last modified Tue 21 Aug 2007 11:25:38 AM CDT A.J. Hildebrand