procmail
[Top] [All Lists]

Re: Extracting Sender's Email Address Only

2002-01-30 15:34:36
At 16:27 2002-01-30 -0500, Derek Battams wrote:
I'm sure this has been asked many times previously, but I don't see
anything in the FAQ addressing this.  I'd like to extract the sender's
email address only and compare it to a blacklist.  I can extract the
From: header using formail, of course, but I want to eliminate everything
but the email address.

From: isn't necessarily the _sender_. It should be the author of the message, but that doesn't make it the sender.

From_ is more conventionally recognized as the sender (as far as headers go).

You might have an easier time taking the blacklist and comparing it against the From_ ...

:0
* $? formail -x"From " | fgrep -i -w -f $BLACKLISTFILE
{
        LOG="we matched someting
"
}

Where blacklistfile contains either email addresses or domains. Since -w is used, you should be able to list either domains or complete addresses in the file, and be sucessful with matches. You probably won't have too many entries that look like dates, so that part of the line won't be significant.

If you need to extract the address and submit it to a program, then you'll need to pipe the appropriate header line into a regexp, say though sed or perl. You'll have an easier time of it with the From_ header, since as extracted, what you're asking for it the first field - all the way up to the first space - no comments or anything else will be hanging around it:

:0
FROMADDR=|formail -x"From "|sed -e "s/\([^ ]*\) .*/\1/"

This doesn't hold true for the From: header though, as I'm sure you're aware, but before I took the time to send this, I see that Mr. Tamkin has posted a reply which gives you the formail invocation to strip a From: header of comments.


---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>