1.match the approved recipients list.
2.contain the correct code in the subject header to be submitted
for entry into the approved recipients list. This means that this
message will be read by myself and I shall manually add that user
to the list.
any other mail I want discarded and resent back to the recipient with
instructions on how to get added to the approved recipients list. I also
want to return the original message back to the recipient.
1. How do I capture the text of the original message? Do I have to archive
it in a temporary file for my reply recipe to use later?
Through clever use of the 'c' flag, the 'f' flag, and formail, you can
avoid having to stick the message in a temporary location. Here's an
off-the-cuff example that accomplished the bulk of your requirements
(comments follow):
# The following are guaranteed to be available in my own procmail
# setup, but should probably be defined explicity here:
SHELL=/bin/sh
FORMAIL=/usr/local/bin/formail
FGREP=/bin/fgrep
SED=/bin/sed
CAT=/bin/cat
:0
* ^From: *\/[^ ].*
{ FROM=$MATCH }
:0
* ^Subject: *\/[^ ].*
{ SUBJECT=$MATCH }
# And now for that example... :-)
SPAM_ACCEPT_LIST=$HOME/etc/accept
SPAM_MESSAGE=$HOME/etc/spam.message
SPAM_CODE="SPAMISBAD"
# A message will enter rejection processing if the sender is not in the
# list of accepted recipients.
:0
* ! FROM ?? ? $FGREP -f $SPAM_ACCEPT_LIST
{
# If they have the correct code, we'll add them to the
# list of accepted recipients and also accept the message
# (i.e., continue processing it outside of this recipe block).
:0c
* $ ^Subject:.*$SPAM_CODE
| echo $FROM >> $SPAM_ACCEPT_LIST
# Otherwise, we'll return their message, along with instructions
# for getting on the accepted recipients list.
:0E
{
# Fix up the header. Because of the 'h' flag, this
# only modifies the header -- the body gets passed
# on to the next recipe intact.
:0fh
| $FORMAIL -rtz \
-I "Subject: Re: $SUBJECT [rejected]"
# Fix up the body. The sed command replaces any occurence
# of '$SPAMCODE' in the response with the actual value
# of the SPAM_CODE variable.
:0fb
| $CAT $SPAM_MESSAGE - |\
$SED "s/\$SPAMCODE/$SPAM_CODE/g"
# And now send it back! Remember that '!' on the
# action line means sendmail $SENDMAILFLAGS.
:0
! -t
}
}
NOTES:
The above code has been tested, briefly. It may break heavily. Be aware
that if you set your shell to something other than /bin/sh it will
probably break.
This doesn't (obviously) implement your randomized code idea; to do so
shouldn't be terribly difficult. You'd have to modify (a) the check
for SPAM_CODE, and (b) the recipe that creates the auto reply.
2. I'm ok with if then's wit the use of :e but I don't know abut doing
complex logic. I think it probably requires more nesting. Does anybody
have any examples using complex logic?
What do you mean by complex logic? The above code was accomplished
through the use of nesting blocks, chained (:E) recipes, and
the use of program exit codes in the conditions. Throw in
or'd regular expression (this|that) and weighted scoring, and
you can accomlish some fairly complex tasks.
The SmartList distribution has some interesting examples of fairly complex
procmail code (available from the same site as procmail).
-- Lars
---
Lars Kellogg-Stedman * lars(_at_)bu(_dot_)edu * (617)353-8277
Office of Information Technology, Boston University