|
Created and maintained by
Jacek Olszewski
Menu software by
PHP Layers Menu System
|
Procmail script for white and black lists
It assumes MTA (mail transmission agent) to be
sendmail, and procmail as a
message delivery mechanism.
It uses 5 files files in user's mail directory. Their names and contents
are given in the script below. To be called when a message arrives, it
requires the following line in the file called .forward in the same
directory:
|
"| /usr/bin/procmail -f-"
|
The script should have the name .procmailrc, and contain:
# $HOME/.procmailrc for $LOGNAME in a Linux host
# logging by 'formail -l' rather than by procmail
# logs of the last 3 days available for the user
LOGABSTRACT=off
LOGF=$HOME/mail.log
DOMAIN=your.domain #modify appropriately
# s.lst filtering status, containing ON or OFF
# c.lst contains code (password) to appear in plussed alias between + and @
# in automatic request, has to be other than 00 (see [1] and [7]),
# w.lst white list of addresses
# b.lst black list of addresses
# r.lst contains request to send an amty message to the plussed alias
# [1] message to the address from which request is sent (see [7]), discard,
# thus blocking non-delivery messages and bouncing loops
:0
* $ ^To:.*$LOGNAME\+00
| formail -l discarded >> $LOGF
# [2] message from MAILER-DAEMON, accept irrespective of filtering
:0
* ^From:.*MAILER-DAEMON
{
:0 ch
| formail -l accepted >> $LOGF
:0
${DEFAULT}
}
# [3] message to the coded address, put sender's address on white list,
# send acknowledgment,
:0
* ? formail -x"To:" | fgrep + | fgrep -c -f $HOME/c.lst
{
:0 ch
| formail -l whitelisted >> $LOGF
# extract sender's address proper (w/o < >)
:0 h
EADDR=| formail -x"From:" | sed 's/^\([^@]*[ <]\)//' | sed 's/\([ >]\).*$//'
# append sender's address to white list, if it's not there already
:0 ch
* ! ? fgrep -s $EADDR $HOME/w.lst
| echo $EADDR >> $HOME/w.lst
:0
| (formail -r;\
echo Thank you. From now on, your messages to $LOGNAME@$DOMAIN;\
echo will be accepted with no further obstacles.;\
echo Please, resend your original message.)\
| $SENDMAIL -t -oi
}
# [4] if filtering is OFF, accept everything
:0
* ? fgrep -s OFF $HOME/s.lst
{
:0 ch
| formail -l accepted >> $LOGF
:0
${DEFAULT}
}
# [5] message from an address on white list,
# tolerate plussed-numbered addresses, accept
:0
* ? test -s $HOME/w.lst
* ? formail -x"From:" -x"Reply-To"\
| sed 's/\(\+[^@ <]*\)@/@/ig' | fgrep -is -f $HOME/w.lst
{
:0 ch
| formail -l accepted >> $LOGF
:0
${DEFAULT}
}
# [6] message from an address on black list, discard
:0 h
* ? test -s $HOME/b.lst &&\
formail -x"From:" -x"Reply-To" \
| sed 's/\(\+[^@ <]*\)@/@/ig' | fgrep -is -f $HOME/b.lst
| formail -l discarded >> $LOGF
# [6a] message w/o From: or Reply-To:
:0 h
* ? test -z `formail -x"From:"`
| sed s/MAILER-DAEMON/UNKNOWN/ | formail -l discarded >> $LOGF
# [7] message from an address on neither list, discard and
# send the request to the sender from $LOGNAME+00 address, see [1]
:0
{
:0 ch
| formail -l challenged >> $LOGF
:0 h
| (formail -r -I"From: $LOGNAME+00@$DOMAIN";\
cat $HOME/r.lst) | $SENDMAIL -t -oi -f$LOGNAME+00@$DOMAIN
}
# 20 Jun 2008: modify [6] to simplify tests of w.lst and b.ls
# add [6a] for empty From: and Reply-To:
# 29 Jan 2005: correct [6] for empty black list
# 19 Jan 2005: correct [5] and [6] for user@ and @domain.name
# 29 Dec 2004: strict full address, no prefixes in [5] and [6]
# 29 Mar 2004: correct [3] for code eq username, and [5] for empty white list
# 3 Mar 2004: accepting plussed (+00) addresses to break possible deadlock
# between 2 people using pef [5]
# 2 Oct 2003: logging by formail -l discarded|challenged|whitelisted|accepted
# 29 Jul 2003: correct extraction of sender's address in [3]
# 22 Jul 2003: add flags fh in [7]
|
You may grab (copy&paste) the scripts above, modify them appropriately, and, together
with 5 files mentioned in the scripts, install them
in your mail directory on the server. Alternatively, you may fetch
w-b-lists.tgz from downloads, containing the above scripts and the 5 files that you
can modify and install. If you do not have shell or
ftp access to your home directory on the mail server, you may ask your administrator to do that.
It would be much easier for you, if you could persuade your administrator to
install pef (Personal Email Filter) for use by every email user, see
pef under tools. It is a web interface for handling white and
black lists, code (password), automatic response to unknown senders, and
switching filtering ON and OFF, with no need to have a shell or ftp access to
your home directory. It includes the above scripts, to be installed
by the administrator system wide.
next
|