Index

Simple qmail Whitelisting

This script checks the senders address against a list of known addresses. If a match is found, the mail is allowed through as usual. If no match can be found, the mail is forwarded to a user specified address.

I use this script to sort mail from unknown senders (mostly spam) to a separate maildir, which I can then prune at my leisure. This keeps my inbox free from spam.

This script requires no patches to qmail. It makes use of the dot-qmail filtering, built into qmail and the condredirect program supplied with qmail.

The Code

#!/bin/sh

##
## simple whitelisting for qmail (v.4)
## by mattias wikstrom
## http://www.mattiaswikstrom.net
##
## example .qmail:
## -------------------------------------------------
##   |condredirect send-spam-here ifwhitelisted.sh
##   ./Maildir/
## -------------------------------------------------
##

## conf
whitelist=$HOME/.whitelist/whitelist

## code
(test "$SENDER" && grep -qix "$SENDER" $whitelist) || exit 0
exit 100

Download

ifwhitelisted.sh

Install

Create the list of addresses and copy it to ~/.whitelist/whitelist. The file should contain, one email address per line. All recipients from your sent folder is probably a good place to start.

Copy ifwhitelisted.sh to a directory in your PATH.

Check that condredirect and grep are in your PATH.

Add the following line to your .qmail file:

|condredirect send-spam-here ifwhitelisted.sh

Change "send-spam-here" to the address where you want the unknown mail to go. Also remember to add a delivery instruction after the whitelisting, so that the mail from recognized senders, doesn't get lost.

If you use procmail or maildrop for filtering it might be a good idea to run the filtering before the whitelisting.


2007-08-06 Copyright Mattias Wikström (email: me at domain)