Why?
Due to a complete power loss at hetzner I had to reboot my server (crying). After reboot I had the problem that courier was restartet and what should I say - it was unable to load the *.so files for the vpopmail support. As it looks like upstream has stopped to support vpopmail. So I'd to find a different new solution and I've decided to kick qmail -> I switched to Postfix. Of course I am running gentoo and have followed (at least parts of it) this doku.
What I've missed in this doku was all about delivering and filtering the mails. Therefore I'll describe here what I've done.
SQL table
I've done some slight different handling of the homedir in the
user table.
In the following I assume some virtual mailing directory like the following
/var/vmail/ -\
|
|- foo-domain.com/ -\
| |- user1/.maildir
| |- user2/.maildir
|
|- bar-domain.com/ -\
|- user1/.maildir
|- user2/.maildir
I'd suggest to set the homedir for each user to
/var/vmail/${domain} and not to /var/vmail as suggested in the
howto. Therefore the maildrop rules in one file apply to a domain -
seams the more natural way to me.
Postfix modifications
In the main.cf we have to modify the transport mechanism. Therefore
the following 2 lines are important.
maildrop_destination_recipient_limit = 1
virtual_transport = maildrop
The next part is to modify the master.cf to configure the maildrop
handling
maildrop unix - n n - - pipe
flags=ODRhu user=vmail argv=/path/to/maildrop -d ${recipient} ${user} ${domain}
I've appended ${user} and ${domain} to use the data as $1 and
$2 resp. in the .mailfilter. Some more information on which my
configuration is based can be found here. The variables which are
provided by the postifx pipe are described in the manpage.
Maildrop
A very cute way to check if maildrop is working correctly - especially together with the courier authlib is the following statement.
$ echo "Hello" | maildrop -V 5 user1@foo-domain.com user1 foo-domain.com
maildrop: authlib: groupid=1006
maildrop: authlib: userid=1006
maildrop: authlib: logname=user1@foo-domain.com, home=/var/vmail/foo-domain.com, mail=/var/vmail/foo-domain.com/user1/.maildir
maildrop: Changing to /var/vmail/foo-domain.com
Message start at 0 bytes, envelope sender=hugo@eierbaer.at
...
I've placed the .mailfilter file inside of
/var/vmail/${domain}. And you should see the filtering - of course
you can even feed maildrop with a real testmail:
$ cat ${test_file} | maildrop -V 5 user1@foo-domain.com user1 foo-domain.com
And here some example .mailfilter file
MAILBOX = "/var/vmail/$2/$1/.maildir"
if( /^Subject:.*\*\*\*SPAM\*\*\*/ )
{
to "${MAILBOX}/.spam"
}
if( ${1}=="gentoo" )
{
if( /^From:.*bugzilla-daemon@gentoo.org/ )
{
to "${MAILBOX}/.gentoo-bgo"
}
if( /^Subject:.*\[gentoo-dev\]/ )
{
to "${MAILBOX}/.gentoo-dev"
}
if( /^Subject:.*\[gentoo-dev-announce\]/ )
{
to "${MAILBOX}/.gentoo-dev-announce"
}
if( /^Subject:.*\[gentoo-project\]/ )
{
to "${MAILBOX}/.gentoo-project"
}
if( /^Subject:.*\[gentoo-core\]/ )
{
to "${MAILBOX}/.gentoo-core"
}
if( /^(To|Cc):.*heimdal-discuss@sics.se/ )
{
to "${MAILBOX}/.heimdal"
}
if( /^Subject:.*\[Heimdal-bugs]/ )
{
to "${MAILBOX}/.heimdal"
}
}
to $MAILBOX
Happy hacking!