Difference between revisions of "Procmail"

From YobiWiki
Jump to navigation Jump to search
Line 77: Line 77:
   
 
==[[Mail_Tips#mairix|Calling mairix by writing emails]]==
 
==[[Mail_Tips#mairix|Calling mairix by writing emails]]==
  +
==[[Alert_notifications#Jabber.2FSMS_alerts|Sending Jabber notifications]]==
   
 
==Sort and copy==
 
==Sort and copy==

Revision as of 23:53, 20 September 2008

Installation

apt-get install procmail

installer les ~/.procmailrc tels que celui-ci:

Exemple de ~/.procmailrc:

#Preliminaries
SHELL=/bin/bash               #Use the Bourne shell (check your path!)
MAILDIR=${HOME}/Maildir/      #First check what your mail directory is!
LOGFILE=${MAILDIR}procmail.log
DEFAULT=${MAILDIR}
ORGMAIL=${MAILDIR}
#LOG="--- Logging ${LOGFILE} for ${LOGNAME}, "
UMASK=007
COMSAT=no                     # If you don't use biff/comsat notifier

#Troubleshooting:
VERBOSE=no
#LOGABSTRACT=all
LOGABSTRACT=no

#Whatever recipes you'll use
#The order of the recipes is significant

## Pour utiliser une install locale de spamassassin:
## On trie ce qui a déjà été scanné et taggué comme spam:
:0
* ^X-Spam-Status: Yes|\
  ^X-Spam-Flag: YES|\
  ^Subject: \*\*\*\*\*SPAM\*\*\*\*\*
.SPAM/
## On appelle spamassassin puis on continue les règles de tri
:0fw: spamassassin.lock
* <
| /usr/local/bin/spamassassin -a
## On écarte les mails taggués comme spam
:0
* ^X-Spam-Flag: YES
.Internet.SPAM/

## Exemple complexe pour envoyer un SMS via un mail avec pour sujet: "[1] corps du SMS"
## [SMS:]
#:0 c
#* ^Subject: \[SMS:[0-9]+\]
#|gawk '/^Subject: \[SMS/{sub(/^Subject: \[SMS:[0-9]+\]/,"");print}'|linuxsms -server:gomobile2 -prefix:32 -number:$MATCH

:0
* ^From: root@teuwen\.org
.Logs/

# Pour trier toutes les mailing-lists de Debian dans des folders séparés:
:0
* ^X-Mailing-List: <debian-.+@lists\.debian\.org>
* ^X-Mailing-List: <debian-\/[-a-zA-Z0-9]+
.Debian.$MATCH/

Voir MailServer, section Procmail pour plus d'infos
ainsi que:

apt-get install procmail-lib

Pour vérifier la syntaxe du fichier:

proclint ~/.procmailrc

Nombreuses recettes dans /usr/share/procmail-lib qu'on peut inclure via INCLUDERC,
cf /usr/share/doc/procmail-lib/examples

winmail.dat

Pour décoder les attachements d'Outlook, utiliser ytnef et éventuellement l'intégrer à procmail:

apt-get install ytnef libmime-perl libmailtools-perl

(en tant q'utilisateur:)

mkdir -p ~~/.ytnef/output

dans ~/.procmailrc, ajouter qqch comme:

PATH=/bin:/usr/bin
HOME=/home/<user>
:0fw
* > 0
| /usr/bin/ytnef-filter

Calling mairix by writing emails

Sending Jabber notifications

Sort and copy

Le but de ce setup est de trier les mails, les marquer comme lus, et placer une copie non-lue dans un répertoire commun .
Ainsi pour consulter les nouveaux mails, un seul répertoire à regarder où l'on efface au fur et à mesure les mails qu'on a lu.
Les mails triés habituellement servent alors uniquement d'archives.

.procmail-file.rc

#.procmail-file.rc
#
# Author: Philippe Teuwen <phil@teuwen.org>
#
# Set these variables before invoking:
#
# As global:
# COPYDEST      Destination to drop a copy of the filed mail, this copy will be left unread
# Per rule:
# REGEXn        With n=1..3, allows to have up to three regexps on the headers (^ is already prepend)
# DEST          Destination into which addressed mail will be dropped, this copy will be marked as read
# NOCOPY=1      (opt) Set the variable to avoid leaving the copy, only filing and marking as read
# INCLUDERC=.procmail-file.rc

:0
* $REGEX3 ?? .
* $REGEX2 ?? .
* $REGEX1 ?? .
* $ ^$REGEX1
* $ ^$REGEX2
* $ ^$REGEX3
{
  :0 c
  * ! $NOCOPY ?? .
  $COPYDEST

  # To file the mail as usual (c is just to continue rules processing, the copy won't be used)
  :0 c
  $DEST

  # To mark the last mail as read by renaming the file
  :0 ai
  * LASTFOLDER ?? ()\/[^/]+^^
  |mv "$LASTFOLDER" "$DEST/cur/$MATCH:2,S"
}

:0
* ! $REGEX3 ?? .
* $REGEX2 ?? .
* $REGEX1 ?? .
* $ ^$REGEX1
* $ ^$REGEX2
{
  :0 c
  * ! $NOCOPY ?? .
  $COPYDEST

  # To file the mail as usual (c is just to continue rules processing, the copy won't be used)
  :0 c
  $DEST

  # To mark the last mail as read by renaming the file
  :0 ai
  * LASTFOLDER ?? ()\/[^/]+^^
  |mv "$LASTFOLDER" "$DEST/cur/$MATCH:2,S"
}

:0
* ! $REGEX3 ?? .
* ! $REGEX2 ?? .
* $REGEX1 ?? .
* $ ^$REGEX1
{
  :0 c
  * ! $NOCOPY ?? .
  $COPYDEST

  # To file the mail as usual (c is just to continue rules processing, the copy won't be used)
  :0 c
  $DEST

  # To mark the last mail as read by renaming the file
  :0 ai
  * LASTFOLDER ?? ()\/[^/]+^^
  |mv "$LASTFOLDER" "$DEST/cur/$MATCH:2,S"
}

REGEX1=
REGEX2=
REGEX3=
NOCOPY=

.procmailrc

COPYDEST=.Already_filed/
FILER="${HOME}/.procmail-file.rc"

# Example: 2 regex to select mail s from root and with subject Cron
REGEX1="From:.*root"
REGEX2="Subject: Cron"
DEST=.Logs.Cron/                        INCLUDERC=$FILER

# Another example: reminders are folded and marked as read but
# we don't even want to see them in our COPYDEST
REGEX1="Subject:.*mailing list memberships reminder"
NOCOPY=1
DEST=.Mailing-lists.reminders/          INCLUDERC=$FILER