System Information
กก
System Information

University of Virginia

root@cs.virginia.edu Department of Computer Science


Filtering Electronic Mail

Recommended Filter: procmail

Procmail is a program which understands regular expressions and will act on your mail according to regular expressions you specify.

The man page for procmail is good, but here are some quick pointers to help you get started.

Enabling procmail

Here are the steps necessary to enable procmail in your environment.

  1. Create a rules file (see below). It can be named anything, but procmail will look for a file named .procmailrc. If you name it something else, you'll have to put that on the command line.

  2. Enable procmail in your .forward file. If you want to have mail filtered and delivered to your mailbox, you can put both procmail and your userid into your .forward file. The following line in your .forward file will enable procmail:

           "| /usr/cs/bin/procmail"
           

    Note that the full path to the procmail program is necessary. Note also that this path has to be the correct path on the mail server, and that may or may not be the same as the path to procmail on an interactive server. Use /usr/cs/bin/procmail.

    If you decided to name your rules file something other than .procmailrc, name it on the command line, like this:

           "| /usr/cs/bin/procmail /home/mst3k/Mail/rules"
           

That's all that you have to do to enable procmail.

The Rules File

The Rules file is parsed by procmail a little like a shell script. It uses the same comments and variable assignment syntax. Rules, however, have their own syntax. These are explained briefly below. To get the best information on all the fine details, see the man page.

Environment Variables

Any variable can be created and assigned to, just like in a shell script. Some environment variables, however, have special meaning to procmail. Here is a list of important ones and good default settings for them:

Variable: DEFAULT
Good Default: /var/spool/mail/userid
This controls the default behavior of procmail for when it has no rule specifying what to do.

Variable: MAILDIR
Good Default: $HOME/Mail
This specifies the directory where procmail will store files that it writes, if no absolute path is given.

Variable: LOGFILE
Good Default: /dev/null
Specifies the file where procmail logs its activity. It's best to leave this set to /dev/null unless you're tracking down a problem. The log file tends to grow without bounds over time.

Variable: UMASK
Good Default: 077
Sets the default permission for files created by procmail. 077 sets the files such that only you can read or write them by default. See the man page for umask(1) for more information on what this number means.

An Example procmailrc File

See the procmail(1) man page for more information. Most of the basic functionality and some advanced functionality is demostrated in this example.

[an error occurred while processing this directive]