Procmailrc Beispiele
.forward file
"|IFS=' '&&exec /full/path/to/procmail -f-||exit 75 #your_login_name"
# '/full/path/to/' must be replaced with #
# the real path such as '/usr/local/bin/'. #
.procmailrc file
##############################################################
# #
# some examples of procmailrc #
# (c) 1996-1998 Tadashi Kawaguchi <ojin@erehwon.org> #
# Created on: 5/30/96 Last Modified on: 10/18/98 #
# #
##############################################################
# Set path #
PATH=/bin:/usr/bin:/usr/local/bin:/opt/local/bin/:$HOME/bin:$HOME:
SENDMAIL=/usr/lib/sendmail
SHELL=/bin/sh
# Set on when debugging #
#VERBOSE=on
VERBOSE=off
# Directory for storing procmail log and rc files
PMDIR=$HOME/.procmail
LOGFILE=$PMDIR/log
# Set environment variables #
UMASK=077
LOCKTIMEOUT=1024
TIMEOUT=960
SUSPEND=16
LINEBUF=4096
# rc files to be included #
INCLUDERC=$PMDIR/rc.sinkspam
INCLUDERC=$PMDIR/rc.autoinfo
INCLUDERC=$PMDIR/rc.autosend
INCLUDERC=$PMDIR/rc.ftpmail
INCLUDERC=$PMDIR/rc.mllist
#########################################################################
# forward and aliases #
# You must change dummy addresses like "your_login_name@your.domain" #
# to the real mail address. #
#########################################################################
# forward to your_logname@other.domain
:0
* ^TO.*your_login_name@hostname.domain
! your_logname@other.domain
#########################################
# aliases #
#########################################
:0
* ^TO.*your_login_name@your.domain.*
! your_logname@other.domain
####### aliases for administrator ########
:0
* ^TO.*(P|p|H|h)ostmaster@your.domain.*
! your_logname@other.domain
:0
* ^TO.*mailmaster@your.domain.*
! your_logname@other.domain
:0
* ^TO.*webmaster@your.domain.*
! your_logname@other.domain
:0
* ^TO.*ftpmaster@your.domain.*
! your_logname@other.domain
:0
* ^TO.*mlmaster@your.domain
! your_logname@other.domain
########### aliases for staff ############
:0
* ^TO.*somebody_1@your.domain.*
! foo@bar.another.domain
#########################################
# other aliases #
#########################################
########### from remote host ############
:0
* ^TO.*your_login_name@host
! your_logname@other.domain
########### from local host #############
:0
* ^TO.*your_login_name
! your_logname@other.domain
######### `To: foo@someother.domain' ########
:0
* ^Received:.*hostname.domain.*for .(alias-1|alias-2|...|alias-n)@your.domain.*$
! your_logname@other.domain
########### To unknown users ############
:0
* ^Received:.*hostname.domain.*for.*@your.domain.*$
* !^X-Loop: postmaster@your.domain
* !^FROM_DAEMON
{
TMPFILE=tmp.$$
TOADDRESS=`formail -uReceived: | formail -xReceived: \
| sed -e 's/^.*for <//' -e 's/>;.*$//'`
MAILDIR=$PMDIR/unknown_user
:0 ac:
$TMPFILE
:0 ah
| (formail -rA "X-Loop: postmaster@your.domain" \
-I "Precedence: junk" \
-I "From: postmaster@your.domain" \
-I "Subject: Returned Mail: Undeliverable" ; \
echo "The mail you sent could not be delivered to:" ; \
echo "$TOADDRESS is not a known user." ; \
echo "" ; \
echo "The first 100 lines for the original note follow..." ; \
echo "" ; \
head -100 ./$TMPFILE) \
| $SENDMAIL -oi -t -f'postmaster@your.domain'; \
rm -f $TMPFILE
}
########### from mailer-daemons #########
:0:
* ^FROM_MAILER
$PMDIR/daemon_mbox
########### trash other junk mails #########
:0
/dev/null
auto info
#########################
# autoreply info_file #
#########################
:0 h
* ^To:.*info@your.domain
| (formail -r -I "From: info@your.domain" \
-I "Reply-To: webmaster@your.domain" \
-I "Subject: your.domain information" \
-I "Errors-To: mailmaster@your.domain" ; \
cat $PMDIR/autoreply/info.txt) | $SENDMAIL -oi -t
auto send
#################################################################
# autosend requested one file #
# This script ignores the body of incoming mails and #
# does not return files that have names starting with a dot. #
# usage: #
# "Subject: send file the_file_you_want" #
# "To: sender@your.domain" #
#################################################################
:0 h
* ^Subject: send file [a-zA-Z0-9_].*
* ^To:.*sender@your.domain
* !^X-Loop: sender@your.domain
* !^Subject:.*Re:
* !^FROM_DAEMON
* !^Subject: send file .*[/.]\.
{
MAILDIR=$PMDIR/autoreply # chdir to the autoreply directory
:0 fhw # reverse mailheader and extract name
* ^Subject: send file \/[^ ]*
| formail -rA "X-Loop: sender@your.domain" \
-I "From: sender@your.domain"
FILE="$MATCH" # the requested filename
:0 ah
| cat - ./$FILE | $SENDMAIL -oi -t
}
get/put file
#################################################################
# auto get requested one file #
# it ignores the body of incoming mails and does not #
# return files that have names starting with a dot #
# usage #
# "Subject: get file the_file_you_want" #
# "To: geter@your.domain" #
#################################################################
:0 h
* ^To:.*geter@your.domain
* ^Subject: get file [a-zA-Z0-9_].*
* !^X-Loop: geter@your.domain
* !^Subject:.*Re:
* !^FROM_DAEMON
* !^Subject: get file .*[/.]\.
{
MAILDIR=$PMDIR/ftpmail # chdir to the archiver directory
:0 fhw # reverse mailheader and extract name
* ^Subject: get file \/[^ ]*
| formail -rA "X-Loop: geter@your.domain" \
-I "From: geter@your.domain"
FILE="$MATCH" # the requested filename
:0 ah
| cat - ./$FILE | $SENDMAIL -oi -t
}
#################################################################
# auto put requested one file #
# it does not put files that have names #
# starting with a dot #
# usage #
# "Subject: put file the_file_you_send" #
# "To: puter@your.domain" #
#################################################################
:0 h
* ^To:.*puter@your.domain
* ^Subject: put file [a-zA-Z0-9_].*
* !^X-Loop: puter@your.domain
* !^Subject:.*Re:
* !^FROM_DAEMON
* !^Subject: put file .*[/.]\.
{
PUTDIR=$PMDIR/ftpmail
SUBJECT=`formail -xSubject:`
FILENAME=`echo "$SUBJECT" | sed -e 's/^.*put file //'`
REPLYTO=`formail -xFrom:`
TMPFILE="tmp.$$"
MAILDIR=$PUTDIR # chdir to the archiver directory
:0 fhb
* ? test ! -f $FILENAME
| (formail -k -X Content-Type: -X Date: -X From: -X Subject: \
| cat > $PUTDIR/$FILENAME) ; \
ls -go > $PUTDIR/allfiles.txt ; \
touch $PUTDIR/$TMPFILE
:0 hc
* ? test ! -f $TMPFILE
| (formail -A "Precedence: junk" \
-I "To: $REPLYTO" \
-I "From: puter@your.domain" \
-I "Subject: Try again please" \
-A "X-Loop: puter@your.domain" ; \
echo "The filename $FILENAME already exists." ; \
echo "Please try again with another filename." ; \
echo "" ; echo "----" ; \
echo "puter@your.domain" ; \
) | $SENDMAIL -t
:0 hc
* ? test -f $TMPFILE
| (formail -A "Precedence: junk" \
-I "To: $REPLYTO" \
-I "From: puter@your.domain" \
-I "Subject: Thank you !" \
-A "X-Loop: puter@your.domain" ; \
echo "Your mail was saved into a file as follows:" ; \
echo "" ; \
ls -go $PUTDIR/$FILENAME ; \
echo "" ; echo "----" ; \
echo "puter@your.domain" ; \
) | $SENDMAIL -t ; \
rm -f $PUTDIR/$TMPFILE
}
sink spam
#########################################
# Sink mails that suspected as Spam #
#########################################
# `From Ô domains on the black list file
BLACKLIST=$PMDIR/banned.domains.txt
FROMDOM=`formail -x'From ' | sed -e 's/.*@//'`
ISBANNED=`grep -i "${FROMDOM}" $BLACKLIST`
:0
* ? test -n "$ISBANNED"
/dev/null
# `From:Ô domains on the black list file
BLACKLIST=$PMDIR/banned.domains.txt
FROMDOM=`formail -x'From:' | sed -e 's/.*@//'`
ISBANNED=`grep -i "${FROMDOM}" $BLACKLIST`
:0
* ? test -n "$ISBANNED"
/dev/null
# X-Advertisement header found in message
:0
* ^X-Advertisement:.*
/dev/null
# Bogus `To' addresses
:0
* ^TO((F|f)riend|(Y|y)ou|(H|h)ello)@.*
/dev/null
# Spam domains or keywords found in `Received:' header
:0
* ^Received:.*(ybecker.net|earthlink.net|CLOAKED|savetrees).*
/dev/null
# From a numerical userid
:0
* ^From[ :] *[0-9]+@.*
/dev/null
# From a numerical host.domain
:0:
* ^From[ :].*@[0-9]+\.[0-9]+
/dev/null
# Blank Message-Id
:0
* ^Message-Id: *$
/dev/null
# Null Message-Id
:0
* ^Message-Id: <>$
/dev/null
maling list
#########################################
# subscribe ml #
# add new subscriber to the list file #
#########################################
:0
* ^To:.*owner-ml@your.domain
* ^Subject:.*(s|S)ubscribe *ml
* !^X-Loop: owner-ml@your.domain
* !^Subject:.*Re:
* !^FROM_DAEMON
{
WELCOMEFILE=$PMDIR/ml/ml_welcome.txt # welcome message file
LISTFILE=$PMDIR/ml/ml.list # e-mail address file
TMPFILE=$PMDIR/ml/ml.list.tmp
FROMADDR=`formail -xFrom:`
:0 fhw
* ? test -f $LISTFILE
| (formail -xFrom: \
| sed -e 's/^ //' \
-e '/.*/y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
>> $LISTFILE) ; \
sort -f $LISTFILE > $TMPFILE ; \
uniq $TMPFILE > $LISTFILE
:0 ah
* ? test -f $TMPFILE
| (formail -A "Precedence: list" \
-I "To: $FROMADDR" \
-I "From: owner-ml@your.domain" \
-I "Subject: Welcome to our mailing list !" \
| cat - $WELCOMEFILE 2>&1 | $SENDMAIL -fowner-ml -oi -t) ; \
rm -f $TMPFILE # -f option can be used if you are
# a trusted user, and an alias
# `owner-ml: your_logname, nobody'
# should exist in /usr/lib/aliases
}
############################################
# signoff ml #
# remove a subscriber from the list file #
############################################
:0
* ^To:.*owner-ml@your.domain
* ^Subject:.*(s|S)ignoff *ml
* !^X-Loop: owner-ml@your.domain
* !^Subject:.*Re:
* !^FROM_DAEMON
{
LEAVEFILE=$PMDIR/ml/ml_leave.txt # good-bye message file
LISTFILE=$PMDIR/ml/ml.list
TMPFILE=$PMDIR/ml/ml.list.tmp
FROMADDR=`formail -xFrom:`
OLDADDR=`echo "$FROMADDR" \
| sed -e '/.*/y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
-e 's/.* <//' -e 's/>//' -e 's/ (.*)//' -e 's/^ //'`
DUMMY=`sed -e '/'$OLDADDR'/d' $LISTFILE > $TMPFILE`
:0 ah
* ? test -s $TMPFILE
| (formail -A "Precedence: list" \
-I "To:$FROMADDR" \
-I "From: owner-ml@your.domain" \
-I "Subject: See you again !" \
| cat - $LEAVEFILE | $SENDMAIL -fowner-ml -oi -t) ; \
rm -f $LISTFILE ; mv $TMPFILE $LISTFILE
}
#################################
# send help file #
#################################
:0
* ^To:.*owner-ml@your.domain
* ^Subject:.*(s|S)end *(h|H)elp.*
* !^X-Loop: owner-ml@your.domain
* !^Subject:.*Re:
* !^FROM_DAEMON
{
HELPFILE=$PMDIR/ml/ml_help.txt # help file for the list
:0 ah
* ? test -f $HELPFILE
| formail -rA "X-Loop: owner-ml@your.domain" \
-A "Precedence: list" \
-I "From: owner-ml@your.domain" \
-I "Subject: File: HELP" \
| cat - $HELPFILE | $SENDMAIL -fowner-ml -oi -t
}
#################################
# send list file #
#################################
:0
* ^To:.*owner-ml@your.domain
* ^Subject:.*(s|S)end *(l|L)ist.*
* !^X-Loop: owner-ml@your.domain
* !^Subject:.*Re:
* !^FROM_DAEMON
{
LISTFILE=$PMDIR/ml/ml.list
:0 ah
* ? test -f $LISTFILE
| formail -rA "X-Loop: owner-ml@your.domain" \
-A "Precedence: list" \
-I "From: owner-ml@your.domain" \
-I "Subject: File: SUBSCRIBER LIST" \
| cat - $LISTFILE | $SENDMAIL -fowner-ml -oi -t
}
#################################
# send archive of ML #
#################################
:0
* ^To:.*owner-ml@your.domain
* ^Subject:.*(s|S)end *(a|A)rchive.*
* !^X-Loop: owner-ml@your.domain
* !^Subject:.*Re:
* !^FROM_DAEMON
{
ARCHIVEFILE=$PMDIR/ml/ml_mbox # archived mbox of the list
:0 ah
* ? test -f $ARCHIVEFILE
| formail -rA "X-Loop: owner-ml@your.domain" \
-A "Precedence: list" \
-I "From: owner-ml@your.domain" \
-I "Subject: File: ML ARCHIVE" \
| cat - $ARCHIVEFILE | $SENDMAIL -fowner-ml -oi -t
}
#################################
# Unknown command #
#################################
:0
* ^To:.*owner-ml@your.domain
* !^X-Loop: owner-ml@your.domain
* !^FROM_DAEMON
{
HELPFILE=$PMDIR/ml/ml_help.txt
COMMAND=`formail -xSubject:`
:0 ah
* ? test -f $HELPFILE
| (formail -rA "X-Loop: owner-ml@your.domain" \
-A "Precedence: list" \
-I "From: owner-ml@your.domain" \
-I "Subject: Unknown command" ; \
echo "> $COMMAND" ; \
echo "The command you sent was not executable." ; \
echo "Here is the help for this list." ; \
echo "" ; \
cat - $HELPFILE) | $SENDMAIL -fowner-ml -oi -t
}
#########################################
# mailing list #
# initial $NUM = "111000" #
#########################################
:0
* ^To:.*ml@your.domain
* ^Sender: owner-ml@your.domain
/dev/null
:0
* ^To:.*ml@your.domain
* !^X-Loop: ml@your.domain
* !^FROM_DAEMON
{
LOCKTIMEOUT=2048
TIMEOUT=1920
SUSPEND=32
LINEBUF=20480
CNTFILE=$PMDIR/ml/ml.num
LOCKFILE=$CNTFILE$LOCKEXT
DUMMY=`lockfile -l2048 -s32 $LOCKFILE` # lock the count file
NUM=`cat $PMDIR/ml/ml.num` # get the serial number
NUM=`echo "$NUM + 1" | /bin/bc` # then increase it by one
DUMMY=`echo "$NUM" > $CNTFILE \ # increment the serial number
&& rm -f $LOCKFILE` # unlock the count file
# make sure that you have installed
# a 'lockfile' binary which is part
# of the procmail package.
LISTFILE=$PMDIR/ml/ml.list
FROMADDR=`formail -xFrom: \
| sed -e 's/.* <//' -e 's/>//' -e 's/ (.*)//'`
SUBJECT=`formail -xSubject:`
ISMEMBER=`grep -i "${FROMADDR}" $LISTFILE`
CNT=`echo "$NUM" | sed -e 's/^[1-9][1-9][0-9]//'`
NSUBJECT=`echo "$SUBJECT" | sed -e 's/^.*[0-9][0-9][0-9]\]//'`
NSUBJECT="[ml $CNT]$NSUBJECT" # add list name & serial number
:0 hw: $LOCKFILE # if not from a subscriber
* ? test -z "$ISMEMBER" # return an error message
| (formail -r -A "Precedence: junk" \
-I "From: owner-ml@your.domain" \
-I "Subject: Re: $SUBJECT - Undeliverable" \
-A "X-Loop: ml@your.domain" ; \
echo "The mail you sent could not be delivered." ; \
echo "Reason: Your are not a subscriber of this list.") \
| $SENDMAIL -oi -t ; \
echo "$NUM - 1" | /bin/bc > $CNTFILE # decrement the serial number
:0 wc
* ? test -n "$ISMEMBER"
| (formail -A "X-Loop: ml@your.domain" \
-A "Precedence: junk" \
-I "Reply-To: ml@your.domain" \
-I "Sender: owner-ml@your.domain" \
-I "Subject: $NSUBJECT") \
| $SENDMAIL -fowner-ml `cat $LISTFILE`
:0 a: # archive the message shorter than 1000 bytes
* < 1000
ml_mbox
}