On Fri, 6 Aug 1999, Dave wrote:
I am fairly new at procmail, so any suggestions, rewrites,
corrections, or different approaches are welcome.
Instead of using the built in features of procmail, you seem to be doing
everything manually. For example the grep in the pattern line. Here is a
far simpler script that works. My comments are always after each piece of
code.
# if you touch reject.rc.log, you'll get copious
# logging info remove reject.rc.log after you're sure
# it works.
:0
* ? test -f reject.rc.log
{ LOGFILE=reject.rc.log LOGABSTRACT=all VERBOSE=yes }
No change here.
REJECTFILE=reject-list # file containing
# addresses to reject
# and bounce back mail to
Do instead REJECTFILE=`cat reject-list`
and make sure that the reject-list file is a | seperated list (no
spaces) between each address. ie. ad1(_at_)d(_dot_)d|ad2(_at_)b(_dot_)c etc.
FORMAIL=formail # /usr/local/bin/formail
Not needed.
FROM=`formail -rtzXTo:` # get who it's from
# if the sender is in the reject file, then capture
# and forward a copy to one or two individuals.
:0 :$REJECTFILE.lock
* $ ! ^X-Loop: *$LOGNAME(_at_)$HOST
* ? grep -s "$FROM" $REJECTFILE
Ouch.
First don't lock. It's not needed. I really don't think the X-Loop part is
needed either.
Make the pattern:
:0
* $ ^(From|Sender):.*($REJECTFILE)
{
Much much simpler. Keep in mind that this can't catch cases where someone
is obscuring his address. I added sender to help a little. You can change
the pattern as you like.
DELIVERED=yes # tell sendmail that
# the mail was delivered
Don't need this, the message will be delivered at the end anyway.
COMSAT=no # but be quiet about it
Not needed either for this script.
# First make a copy of the entire mail
REJECTMAIL=reject.mail
Ok, but put this line at the top of the file.
LOCKFILE=$REJECTMAIL.lock
Let procmail name the locks automatically. So don't do this.
:0c
$REJECTMAIL
You forgot to lock, (the script is different, and only this part needs a
lock now).
:0c:
$REJECTMAIL
#this keeps a copy of each message, if you don't want that remove it.
# Replace the mail with a reply
FROMSIG="$LOGNAME's Mailer-Daemon <$USER>"
SUBJECT="This email has been captured/rejected"
# (Note: do not use -k here; "h" recipes include
# the blank line in the headers, and formail -r
# generates a blank line also. If you use '-k',
# then the original blank line will be kept, and
# the additional will be added, resulting in two
# blank lines).
:0 fhw
| $FORMAIL -rtI"To: user1(_at_)ourcompany(_dot_)com, \
user2(_at_)ourcompany(_dot_)com" \
-I"From: $FROMSIG" \
-I"Subject: $SUBJ" \
-I"X-Loop: $LOGNAME(_at_)$HOST" \
-I"Precedence: junk" \
; echo "The postmaster account has captured" \
; echo "the following email and sent a copy" \
; echo "to you for your records." \
; echo "" \
; echo "The original mail follows:" \
; echo "-------------------------------" \
; cat $REJECTMAIL
# release the lock file now
LOCKFILE
# Finally, deliver it
:0 w
! -oi -t
OUCH!!
Here is a much better script: (let procmail do the work!)
MESSAGE='\
The postmaster account has captured \
the following email and sent a copy \
to you for your records. \
\
The original mail follows: \
------------------------------- \
'
:0fbw
| sed 1i"$MESSAGE"
# the sed simply inserts the $MESSAGE at the start of the message.
:0
! user1(_at_)ourcompany(_dot_)com, user2(_at_)ourcompany(_dot_)com
#let procmail deliver it, no need for formail.
}
-Ariel