procmail
[Top] [All Lists]

Re: RFC822 compliant email address

2002-07-03 15:28:58
At 21:02 2002-07-03 +0200, Werner Reisberger wrote:
I am looking for a regexp usable in a procmail recipe which checks if
an email address is valid according to rfc822. One exception of rfc822
could be that the local-part is not composed of characters within double
quotes. I also don't want to allow a domain part consisting of an IP address.

The ORA _Mastering_Regular_Expressions_ book by Jeffren Friedl has a detailed (and massive) regexp, but I rather doubt it'd work within procmail - you might need to run it through perl or somesuch.

        <http://www.oreilly.com/catalog/regex/>

They released the second edition just this month:

        <http://www.oreilly.com/catalog/regex2/>

 * subscraddr ?? ^[^ ;@<>,:()"\]*[^ 
;.@<>,:()"\]+(_at_)[-a-z0-9]+\(_dot_)[-a-z0-9]+

This is less than 1/80th of the size (and doesn't even TOUCH the complexity) of the RFC822 address parser in the regexp book. It is discussed in Ch7 of the book, and the code is laid out (with comments) in Appendix B, which ends with an uncommented pure regexp block. The author makes the perl code (but for some reason, not the raw regexp) available online:

        <http://public.yahoo.com/~jfriedl/regex/code.html>

(the script there doesn't have the standard unix header comment line to make it a proper self-executing script, so if you d/l it, either add that line, or be sure to actually invoke it using perl: 'perl scriptname').


# extract the From: line - I do this along with other headers as
# a matter of course in my .procmailrc
:0
* ^From:[       ]*\/[^  ].*
{
        FROM=$MATCH
}

# Check for address validity
:0
* !? email-opt.pl "$FROM"
{
        LOG="Gaak!  Address isn't valid!$NL"

        # do something
}


Have fun.

---
 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>