Procmail Filters

The major differences in using procmail on the new (maildir) versus the old (mailbox) E-Mail server(s) is in the syntax/format to use for folders:

  • specify each folder to deliver to (except $DEFAULT), with a leading . and a trailing / to denote maildir format:
      .MyFolder/
  • when using sub-folders, use a . as folder-delimiter:
      .Level1.Level2.MyFolder/
  • you therefore cannot have folder names containing a . because that would be interpreted as designating a sub-folder ...
    and neither can folder names contain a /
    ... and besides these 2 special characters, also be careful with other special symbols: chances are you want/need to access your E-Mail with different client software and from different OS-es and all of these can differ in subtle ways in the way they handle non-ascii characters.

We very strongly advise to use the web based procmail that is available on all our E-Mail servers ... most probably the default will be just fine.

If the default web based procmail is not OK for you, it is easily extendable to suit your needs:

  • you can change the standard procmail variables and/or add additional processing rules to tweak the default procmail setup to your needs:

    • all E-Mail delivery actions are logged in the procmail LOGFILE (per month):
      • If you don't want E-Mail delivery reports in LOGFILE, set the LOGABSTRACT=no
      • By setting VERBOSE=yes you get extended diagnostics with each delivery report in LOGFILE
      • We advise not to change the default procmail LOGFILE unless you know what you are doing
    • we advise against changing the default SPAMFOLDER variable, but if you really like to, you can of course
    • MAILDIR and EMAILADDRESS are only to be changed if you really, really know what you are doing
  • to prevent some important e-mail messages from winding up in your spam folders, make them being delivered to your inbox explicitely ... to do so, add the following above the default spam rules:

      # important E-Mail, never to be put in SPAM folder
      # therefore this filter is put before the SPAM filter
      # it will be delivered to your normal inbox
      :0 :
      * Subject: Important Subject .*
      $DEFAULT
  • to use a different folder than your inbox, you can specify it as in:

      # another important E-Mail, never to be put in SPAM folder
      # but to be delivered to the specified folder instead
      :0 :
      * Subject: .* Important substring of Subject .*
      .ImportantFolder/
  • Instead of filtering on Subject, you can of course also filter on From:, To:, ... man procmailrc might be a good help if you want more than the simple recipes above ;-)

  • Adapt and change as you need, but tread carefully: if you mess things up, mail can/will get lost!

If you really want to set up your own procmail filters from scratch:

  • create/edit in your mailhome directory a file .procmailrc
    • a good start might be:
        YEAR=`date +%Y`
        MONTH=`date +%m`
        pr
        LOGFILE=$HOME/procmaillog-$YEAR-$MONTH
        LOGABSTRACT=all
        VERBOSE=no
        COMSAT=no

        # important E-Mail, never to be put in SPAM folder
        # therefore this filter is put before the SPAM filter
        # it will be delivered to your normal inbox
        :0 :
        * Subject: Important Subject .*
        $DEFAULT

        # another important E-Mail, never to be put in SPAM folder
        # but to be delivered to the specified folder instead
        :0 :
        * Subject: .* Important substring of Subject .*
        .ImportantFolder/

        # Spam
        :0 :
        * ^X-Spam-Status: Yes
        .Procmail.spam-$YEAR-$MONTH/
  • As in the web procmail example above, all E-Mail delivery actions are logged in a log file (also per month)
  • All spam is put aside in a separate folder (per month), except for some important messages.
  • Adapt and change as you need, but tread carefully: if you mess things up, mail can/will get lost!
  • Some hints for procmail programmers
    • test as soon as possible (every character may have (side) effects)
    • procmail regular expresssions are not greedy
    • procmail regular expressions after backreference operator \/ are  greedy (but not including newline at end).
    • procmail variables are context dependent (a variable cannot be used everywhere)
    • do not use locks surrounding nested recipes  ==> lock at the lowest internal recipes

Don't forget to clean up old log and spam files from time to time ;-)