Filters

Credits

Various bits of code, scripts, and procedures were put together with information from John Simpson's qmail.jms1.net website. It's an excellent resource on managing and setting up a Qmail server.

Maildrop allows you to filter mail by calling it using a .qmail file in a user's vpopmail home directory. It can be used to filter mail through SpamAssassin, with per-user configuration options, or to filter mail into subfolders of their mailbox depending on specified criteria. eg. Mail that SpamAssassin has flagged as spam can be moved to a special folder.

Filter Writing Guides and Examples
http://www.antagonism.org/mail/folder-creation-maildrop.shtml
http://www.courier-mta.org/maildrop/maildropfilter.html

Environment variables
The following snippet of code is a good opening for your filter script and will set some important variables for your script to use:

SHELL="/bin/sh"
import EXT
import HOST
VPOP="| /home/vpopmail/bin/vdelivermail '' bounce-no-mailbox"
VHOME=`/home/vpopmail/bin/vuserinfo -d $EXT@$HOST`
VDHOME=`dirname "$VHOME"`
logfile "/tmp/log-maildrop"

Ensure delivery of messages
To make sure unfiltered messages get delivered, make sure to finish your filter with a line to deliver any unfiltered messages. If you don't, the messages will be quietly discarded! There's 2 options you can use depending on where the filter is being called from:

  • Use this option to close out a user's mail filter and deliver the message to their Inbox. If you use this in a global filter, called via .qmail-default, a user's .qmail file won't be processed.
    to "$VHOME/Maildir"
  • For a global filter, called from .qmail-default that will apply to all users, this is the best choice to use. The server will deliver the message using /home/vpopmail/bin/vdelivermail ensuring that a user's own .qmail file will be processed.
    to "$VPOP"

Filter Installation
To call a mailfilter, create a /home/vpopmail/domains/<domain>/<user>/.qmail file, containing:

|/var/qmail/bin/preline /usr/local/bin/maildrop /home/vpopmail/domains<domain>/<user>/.mailfilter

World-read permissions must not be enabled on that file, so we'll adjust it to the vpopmail user:

cd /home/vpopmail/domains/<domain>/<user>
chown vpopmail:vchkpw .qmail
chmod go-r .qmail

The .mailfilter file must also not be world-readable:

chown go-r .mailfilter

Logging
Take advantage of our use of Multilog for logging maildrop actions by adding a logfile entry in your filter:

logfile "/tmp/log-maildrop"

Recent Updates

  • 8 months 3 weeks ago
    1.27.2 update
  • 9 months 4 days ago
    Drupal 10/11 config
  • 9 months 5 days ago
  • PHP
    9 months 5 days ago
    PHP 8.3.11 and AlmaLinux
  • 9 months 6 days ago
    New version of Pound