procmail
[Top] [All Lists]

Re: extractions

1999-09-11 14:17:27
S.Toms wrote:
  I'm playing around with the following trying to create a bounce list of
emails of authors which my rules denote as spam so that in the event that

Well, good luck with that... the "author" as you call it (From:
I presume from your recipe) is almost invariably spoofed.
Once in a while it's a randomly selected name from the unlucky
recipients, and it might turn out to be someone you "know"
because your addresses were extracted from a common source.

Spam identification is tricky.

Anyway,

I get another from them I can have it deleted without going through the
rest of my filters.

:0
* ^Subject:.test-header-extraction
{
   FROMLINE=`formail -xFrom:`

   :0f
   | formail -bfA "X-Header-From: ${FROMLINE}" | \
             echo ${FROMLINE} >> ${PMDIR}/rc.bounceList
}

  This does extract the email address and places it into the file,
unfortunately it blows out the message itself and kills my Inbox. I have a
feeling it has something to do with the | before the echo but I'm unsure
of how exactly it should be.

I think it's the "f" flag causing you trouble here... the (empty)
standard output of your formail|echo pipe comes back to replace
the header & body, which is probably not what you want.

Assuming that you are trying to alter the header for now by adding
your X-Header-From headerfield, and also put the address into that
rc.bounclist file, then otherwise continue as normal,
try something like this (untested, and probably not very efficient):

  :0
  * ^Subject:.test-header-extraction
  {
     FROMLINE=`formail -xFrom:`
  
     # add the X-Header-From here... filter header only...
     :0fh
     | formail -bfA "X-Header-From: ${FROMLINE}"

     # save the From: address here (does not filter or read its input
     # hence 'i' to ignore errors)
     :0hci
     | echo ${FROMLINE} >> ${PMDIR}/rc.bounceList
  }


  The other thing I want to do is remove all the other crap in the line,
for example, mine shows up as    S.Toms <tomas(_at_)primenet(_dot_)com>   and 
the
whole line goes into the file, how can I make just the 
tomas(_at_)primenet(_dot_)com
goto the file?

You can play various games, but totally arbitrary (but legal) comments
are impossible to extract with procmail alone (due to lack of looping
construct).  Good approximations can be made, but a lazy way that
works arbitrarily (at the expense of an extra process) is to
pipe an address as a From: line into "formail -r"
and then get rid of the "To: " it produces.

So, instead of:
:0
* ^Subject:.test-header-extraction
{
   FROMLINE=`formail -xFrom:`
 ....

try the following (the extra condition ensures that there *is*
a From: headerfield, and pull it out with \/ into the MATCH variable):

:0
* ^Subject:.test-header-extraction
* ^\/From: *[^ ].*
{
   FROMADDR=`echo "$MATCH" | formail -r`
   :0
   * FROMADDR ?? ^To:.\/.*
   { FROMADDR="$MATCH" }

   # add the X-Header-From here... filter header only...
   :0fh
   | formail -bfA "X-Header-From: ${FROMLINE}"

   # save that minimal From: email address here (does not filter
   # or read its input hence 'i' to ignore errors)
   :0hci
   | echo ${FROMADDR} >> ${PMDIR}/rc.bounceList

}

Hope that's of some help, anyway.

Cheers,
Stan

<Prev in Thread] Current Thread [Next in Thread>
  • extractions, S.Toms
    • Re: extractions, Stan Ryckman <=