I am trying to figure out how I could do the following when I received
email:
1) get the name of the sender
2) check how many times the sender sent me email before, by checking in a
in a file. The format is
address1
address2
address3
address2
address1
[etc]
3) if the number of times the name is in the file is lower that a MAXIMUM,
process
the mail, if not bounce the mail back.
Danielle,
There are two ways to count things in procmail recpies: using "test" or
using weighted scoring techniques. The first is easy, but involves
extra processes, the latter is more efficient but I can never remember
the technique (and thus never use it, and thus don't know it :^}).
David Tamkin will be able to remind us.
Here is a recipe fragment to accomplish the description above.
SENDER=`formail -rtzxTo:`
COUNT=`fgrep -c "$FROM" $LIST`
MAXIMUM=30 # set to the maximum number of occurances to
process
PROCESS=process-command # or whatever you want to do with the mail
# Only process the mail if it hasn't exceeded the maximum
:0
* ? test $COUNT -le $MAXIMUM
| $PROCESS
:0E
* ^Subject: *\/[^ ].*
* $!^X-Loop: *$LOGNAME(_at_)$HOST
{
:0fh # generate a reply header
| formail -rt -I"From: $LOGNAME's Mail Agent <$LOGNAME>" \
-I"Subject: Re: $MATCH" \
-I"Precedence: junk" \
-I"X-Loop: $LOGNAME(_at_)$HOST"
:0afb # generate a reply body
| echo "I'm sorry, but your request was not processed because" ; \
echo "the maximum number of requests per address has been" ; \
echo "exceeded. The original message follows." ; \
echo "----------------------------------------------------" ; \
cat -
:0a # send it
! -t
# if any of the recipes above fail, log the entire message in
# the error log
:0e
errorlog
}
> What I have so far is
>
> to get the sender address
>
> FROM="'$FORMAIL -rx To:'"
Use "-rt", instead of just "-r". See the procmail archives as to why.
> which get FROM=address, and this work
> then to check I would assume that
>
> COUNT="egrep -c "$FROM" $LIST"
This fails because the addresses are not regular expressions. If you
are just searching for strings (and addresses are simply strings), use
"fgrep".
> would set COUNT to the number of times that FROM was found in the
> file LIST, ex COUNT=3. This does not work.
> I think the next step would be to compare COUNT to MAXIMUM, but
> then I would need ideas how to do this.
As I said above, either use "test" or a weighted scoring techinque. See
"procmailsc" for description of the latter.
> If there are suggestions,, I would reaaly appreciated, and I thank
> in advance replys.
>
> Danielle
Good luck.
___________________________________________________________
Alan Stebbens <aks(_at_)sgi(_dot_)com> http://reality.sgi.com/aks