Maildrop

De Wiki NCad
Révision de 19 février 2014 à 01:28 par Cacheln (discuter | contributions) (Page créée avec « == Installation == * On installe le service maildrop : {{ Box Console | objet=sudo apt-get install maildrop }} == Configuration == === Postfix === * On édite le fich... »)

(diff) ← Version précédente | Voir la version courante (diff) | Version suivante → (diff)
Aller à : navigation, rechercher

Installation

  • On installe le service maildrop :
ICON Terminal.png

sudo apt-get install maildrop

Configuration

Postfix

  • On édite le fichier /etc/postfix/main.cf et on remplace :
virtual_transport = virtual
  • Par :
virtual_transport = maildrop
maildrop_destination_recipient_limit = 1
  • Dans le fichier /etc/postfix/master.cf on remplacera :
maildrop  unix  -       n       n       -       -       pipe
 flags=DRhu user=vmail:vmail argv=/usr/bin/maildrop -d ${recipient}
  • Par :
maildrop  unix  -       n       n       -       -       pipe
 flags=DRhu user=vmail:vmail argv=/usr/bin/maildrop -w 90 -d ${user}@${nexthop} ${extension} ${recipient} ${user} {nexthop}
  • On crée le fichier de configuration /etc/maildroprc et on y ajoute la ligne suivante :
DEFAULT="/var/mail/vmail/"
  • Les règles de routage des mails sont écrites dans le fichier /var/mail/vmail/.mailfilter. Le fichier ci-dessous crée le répertoire mail de l'utilisateur au cas où il n'existerait pas. Ce script permet également de placer les messages identifiés comme SPAM dans un dossier séparé.
# Global maildrop filter file (used on Debian)
# For use with Postfix/Courier IMAP/Amavisd-new virtual mailbox domains.
#
# This maildroprc automagically creates a Spam folder for the recipient
# and places spam there. It also subscibes the recipient to the folder.
#
# Example maildir: /home/vmail/example.com/user/
#
# Also in main.cf:
# virtual_transport = maildrop
# maildrop_destination_concurrency_limit = 2
# maildrop_destination_recipient_limit = 1
#
# and in master.cf:
#
# maildrop  unix  -       n       n       -       -       pipe
#  flags=DRhu user=vmail:vmail argv=/usr/bin/maildrop -w 90 -d ${user}@${nexthop}
#  ${extension} ${recipient} ${user} ${nexthop}
#
# /var/log/maildroprc.log needs to exist and owned by vmail:vmail and
# a logrotate script needs to be created.
#
HOME_DIR="/var/mail/vmail"
EXTENSION="$1"
RECIPIENT=tolower("$2")
USER="$3"
HOST="$4"
SENDER="$5"
DEFAULT="$HOME_DIR/$HOST/$USER"
 
# 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`
}
 
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
       {
               # Create the subdirectory
               `maildirmake -f $EXTENSION $HOME_DIR/$HOST/$USER`
               log "Ran \"maildirmake -f $EXTENSION $HOME_DIR/$HOST/$USER\""

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

       # Deliver the message to the mailbox
       exception {
               # for those who unsubscribed themselves - subscribe them
               `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"
       }
}
  • On applique les permissions adéquates sur les fichiers utilisés par maildrop :
ICON Terminal.png

chown vmail:daemon /etc/maildroprc chown vmail:daemon /var/run/courier/authdaemon/ -R chown vmail:vmail /var/mail/vmail/.mailfilter