LOCALMAILFILTER(7) | Double Precision, Inc. | LOCALMAILFILTER(7) |
localmailfilter - Local mail filtering
echo /usr/bin/maildrop >/etc/courier/maildropfilter mkdir $HOME/.mailfilters vi $HOME/.mailfilters/rcptfilter $HOME/.mailfilters/rcptfilter-ext vi $HOME/.mailfilters/smtpfilter $HOME/.mailfilters/smtpfilter-ext chmod 700 $HOME/.mailfilters chmod 600 $HOME/.mailfilters/*
The maildrop mail filter can be used by the Courier mail server as a mail filtering engine, rejecting unwanted mail on a per-recipient basis.
The actual filtering interface used by the Courier mail server does not really require that maildrop must be used as a mail filtering engine, it just so happens that maildrop has a compatible interface that can be used right out of the box. The following brief information can be used to craft a homebrewed mail filter to take maildrop's place.
The local mail filter only works for addresses that correspond to local accounts. This filtering is not used if the recipient is a remote address on another mail server. The local mail filter is disabled by default. To enable local mail filtering you will need to initialize the /etc/courier/maildropfilter configuration file to contain the pathname to your local mail filter.
Local mail filtering is performed in two distinct phases:
Recipient filters
Content filters
It should be noted that mail filtering is executed as an integral part of receiving a message from a remote mail server. If the message is rejected, the Courier mail server refuses to accept the message for delivery.
The local mail filter will be invoked as follows:
HOME=$HOME FILTER -D uid/gid -M filter
The local mail filter will NOT be invoked as root, so if it needs to access files in the recipient's account, it must be installed setuid to root (as maildrop is installed by default).
"uid/gid" is the recipient account's system userid and group id, respectively. The recipient account's home directory is placed in the HOME environment variable, prior to running FILTER, and "filter" is set as follows:
rcptfilter
smtpfilter
rcptfilter-ext, smtpfilter-ext
rcptfilter-alias-ext
The rcptfilter invocation must terminate with a zero exit code when the message originates from a mailing list or any other source that should be considered as "whitelisted". This filtering model does not fit very well with some mail transfer protocols, so unless trusted sources are explicitly declared to be whitelisted, there is a remote possibility that the recipient will be removed from a mailing list because of a poorly-written mail filter from some other recipient of the same message. The 0 return exit code (which is the implied default if no mail filtering is installed) protects the recipient from being adversely affected, in any way, by anyone else's mail filter.
The mail filters may print a diagnostic message before rejecting a message. The diagnostic message will be returned to the sending mail relay, where possible.
The mail filters inherit environment variables that describe the incoming mail. The following environment variables are provided by default:
SENDER
TCPREMOTEHOST, TCPREMOTEIP
BLOCK2
Maildrop implements this mail filtering API as follows:
$HOME/.mailfilters
smtpfilter*, rcptfilter*
See maildrop(1)[2] for more information.
The /etc/courier/aliases configuration file is used to mail aliases, see makealiases(8)[3]. The system administrator may set aside a reserved local account that will be used to specify a local mail filter for messages addressed to aliases. The configuration file /etc/courier/aliasfilteracct specifies the home directory of the mail account that will be used to filter alias recipients.
For example, if /etc/courier/aliasfilteracct contains /home/admin, then the Courier mail server runs the mail filter as follows:
HOME=/home/admin FILTER -D uid/gid -M rcptfilter-alias-name
Here, "uid/gid" is owner uid and gid of the specified directory NOTE: "name" is a fully qualified address, and the local aliases listed in /etc/courier/aliases do not typically include the domain name. If defines an alias called "system", for example, the -M option will probably be "system@example.com", if example.com is the contents of /etc/courier/me configuration file.
Unfortunately, currently it is not possible to specify content filters (a.k.a. smtpfilters) for aliases, only recipient filters.
/etc/courier/maildropfilter
/etc/courier/aliasfilteracct
courierfilter(8)[4], maildrop(1)[2].
Sam Varshavchik
07/24/2017 | Courier Mail Server |