Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Validating an email address

Reply
Thread Tools

Validating an email address

 
 
Tom Anderson
Guest
Posts: n/a
 
      12-09-2005
Hi all,

A hoary old chestnut this - any advice on how to syntactically validate an
email address? I'd like to support both the display-name-and-angle-bracket
and bare-address forms, and to allow everything that RFC 2822 allows (and
nothing more!).

Currently, i've got some regexps which recognise a common subset of
possible addresses, but it would be nice to do this properly - i don't
currently support quoted pairs, quoted strings, or whitespace in various
places where it's allowed. Adding support for those things using regexps
is really hard. See:

http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html

For a level to which i am not prepared to stoop.

I hear the email-sig are open to adding a validation function to the email
package, if a satisfactory one can be written; i would definitely support
their doing that.

tom

--
Women are monsters, men are clueless, everyone fights and no-one ever
wins. -- cleanskies
 
Reply With Quote
 
 
 
 
Ben Finney
Guest
Posts: n/a
 
      12-09-2005
Tom Anderson <(E-Mail Removed)> wrote:
> A hoary old chestnut this - any advice on how to syntactically
> validate an email address?


Yes: Don't.

<URL:http://www.apps.ietf.org/rfc/rfc3696.html#sec-3>

The only validation you should be doing before sending the message is
on the domain part. Since there are records available in DNS to
verify, you can check those. Is there an MX record? Is the address
valid? Do the mappings both way for that record make sense?

Please, don't attempt to "validate" the local-part. It's not up to you
to decide what the receiving MTA will accept as a local-part, and
(short of asking the MTA which most of them disable due to abuse by
spammers) you can't find out without just delivering the message.

So, once you've determined that you can reach the MX host, and that it
actually *is* the MX host for the domain, just deliver the message.

--
\ "Those who can make you believe absurdities can make you commit |
`\ atrocities." -- Voltaire |
_o__) |
Ben Finney
 
Reply With Quote
 
 
 
 
Tom Anderson
Guest
Posts: n/a
 
      12-10-2005
On Sat, 10 Dec 2005, Ben Finney wrote:

> Tom Anderson <(E-Mail Removed)> wrote:
>
>> A hoary old chestnut this - any advice on how to syntactically
>> validate an email address?

>
> Yes: Don't.
>
> <URL:http://www.apps.ietf.org/rfc/rfc3696.html#sec-3>


The IETF must have updated that RFC between you posting the link and me
reading it, because that's not what it says. What it says that the syntax
for local parts is complicated, and many of the variations are actually
used for reasons i can't even imagine, so they should be permitted. It
doesn't say anything about not validating the local part against that
syntax.

> Please, don't attempt to "validate" the local-part. It's not up to you
> to decide what the receiving MTA will accept as a local-part,


Absolutely not - it's up to the IETF, and their decision is recorded in
RFC 2822.

tom

--
Whose house? Run's house!
 
Reply With Quote
 
Mike Meyer
Guest
Posts: n/a
 
      12-10-2005
Tom Anderson <(E-Mail Removed)> writes:
> On Sat, 10 Dec 2005, Ben Finney wrote:
>> Please, don't attempt to "validate" the local-part. It's not up to
>> you to decide what the receiving MTA will accept as a local-part,

> Absolutely not - it's up to the IETF, and their decision is recorded
> in RFC 2822.


Wrong. The IETF dictates what your MTA *must* accept, not what it will
accept. It's perfectly legal to accept more than what the IETF says is
legal. In fact the rule of thumb for interoperability (on the off
chance that anyone still cares about such) is "be generous in what you
accept, and strict in what you send", so you're even encouraged to
accept more than what the IETF says you have to.

If you didn't generate the address, you have no way of knowing if the
the receiving MTA will accept it or not without actually trying
it. Rejecting an address because you don't like it could break
perfectly functional email addresses.

<mike
--
Mike Meyer <(E-Mail Removed)> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validating Multiple E-mail Address - JavaScript & CustomValidator cemcat ASP .Net 1 12-19-2005 04:44 PM
Re: Validating an email address Jean-Paul Calderone Python 0 12-09-2005 02:38 PM
Validating User Input (numeric only, and valid email address attributes) charleswesley@gmail.com ASP .Net 2 10-01-2005 07:49 PM
Validating/Changing MSN Messenger email address Justin Weidmak Computer Support 2 07-04-2004 03:01 PM
code for validating IPv4 address qazmlp C Programming 14 07-29-2003 08:05 PM



Advertisments