PDA

View Full Version : RFC 822 compliance



Citizen Bleys
01-14-2005, 03:51 PM
I've just finished searching the IETF's RFC 822 (email message format standard) and cannot find a definitive list of what characters are and are not valid for email addresses.

I know that alphanumerics, underscores, and hyphens are valid in email addresses. I've tried searching for programming routines to determine valid email addresses, but I was unable to find one that contained the ampersand (&) character.

I thought that ampersands in email addresses were not RFC 822 compliant, and verified this by attempting to sign up for a number of free email services with entirely valid email addresses except for the addition of an ampersand. None works.

I need to find a reliable document that spells out in black and white what characters are and are not RFC 822 compliant in the prefix (i.e., before the @) portion of an internet email address.

Dr Unne
01-14-2005, 06:56 PM
http://www.ietf.org/rfc/rfc0822.txt?number=822 is the RFC822 document itself. It gives valid email addresses as a Backus-Naur grammar. Can't get much more specific than that. ADDRESS SPECIFICATION is on page 27.

To attempt to put it into some semblance of English: The part before the @ is <em>word</em>, which is (eventually) one or more of any character (ASCII 0-177) "except specials, SPACE and CTLs"; CTLS are ASCII 0- 37, 177, and 127; SPACE is ASCII 40 and 32; "specials" are ()&lt;>@,;:"\.[] Apparently also valid is a "quoted-string", which means a string (made of ASCII 0-177) in double-quotes that doesn't include a ", a \, or a carriage-return, although you can use \ as an escape-character to escape a CHAR (ASCII 0-177). Now that's the part BEFORE the @. You can enjoy reading about the part after the @ yourself.

So far as code to check for valid addresses, see for example http://search.cpan.org/~pdwarren/Mail-RFC822-Address-0.3/Address.pm which is a Perl module. http://www.perldoc.com/perl5.8.0/pod/perlfaq9.html has one part "How do I check a valid mail address?" which says that the only real way to check for a valid address is just to try it and see if it bounces.

Citizen Bleys
01-14-2005, 07:17 PM
Yeah, I read (aka: skimmed) the 822 specification, couldn't find any mention of the ampersand. Note that the ampersand isn't in those "specials"

Bugger.

Dr Unne
01-14-2005, 08:01 PM
If it isn't in the list of forbidden characters, then it's valid. The Perl module agrees. Just because Hotmail or something says it isn't valid doesn't mean it really isn't valid according to the specification.

<pre style="font-size: 7pt;">chester [~] $ perl -e 'use Mail::RFC822::Address qw(valid);valid(q|test@test.com|) ? print "Yes.\n" : print "No.\n"'
Yes.
chester [~] $ perl -e 'use Mail::RFC822::Address qw(valid);valid(q|test&test@test.com|) ? print "Yes.\n" : print "No.\n"'
Yes.
chester [~] $ perl -e 'use Mail::RFC822::Address qw(valid);valid(q|&test@test.com|) ? print "Yes.\n" : print "No.\n"'
Yes.
chester [~] $ perl -e 'use Mail::RFC822::Address qw(valid);valid(q|test&@test.com|) ? print "Yes.\n" : print "No.\n"'
Yes.
chester [~] $ perl -e 'use Mail::RFC822::Address qw(valid);valid(q|&@test.com|) ? print "Yes.\n" : print "No.\n"'
Yes.
chester [~] $ perl -e 'use Mail::RFC822::Address qw(valid);valid(q|&&&&&@test.com|) ? print "Yes.\n" : print "No.\n"'
Yes.
chester [~] $ perl -e 'use Mail::RFC822::Address qw(valid);valid(q|&&[&&&@test.com|) ? print "Yes.\n" : print "No.\n"'
No.
chester [~] $ perl -e 'use Mail::RFC822::Address qw(valid);valid(q|test\&@test.com|) ? print "Yes.\n" : print "No.\n"'
No.
chester [~] $ perl -e 'use Mail::RFC822::Address qw(valid);valid(q|"test"@test.com|) ? print "Yes.\n" : print "No.\n"'
Yes.
chester [~] $ perl -e 'use Mail::RFC822::Address qw(valid);valid(q|"test&"@test.com|) ? print "Yes.\n" : print "No.\n"'
Yes.
chester [~] $ perl -e 'use Mail::RFC822::Address qw(valid);valid(q|"test\&"@test.com|) ? print "Yes.\n" : print "No.\n"'
Yes.</pre>