Installation:Debian:Maildrop

From PMWH2 - PHPMyWebHosting's official wiki
Jump to: navigation, search
up

Introduction

Maildrop is being used for filtering purposes and automated delivery in the appropriate directories. To guarantee a smooth operation with Pmwh2 there must be a small change of Code in Maildrop.

Even though the manpage of maildrop is quite informativ, there might be a missunderstanding when it comes to connection with MySQL. The Author likes to give a brief explanation thereof:

The user-data is stored in a MySQL-Database. maildrop fetches these data (homedir and maildir) out of the database, however, before the execution takes place(in delivery-mode, Option -d), all data that was taken from MySQL (homedir, maildir, etc.) will be deleted and replaced with default values.

On that point the question might raise what is going on here: We have a MySQL-Database where all data of the mailaccount are present, but maildrop simply refuse to use them? Does that make sense? A definite answer is not possible. It could be happening that some of the environment-variables are declared wrong, and therefore cause errors or (worse) could be used to manipulate the entire system. But this can only happen if data are retrieved not from the database but from those environment-variables.

Thinking that over we might come to this conclusion: We only verify, if all data were taken correctly from the database. If data were not completely fetched error free then default values must be used. If all data were fetched they can be used, since manipulation of the database hopefully should not be possible.

Not only because of this kind of "bug", but more because of the non present MySQL-support, we will do a new compile of maildrop. The following instructions will show you how to do this.

Download

If you prefer not to compile it by yourself you may freely use the precompiled package. The package was compiled on a Debian-Sarge Installation.

File:Courier-maildrop 0.47-sarge i386.deb.

After Downlading continue with Install Maildrop.


Get the Sources

Eventually your sources.list needs to be updated according to your needs. When done go the directory /usr/src and run the following commands. To make sure your package list has the latest information:

apt-get update

When updated you can get the sources by running:

apt-get source courier-maildrop
apt-get build-dep courier-maildrop

First command gets the source of maildrop being stored in the directory /usr/src/courier-<version>. Second command makes sure all packages needed to compile maildrop will be installed and configured.


Apply the Patch

* Activation of MySQL support
* Removal of Code wich prevents an error free operation with postfix.
Download File:Maildrop mysql-sarge.patch.

This patch eleminates the problem with the environment-variables and also adjusts the rules-file for the compile.
The Rule says that MySQL should be used and that users vmail and postfix must be accepted as a trusted user.
Otherwise maildrop will be ignoring all Inputs from postfix.
This patch is for all who dont want to adjust the build-option manually.
Its time to copy the patch into the directoy /usr/src.
The patch changes two elementary settings in the Courier-Maildrop-Package.

To apply the patch run the following command in the directory /usr/src

patch -p0 < maildrop_mysql-sarge.patch


Compile Maildrop

Maildrop is now patched and ready to compile. To compile Courier-Maildrop run the following command in /usr/src:

apt-get source courier-maildrop -b

Since the sources are already present and un-packed, Debian will skip this step and starts with configure followed by a compile. Unfortunately the whole Courier-system is compiled, not only maildrop. Therefore we get more than one .deb-Files at the end.


Install Maildrop

Of course our maildrop also has to be installed. In the same directory as before /usr/src run the following command:

dpkg -i courier-maildrop<version>.deb

Additionally, after installation the system has to be informed not to upgrade in case of a apt-get upgrade since we are using a patched package

echo courier-maildrop hold | dpkg --set-selections

The hold-status can be switched by

echo courier-maildrop install | dpkg --set-selections

To verify your settings use

dpkg -l courier-maildrop

Below is an example for an output, given by the above verification-command

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?======(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=======bad)
||/  Name              Version        Description
+++-=================-==============-============
hi  courier-maildrop   0.47-4sarge4  Courier Mail Server - Mail delivery agent

Reading the first character will inform you about the status. Character h stands for hold and confirms that this package is not being upgraded automatically.

Configure Maildrop

Maildrop Configurationfile

To avoid a termination with error code Signal 0x0B the configuration-file must be created now. Here you find an example of a typical configuration file.

/etc/courier/maildropmysql.config

hostname             localhost
socket               /var/run/mysqld/mysqld.sock
port                 3306
database             pmwh2
dbuser               pmwh2_user
dbpw                 pmwh2_password
dbtable              users
default_uidnumber    1001
default_gidnumber    1001
uid_field            email
uidnumber_field      uid
gidnumber_field      gid
maildir_field        maildir
homedirectory_field  homedir
quota_field          quota
mailstatus_field     postfix
where_clause        AND postfix = 'y'

The privileges of this files are recommended as 600. Keep in mind that it contains the password for pmwh2.

Maildropscript

In order to give a detailed instruction of operation for maildrop we need the file /etc/courier/maildroprc wich contains these instructions.

/etc/courier/maildroprc

#
# Import variables
#

LOGNAME=tolower("$LOGNAME")
EXTENSION="$1"
RECIPIENT=tolower("$2")
USER="$3"
HOST="$4"
SENDER="$5"

DEFAULT="$HOME/$DEFAULT"
LOGUSERSETTINGS=1

#
# Autocreate logfile, if not existant
#

`test -e /var/log/mailfilter_log`
if ( $RETURNCODE != 0 )
{
    `touch /var/log/mailfilter_log`
}
 
logfile "/var/log/mailfilter_log"

if ( "$EXTENSION" ne "" )
{
    DELIMITER="+"
}

if (!$SENDER)
{
    SENDER = "<>"
}

#
# Autocreate maildir, if not existant
#

`test -e $DEFAULT`
if ( $RETURNCODE != 0 )
{
    `/bin/mkdir -p $DEFAULT`
    `/bin/rmdir $DEFAULT`
    `/usr/bin/maildirmake.courier $DEFAULT`
}

#
# Check that user has his own maildrop include,
# if not available, check if $DEFAULT is set
# (newer maildrop get's that from the DB and updates
# it) and deliver or fail temporarily if not available
#

`test -f $HOME/.mailfilters/$LOGNAME`
if ( $RETURNCODE == 0 )
{
    include "$HOME/.mailfilters/$LOGNAME"
}
else
{
    if ( "$DEFAULT" ne "" )
    {
        to "$DEFAULT"
    }
    else
    {
        EXITCODE=75
        exit
    }
}

Postfix-Adjustments

To let postfix know, that mails are forwarded to maildrop instead of using the own virtual-daemon the adjustments below need to be done. The value of the variable virtual_transport will be switched from virtual into maildrop

/etc/postfix/main.cf

...
# use this for virtual delivery 
#virtual_transport = virtual

#use this for maildrop-delivery 
virtual_transport = maildrop

# courier maildrop
maildrop_destination_concurrency_limit = 1
maildrop_destination_recipient_limit   = 1
...

Postfix also needs to know where exactly the target maildrop is located. It will be done by an adjustment of the file /etc/postfix/master.cf The original file should already contain an out-commented Line for maildrop Please note the whitespaces in the second and third line. Postfix is quite sensitiv regarding the syntax of master.cf

/etc/postfix/master.cf

maildrop  unix  -       n       n       -       -       pipe
 flags=R user=vmail argv=/usr/bin/maildrop
 -d ${user}@${nexthop} ${extension} ${recipient} ${user} ${nexthop} ${sender}

Credits

This Howto was originally written by Philipp Haefelfinger. Updated by --Chris 18:28, 15 September 2006 (CEST)