Software: deliver

Control email delivery (for .qmail only)

deliver is procmail-like tool. It can analyse incoming email, and either reject it with temporary or permanent error, or execute another command to continue delivering this email (this command should be given to deliver in first param). Rules used to analyse email are written in Perl.

To analyse incoming email deliver execute perl-script ~/.deliver, which should either return non-empty string or call SoftError() or HardError(). If ~/.deliver return non-empty string, it will be saved in environment variable $deliver before starting command to continue email delivery.

In ~/.deliver script you can use next functions:

To reject this email (all these functions call exit()):
SoftError('message') see `man qmail-command`, EXIT CODE = 111
HardError('message') see `man qmail-command`, EXIT CODE = 100
To check email headers and content (all these functions return true if 'regexp' match; you can use qr/regexp/ instead of 'regexp'):
_FROM('regexp') Check UUCP-style From_ line that qmail-local adds to mbox-format files
_BODY('regexp') Check email body
From('regexp') Check header From:
To('regexp') Check header To:
Reply_To('regexp') Check header Reply-To:
... You can call any other functions to check any other email headers ("-" in header name should be replaced by "_" in function name, function names are case-insensitive)


  1. Add something like this to your ~/.deliver: From('good_email1a|good_email1b') && 'mailbox1' || (From('good_email2') or CC('good_email2')) && 'mailbox2' || _BODY('Windows|Microsoft') && 'windows' || From('bad_email1') && HardError('SPAM!') || 'default'
  2. Add these lines to your ~/.qmail: # deliver email to ~/Mail/$deliver ($deliver value is result of ~/.deliver) |deliver 'qmail-local "$USER" "$HOME" "$LOCAL" "" "nodeliver" "$HOST" "$SENDER" "./Mail/$deliver"'

Since version 3.0.0 it try hard to normalize MIME parts and convert email headers and body to utf8. You can view normalized email (to find out how to match it with your rules in ~/.deliver) using: deliver -d </path/to/email