As QuMa quite rightly said procmail is indeed cool as well as being very powerful:
"Procmail can be used to create mail-servers, mailing lists, sort your incoming mail into separate folders/files (real convenient when subscribing to one or more mailing lists or for prioritising your mail), preprocess your mail, start any programs upon mail arrival (e.g. to generate different chimes on your workstation for different types of mail) or selectively forward certain incoming mail automatically to someone"(*).
Though difficult to get one's head around its rules system is quite straightforward once you understand it. Here is a pretend .procmailrc file:
SHELL=/bin/bash
MAILDIR=$HOME/mail
DEFAULT=$HOME/Mailbox
LOGFILE=$MAILDIR/logfile
SENDMAIL=/usr/sbin/sendmail
VERBOSE=no
MY_MAIL_ADDR=foo@foo.com

# junk rules
:0 H:
* ^(From|X-From-Line|Return-Path):.*hotmail\.com
* !^X-Originating-IP:
junk

# Temporarily catch the rest of the mail, just in case...
:0 c
mail-inbox-copy

# Switching final delivery to qmail...

:0
* ^TO*
! mymailbox@foo.foo.com

The top is the header, then the rules start. A rule begins with :0 and ends at the next one... If there are no characters following the 0 then it is a normal, filtering rule (i.e. it filters mail matching the regular expression to where you tell it); if it is anything else (e.g. a c -- copy -- or f -- filter but then pass on to next rule) then it does what you tell it (again). The next bits (starting with the *s are the regular expressions -- they can get quite complicated -- and then the last bit is what to do with it (e.g. just put it in a folder, or forward (!) on to another e-mail a/c).

More succinct info can be found at:

  • the Procmail homepage -- http://www.procmail.org/
  • ii.com's "Processing Messages with Procmail" -- http://www.ii.com/internet/robots/procmail/
  • The Procmail mini-FAQ -- http://www.ling.helsinki.fi/users/reriksso/procmail/mini-faq.html
  • Jari Aalto's procmail pages -- http://www.procmail.org/jari/

(*) procmail.org, the procmail homepage