Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it "[email protected]" a valid email address?, According to MailAddress class it is

In order to validate email address, we are relaying on MailAddress Class. However, this email [email protected] address seems to be valid according to MailAddress class.

MSDN states that this are valid email address:

The MailAddress class supports the following mail address formats:

  • A simple address format of user@host. If a DisplayName is not set, this is the mail address format generated.
  • A standard quoted display name format of "display name" . If a DisplayName is set, this is the format generated.
  • Angle brackets are added around the User name, Host name for "display name" user@host if these are not included.
  • Quotes are added around the DisplayName for display name , if these are not included.
  • Unicode characters are supported in the DisplayName. property.
  • A User name with quotes. For example, "user name"@host.
  • Consecutive and trailing dots in user names. For example, user...name..@host.
  • Bracketed domain literals. For example, .
  • Comments. For example, (comment)"display name"(comment)<(comment)user(comment)@(comment)domain(comment)>(comment). Comments are removed before transmission.

Taken from https://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress%28v=vs.110%29.aspx.

Note that 7 bullet is close to this problem, but it says that the consecutive dots can appear in the username not in the domain.

Other resources like http://isemail.info (http://isemail.info/[email protected]) states that this is not a valid email address.

What do you think it should be the correct behaviour?. Here is a poc.

//C# Example
var emailAddress = @"[email protected]";

Func<string,bool> validEmail = (email)=>
{
    try
    {
      var address = new System.Net.Mail.MailAddress(email);
      return true;      
    }catch (Exception ex)
    {
        return false;
    }
};

Assert.IsTrue(validEmail(emailAddress));
//using NUnit.Framework
//O2Ref:nunit.framework.dll
like image 318
Michael Hidalgo Avatar asked Apr 07 '15 23:04

Michael Hidalgo


1 Answers

I think (my personal interpretation of RFC822 with help of this document https://www.cs.tut.fi/~jkorpela/rfc/822addr.html) the address

[email protected]

is NOT valid according to RFC 822 especially its LEXICAL TOKENS definition

where you have the domain part of the address defined as

domain      =  sub-domain *("." sub-domain)

sub-domain  =  domain-ref / domain-literal

domain-ref  =  atom

atom        =  1*<any CHAR except specials, SPACE and CTLs>

specials    =  "(" / ")" / "<" / ">" / "@"   ;  Must be in quoted-
             /  "," / ";" / ":" / "\" / <">  ;  string, to use
             /  "." / "[" / "]"              ;  within a word.    

domain-literal =  "[" *(dtext / quoted-pair) "]"

dtext       =  <any CHAR excluding "[",     ; => may be folded
                 "]", "\" & CR, & including
                 linear-white-space>

linear-white-space =  1*([CRLF] LWSP-char)   ; semantics = SPACE
                                             ; CRLF => folding

quoted-pair =  "\" CHAR                      ; may quote any char

CHAR        =  <any ASCII character>         ; (  0-177,  0.-127.)

so the dot character is a special and needs to be in quotes else it is a separator as defined in the 'domain' part.

According to @dkarp:

The "." means it's a literal dot, not another ABNF production. So a domain is generally atoms separated by dots, and atoms are at least one non-specials character in a row.

like image 145
michalh Avatar answered Nov 15 '22 06:11

michalh