University of Calgary

Email Delivery Filtering with the IT Web Utility

Submitted by teale on Fri, 2007-03-30 13:56.

Introduction
Basics about the Filter rules
Building and Enabling a Filter rule
Building and Enabling more than one Filter rule
Advanced Matching Conditions
Some Examples Explained
Filtering when you use Email Vacation autoreply, Email Forwarding and Tagged Spam Filtering

Introduction

Email delivery filtering is often known as server-side filtering. You define rules to screen your incoming email messages to assist in sorting and organizing your e-mail, most notably:

  • File it into folders according to subject, sender or from, or size - ideal for filing messages from mailing lists,
  • Resend it on to another email address based again on subject or the from address,
  • Throw it away - be careful with this one.

Since this happens during mail delivery (on the server-side), your email program does not need to download thus saving you connection time, download time, and your time to manage the messages such as filing to folders. You can access the folders from the IT IMAP server with an email program such as with IT Webmail.

The downside is you have to poll your folders for new arrivals and misfiled messages. Once enabled, all your incoming mail is subject to the rules.

The following describes the structure of filter rules and then takes you through the basics of setting up server-side filtering rules.

Basics about the Filter rules


The fundamental structure is:

if (condition) then action

Filter rules have two parts: conditions and actions.

The Condition selections

The three types of conditions correspond to asking the questions:

  1. Is certain text pattern found (or not found) in certain headers (subject, from, to, sender)? (contains or = are used interchangeable)
  2. Are certain patterns (regular expression match) found (or not found) in certain headers (subject, from, to, sender)?
  3. Is (or is not) the line count above or below a certain value?
  4. Do you always want to perform this action? (usually the last rule)

The Action selections

Actions include save, savecopy, forward, forwardc, delete
save - Store the message in another folder: the folders are created on the IT IMAP server
savecopy - Store a copy of the message in another folder: as above but a copy is also placed in your INBOX.

Use simple names for your folders but you can build complexity in your folder structure keeping in mind the following rules:

  • You may use spaces, but not forward or back slashes.
  • Forward slashes are used as folder separators: a folder path of Meetings/planning is a folder named planning inside the folder directory called Meetings.
  • You must create any folder directory with your e-mail program prior to running a filter rule. In the previous example you would create the directory called Meetings.
  • If your e-mail program uses a folder directory of Mail for all your folders, then address the folder by Mail/planning or Mail/Meetings/planning. NOTE: In this example, Mail and Meetings would have to exist otherwise one cannot file to the folder planning.
  • Note messages cannot be filed to a folder directory, only to folders.
  • If you store messages in a folder named spam-mail, the messages there could be subject to automatic deletion as specified by the controls on the Spam Tag Filtering email settings page of the IT Web Utilities.

You access your mail folders with Thunderbird, Outlook Express, Apple Mail (and other email programs) or with IT Webmail.

forward - Send the message to another email address
forwardc - Send a copy of the message to another email address and keep a copy for yourself: as above but a copy is also placed in your INBOX.

  • You can separate the addresses by commas or spaces (or both).
  • Please only include the actual address part (i.e. person@example.com) and not any full name parts.
  • If you don't specify a domain for the address (the part after the @) it is assumed to be @ucalgary.ca.

delete -Delete the message: Message is "discarded" permanently. There would be no way to retrieve it without asking the sender to resend it.

Examples

if (from = "myprof@ucalgary.ca") then savecopy Fromprof 
if (to = "mylist-l@mailman.ucalgary.ca") then save LISTS/mylist 
if (sender ~ /@mailman\.ucalgary\.ca/) then save LISTS/othermailman 
if (lines > 1000000) then save Mail/bigmail
always forwardc  myhome@telus.net 

Building and Enabling a Filter rule


Connecting to the IT Utility:

To start, point your web browser at the IT Filter Utility. Enter your IT username and password in the appropriate boxes and press the "Go" button.

Begin your first rule:

  • Click in the text box "Insert new rule here". Rules are typed one per line.
  • Type a rule you had in mind in the text box using the examples, for example,

    if ( subject = "Test Filter" ) then save testfilter

  • Click on Update filter rules to check the syntax of your rule.
  • If no errors, check the check box Enable filter rules.
  • Then <>click on Update filter rules button, to make the rule active immediately:

Correcting Errors:

If the rule is syntactically correct then a green "Enabled" status would be displayed. If any errors in syntax are encountered the rule is labelled with "Error:" and the rule is not activated. Correct any errors in the rule:

  • Remove the "Error:" text in the rule box and make other corrections to the syntax according to the examples shown here.
  • Click on Update filter rules button, to make the rule active immediately again. Repeat until the green status appears.

Testing your rule:

If the rule is a subject match then you could test that rule immediately by sending an email with that subject. Otherwise if based on from address then you will have to monitor your email for the results.

Building and Enabling more than one Filter rule

The filtering process works like an assembly line. When you receive an email message the system starts at the beginning of the list of rules. For each rule in turn, it checks to see if the condition is satisfied by the message. If it isn't, it hands the message on to the next rule. If it is, though, it performs the action and stops processing. If the system gets to the end of the rule list without stopping processing, it delivers the message in your inbox.

Create or add a new rule by typing in the text box, one per line. The changes are inactive until you click the associated "Update filter rules" button. To begin with you may want to add one rule at a time, activate it then to make sure you have typed the rule correctly before adding additional rules. Or you can set up one or more rules and not put them into effect until everything is precisely right. Then check the checkbox Enable Filtering and click "Update filter rules" button. Rules that are flagged Error: are not active. Other rules will be active.

Correct each rule one by one until no errors occur and status of "Enabled" is shown.

Advanced Matching Conditions

However, you can check for a pattern or patterns matching any header at all by using a * by itself in the header text box.

Please also note that the regular expression type of match does not automatically include * characters at the beginning and end of the pattern. This allows you to match for things occurring only at the beginning or end of a header (by only putting a * at the end or beginning of the pattern, respectively), but to look for a wildcard expression in the middle of a header you should put * characters at both the beginning and end.

Check if the message size is or is not above or below some value: If you just put a number in the size box, it specifies a number of characters in the message (both header and body). You can put a "K" after the number to specify kilobytes (1024 bytes) or an "M" to specify megabytes (1024 kilobytes, or 1048576 bytes).

Some Examples Explained

Save messages to a certain mailing list into a folder

There are a number of ways you can do this; they all use header match conditions:

  • If the mailing list puts a special string in the subject line (like the list name in brackets), you could match on the Subject header, with a "contains" style match, and the special string as the pattern.
  • If mail to the list always has the same address in the To or Cc header, you could use the to specifier in the rule to match on either the To header or Cc, with the pattern being the email address sent to.
  • sometimes a mailinglist has a Sender: header line which you can use to match. Note this is not the same a the From: header as From is the author of the message which could be anyone on the mailinglist . The complexity is due to using regular expression matching (the ~ character) and escaping the special character . in the match string.

if (subject contains "[NHL]") then save NHLscores if (sender ~ /@mailman\.ucalgary
\.ca/ then save LISTS/othermailman if (to = "mylist-l@mailman.ucalgary.ca") then
save LISTS/mymailmanlist

remember, in this case, matching either the to or cc header the condition is true

Match expression = or contains are interchangeable. The ~ character indicates regular expression matching and the pattern is enclosed in slashes.
Note the folder directory LISTS would already have to exist by creating it with an e-mail program. You can simply create folders without a folder directory depending on how you want to organize your e-mail, for example LISTS:othermailman is simply the name of a folder.

Forward all mail sent by your colleague to your assistant

You would do this by setting up a rule with a header match condition

  • check if the headers From or Resent-From contain the email address of your colleague, and an action that sends a copy of the mail to your assistant's address. Any email that did not satisfy the condition would be processed by other rules and/or put into your inbox.) Note in this case a copy is sent to your assistant and the original is still filtered and delivered to your mailbox. If you do not want to keep a copy then you would use forward not forwardc.

if ( from = "drjones@ubc.ca") forwardc bsmith@ucalgary.ca

Note the use of matching based on the From address line.

Filing messages with {Spam?} in the subject line

This function has been implemented with the Tagged Spam IT Utility ready for you to enable it. Once Enabled, Spam tagged messages will be filed to spam-mail folder (or deleted) prior to any other filtering including importantly your vacation autoreply or forwarding. The spam-mail folder will also be cleaned according to your choice of how long you want to keep the messages.

Filtering when you use E-mail Vacation autoreply, E-mail Forwarding, Tagged-spam Filtering

Please note the following points in the management of your incoming e-mail:

  • If you have enabled a "Forward all mail to another address" set to "yes, don't keep a copy", your mail is being forwarded elsewhere and any filtering rules you set up for your account will have no effect. If it is set to "yes, do keep a copy", the filtering rules will take effect after you forward a copy elsewhere.
  • If you have "Vacation autoreply" set to "yes, don't keep a copy", your mail is is not delivered and any filtering rules you set up for your account will have no effect. If it is set to "yes, do keep a copy", the filtering rules will take effect after you the autoreply has been sent.
  • If you have "File messages marked as spam into a folder named spam-mail on the mail server" set to "yes", that filing will take place before any filtering rules are applied. False positives may occur and legitimate e-mail may have been filed to the spam-mail folder. Please review the folder and whitelist any legitimate sender's addresses.