Wed 22 Nov 2006
Procmail recipes
Posted by Richard under Configuration , Maintenance , Software , WesthostComments Off
If you want to modify your procmail.rc rules file, then I suggest that you try your rule in isolation first before you break procmail and cause problems.
The first thing to do is to create the file with your test rule in it.
- pico proctest.rc
C:
-
SHELL=/bin/sh
-
TESTDIR=/home/rollingr/test
-
MAILDIR=${TESTDIR}
-
LOGFILE=${TESTDIR}/results.log
-
LOG="--- Logging for ${LOGNAME}, "
-
-
#Troubleshooting:
-
VERBOSE=yes
-
LOGABSTRACT=all
-
-
-
##Insert your rule here instead of sample ##
-
# Start of sample recipe to bounce blacklisted mail
-
:0
-
# Test whether required user is in any of these fields
-
#Original-, Resent-, To, Cc, Bcc,.X-Envelope-To, Apparently-To or -Resent-To
-
* ^TO_requireduser@mydomain.com
-
# If match found then
-
{
-
# Check if the sender is whitelisted
-
# Lock destination file for writing if match
-
:0:
-
# Extract headers From, Sender, Reply-To, Return-Path, To
-
# and compare to entries in white.list
-
# Entries should take form [email]me@my\.domain[/email]
-
# otherwise dot will match any character
-
# grep case insensitive, supress errors
-
# Click for a full explanation of [url=http://unixhelp.ed.ac.uk/CGI/man-cgi?egrep]egrep[/url]
-
* ? formail -x"From" -x"From:" -x"Sender:" \
-
-x"Reply-To:" -x"Return-Path:" -x"To:" \
-
| egrep -is -f white.lst
-
# If match found, deliver to /path/to/mailbox and stop
-
/path/to/mailbox
-
-
# Bounce unwanted mail
-
# Start test - strip body from message
-
:0 h
-
# If not from mailing daemon
-
* ! ^FROM_DAEMON
-
# and not bounce of a bounce
-
* ! ^X-Loop: bounced@mydomain.com
-
# then pipe header with extra bounced header and error message in body to sendmail and stop
-
| ( formail -rt -A "X-Loop: bounced@mydomain.com"; \
-
echo "Your email address is not on our whitelist. Please go to [url]http://www.mydomain.com/whitelist[/url] and subscribe"; \
-
) | $SENDMAIL -t
-
-
# If we got this far, then message is on blacklist and was previously bounced or is from the mailing daemon, so throw it away and stop
-
# Bin everything else sent to this user (such as bounces)
-
:0
-
/dev/null
-
}
-
# if not to required user then continue processing
-
-
## End of sample Recipe ##
-
-
-
# Catch anything that failed test Recipe here
-
:0
-
${TESTDIR}failed.mail
Now we need to create the supporting files
-
- pico white.lst
anyuser\@gmail\.com - Generate a valid message file which will trigger the rule
CODE:
-
From anyuser@gmail.com Wed Nov 15 08:48:26 2006
-
Return-Path: <anyuser@gmail.com>
-
Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.170])
-
by mydomain.com (8.11.6/8.11.6) with ESMTP id kAFFmPd29195
-
for <me@mydomain.com>; Wed, 15 Nov 2006 08:48:25 -0700
-
Received: by 10.66.252.9 with HTTP; Wed, 15 Nov 2006 07:48:23 -0800 (PST)
-
Message-ID: <6757a1050611150748h6b0ada1fkf4dfe9aaefe721db@mail.gmail.com>
-
Date: Wed, 15 Nov 2006 15:48:23 +0000
-
From: "Sender" <anyuser@gmail.com>
-
To: "Recipient" <me@mydomain.com>
-
Subject: Testing Mail Header
-
MIME-Version: 1.0
-
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
-
Content-Transfer-Encoding: 7bit
-
Content-Disposition: inline
-
-
This is a test for procmail
-
-
--
-
Richard
Next create a batch file to run the rule. Point TESTDIR to your directory.
-
- pico procmail.bat
C:
-
#!/bin/sh
-
#The executable file named "proctest"
-
#
-
# You need a test directory.
-
TESTDIR=/home/yourlogin/test
-
if [ ! -d ${TESTDIR} ] ; then
-
echo "Directory ${TESTDIR} does not exist; First create it"
-
exit 0
-
fi
-
#
-
#Feed an email message to procmail. Apply proctest.rc recipes file.
-
#First prepare a mail.msg email file which you wish to use for the
-
#testing.
-
procmail ${TESTDIR}/recipe.rc <mail.msg
-
#
-
#Show the results.
-
less ${TESTDIR}/results.log
-
#
-
#Clean up.
-
rm -i ${TESTDIR}/results.log
-
rm -i ${TESTDIR}/failed.mail
-
- And make it an executable
chmod u+x procmail.bat - Run the test
procmail.bat

