Lire maildrop - mail delivery filter/agent pour les bases de la documentation.

Pour une documentation avec ses exemples.

Un autre exemple plus avancé de l'utilisation de maildrop.

/home/vmail/.mailfilters/user@domaine.com :

# Mini DOC
#
# Make this "cc" for copy or "to" to not send it to Inbox.
# http://www.courier-mta.org/maildrop/
#
#cc
#    copier le mail dans un fichier (dossier).
#dotlock
#    ???
#flock
#    ???
#gdbmopen
#    ???
#log
#    marquer quelquechose dans le fichier de log.
#logfile
#    definir le fichier le log.
#to
#    deposer le mail dans un fichier (dossier).
#xfilter
#    running external commands.
logfile "/home/vmail/.mailfilters/$RECIPIENT-log.txt"
########################################################################### MONAPP
# Extraction des pièces jointes
if ( /^Subject:.*.csv/ )
{
  log ".csv"
  to "|uudeview +o -a -i -q -n -p /home/vmail/user/csv -e .html.tif.jpg.gif -"
}
# Extraction des fichiers de logs
# [ORDI] Logs du 09/06/2008
if ( /^Subject:.*[ORDI] Logs du .*/ )
{
  log "ORDI Log"
  to "|uudeview +o -a -i -q -n -p /home/vmail/user/ORDIlog +e .txt -"
}
# Extraction des POUPOU
if ( /Num POUPOU/:b \
  || /^Subject:.*(POUPOU|PAPA).*/ \
)
{
   log "POUPOU - cc another.user@domain.com"
   cc "!another@domain.com"
   log "POUPOU - appel du PROG extraction body et content"
   xfilter "/home/vmail/user/mail2files.sh"
   log "POUPOU - fin"
#   log "extraction du body content"
#   xfilter "sed '1,/^$/d' > /home/vmail/user/poupou/`date +%Y%m%d%H%M%S`.body.txt"
#   log "PO 1/ PIPE"
#   #xfilter "xargs > /home/vmail/user/po/`date +%Y%m%d%H%M%S`.txt"
#   cc "|xargs > /home/vmail/user/po/`date +%Y%m%d%H%M%S`.txt"
#   log "PO 2/ uudeview"
#   to "|uudeview +o -a -i -q -n -p /home/vmail/user/po +e .html.zip -"

}
# Tous les autres mails
  log "Tout autre mail (else) -> /dev/null"
  to "/dev/null"

Avec mail2files.sh :

#!/bin/sh
# Permet d'extraire le contenu ASCI du mail vers un fichier txt
# Extraction des pièces jointes du mail vers un dossier

fichier=`date +%Y%m%d%H%M%S`

sed '1,/^$/d' > /home/vmail/user/po/$fichier.body.txt

cat /home/vmail/user/po/$fichier.body.txt|uudeview +o -a -i -q -n -p /home/vmail/user/poi +e .html.zip -

Egalement /etc/maildroprc :

LOGNAME=tolower("$LOGNAME")
RECIPIENT=$LOGNAME
#RECIPIENT=tolower("$1")
DEFAULT="/home/vmail/$RECIPIENT/."
RACINEMAIL="/home/vmail/$RECIPIENT"
logfile "/home/vmail/.mailfilters/maildroprc-log.txt"
log "- Linux-bugtraq "
#log "LOGNAME:$LOGNAME RECIPIENT:$RECIPIENT"
if ( "$EXTENSION" ne "" )
{
  DELIMITER="+"
}
if (!$SENDER)
{
  SENDER = "<>"
}
#
# Autocreate maildir, if not existant
#
`test -e /home/vmail/$RECIPIENT`
if ( $RETURNCODE != 0 )
{
  `maildirmake /home/vmail/$RECIPIENT`
  `chmod -R 0700 /home/vmail/$RECIPIENT`
}
else
{
  `maildirmake /home/vmail/$RECIPIENT`
  `chmod -R 0700 /home/vmail/$RECIPIENT`
}
#
# 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/vmail/.mailfilters/$LOGNAME`
if ( $RETURNCODE == 0 )
{
  log "LOGNAME:$LOGNAME RECIPIENT:$RECIPIENT , has its own filter"
  include "/home/vmail/.mailfilters/$LOGNAME"
}
else
{
  log "LOGNAME:$LOGNAME RECIPIENT:$RECIPIENT , default filter"
  if ( "$DEFAULT" ne "" )
  {
    #if ( /^Subject: SPAM/)
    #if ( /^X-Spam-Level: *-.*$/ )
    if ( /^X-Spam-Level: \*\*\*/ )
    {
      `test -e /home/vmail/$RECIPIENT/.spam`
      if ( $RETURNCODE != 0 )
      {
        `maildirmake /home/vmail/$RECIPIENT/.spam`
        `chmod -R 0700 /home/vmail/$RECIPIENT/.spam`
      }
      log "- Spam general. "
      to "/home/vmail/$RECIPIENT/.spam" # Make this "cc" for copy or "to" to not send it to Inbox.
    }
    else
    {
      to "$DEFAULT"
    }
  }
  else
  {
    EXITCODE=75
    exit
  }
}

Extraction des pièces jointes des mails

xfilter "uudeview -i -a +o -v -n -q -p /home/vmail/folder/data/files - 1>/dev/null"

Faire suivre un mail en changeant les en-tête expéditeur (Foward and deplace From header with procmail and reformail)

if ( /^From:.*mail@domaine.com.*/ )
{
       log "mail@domaine.com > another.mail@anydomain.com"
       xfilter "reformail -A'From: new.replace.from.user@anywhere.com' | reformail -U'From:'"
       cc "!another.mail@anydomain.com"
       to "/dev/null"
}

Ressources