User Tools

Site Tools


Sidebar

documentation:systemes:services:mail:maildrop

Introduction

Cette documentation n'est rien de plus qu'un “copier/coller” de la documentation rédigée par Goran Jurić et dont vous pourrez retrouver l'original sur son wiki personnel.

Installation

Il faut simplement installer le paquet maildrop (et non courrier-maildrop).

apt-get install maildrop

Configuration

Il faut éditer (ou créer) le fichier /etc/maildroprc

# Global maildrop filter file

# Uncomment this line to make maildrop default to ~/Maildir for
# delivery- this is where courier-imap (amongst others) will look.
#DEFAULT="$HOME/Maildir"
HOME_DIR="/home/vmail"
logfile "/var/log/maildroprc.log"
EXTENSION="$1"
RECIPIENT=tolower("$2")
USER="$3"
HOST="$4"
SENDER="$5"
DEFAULT="$HOME_DIR/$HOST/$USER"
MAILFILTERUSER="$DEFAULT/.mailfilter"

# Check if host and user directory exist
`test -e $HOME_DIR/$HOST/$USER`
#log "Testing for $HOME_DIR/$HOST subdirectory: result=$RETURNCODE"
## Only continue if directory does NOT exist
if ($RETURNCODE != 0)
{
        log "MailDir $HOME_DIR/$HOST/$USER does NOT exist"
        `test -e $HOME_DIR/$HOST`
        if ( $RETURNCODE != 0 )
        {
                log "Creating $HOME_DIR/$HOST"
                `mkdir $HOME_DIR/$HOST`
                `chmod -R 0700 $HOME_DIR/$HOST`
        }
        # Create users MailDir
        `maildirmake $HOME_DIR/$HOST/$USER`
}

`test -e ${MAILFILTERUSER}`
if ( $RETURNCODE == 0 )
{
        exception {
                log "Including ${MAILFILTERUSER}..."
                include "${MAILFILTERUSER}"
        }
}

if (/^X-Spam-Flag: YES/)
{
        EXTENSION = "Junk"

        # See if the spam directory already exists
        `test -e $HOME_DIR/$HOST/$USER/.$EXTENSION`
        log "Testing for $EXTENSION subdirectory: result=$RETURNCODE"
        if ( $RETURNCODE != 0 ) # spam directory does not exist - so we create it
        {
                 `maildirmake -f $EXTENSION $HOME_DIR/$HOST/$USER`
                log "Ran \"maildirmake -f $EXTENSION $HOME_DIR/$HOST/$USER\""

                `if ! grep -q INBOX.$EXTENSION $HOME_DIR/$HOST/$USER/courierimapsubscribed; then echo INBOX.$EXTENSION >> $HOME_DIR/$HOST/$USER/courierimapsubscribed; fi`
        }

        exception {
                 `if ! grep -q INBOX.$EXTENSION $HOME_DIR/$HOST/$USER/courierimapsubscribed; then echo INBOX.$EXTENSION >> $HOME_DIR/$HOST/$USER/courierimapsubscribed; fi`
                to "$HOME_DIR/$HOST/$USER/.$EXTENSION"
        }
}

Logs

touch /var/log/maildroprc.log
chown vmail:vmail /var/log/maildroprc.log

Mise en place de la règle pour logrotate :

/var/log/maildroprc.log {
    rotate 7
    daily
    compress
    delaycompress
    copytruncate
    notifempty
}

Postfix

Nous devons également modifier la configuration de postfix afin qu'il utilise maildrop pour le transit des mails.

/etc/postfix/main.cf

virtual_transport = maildrop
maildrop_destination_concurrency_limit = 2
maildrop_destination_recipient_limit = 1

/etc/postfix/master.cf

maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}

Devient :

maildrop  unix  -       n       n       -       -       pipe
  flags=ODRhu user=vmail:vmail argv=/usr/bin/maildrop -w 90 -d ${user}@${nexthop}
  ${extension} ${recipient} ${user} ${nexthop}

Et enfin on relance postfix pour intégrer les nouvelles directives :

/etc/init.d/postfix restart
documentation/systemes/services/mail/maildrop.txt · Last modified: 2017/07/14 19:45 (external edit)