April 13th, 2009

Working on the computer, Working

Outlook Rules: Advanced Filtering

My company has moved to Exchange 2007 to handle its email and other communication services. While most people in the marketing side and some of the managerial people don't mind, it's causing a number of developers a slight headache. POP and IMAP are no longer an option (IMAP was killed off quite a while ago anyway) so that means Thunderbird is also no longer an option.

A number of us have explored Outlook's rule system and have found it to be extremely lacking. Most of the rules we would also use are client-side only anyway (like marking a message as read? Crazy). With this in mind I wrote a VBA Macro for Outlook to implement custom rules similar to the Thunderbird Filter system. I haven't programmed in VB in years so I was considerably rusty about it. I managed to cobble something together in four or five hours and even got it self-signed so I wouldn't have to lower the security settings. The only other problem was every time it accessed an email address field it popped up a security warning dialog, so any filters on those would get rather annoying quickly. Thankfully it didn't take much effort to find the Redemption add-on that allowed me to access those without that pop-up and without exposing the default access system to too much risk. There's still security holes but isn't that the pseudo name for Outlook? heh.

Below is an example of the code to configure a couple of rules:
setMatchType AllOftheFollowing addCriteria Subject, BeginsWith, "[svn-" addCriteria Subject, Contains, "my.name" addAction MarkAsRead, "" addAction MoveFolder, "Issues" closeRuleSet setMatchType AnyOfTheFollowing addCriteria Subject, BeginsWith, "System Alert" addCriteria Subject, BeginsWith, "Cronjob <yz@psx>" addCriteria FromAddress, Contains, "alert.system@" addCriteria FromAddress, Contains, "another.alert.system@" addAction MoveFolder, "Exceptions" closeRuleSet

Surprisingly enough this is a rule that Outlook can't support. When doing checks against a single field (Subject) you can't require two pieces of text to both be found; it only allows an OR match between them. It also doesn't allow BeginsWith or EndsWith matching of a string. Lastly there's no way to specify multiple criteria with an OR between individual field checks to do the same action. If I were to set the second rule set to 'contains' it would take two different rules.

The only thing really missing is a regular expression criteria. It's possible but would take some more digging to get a vb.regexp object working (not natively imported into VBA for Outlook).
  • Current Music
    "One More Day With You" by Diamond Rio
  • Tags