procmail

The Swiss Army Knife for server-side e-mail rules in the world.

Useful snippets:

# DUPLICATE REMOVAL
# This rule uses formail to remove emails that have a message-id that has
# already passed through the system. It keeps an 8K log.  "W" waits until it
# gets the exit code from formail and filters if appropriate. the 'h' means
# pipe the headers only. it uses a user-defined lockfile for this task.
:0 Wh: msgid.lock
| $FORMAIL -D 8192 $HOME/.msgid.cache

Resources: