[英]Is it “a@bbb..com” a valid email address?, According to MailAddress class it is
In order to validate email address, we are relaying on MailAddress Class . 为了验证电子邮件地址,我们正在中继MailAddress Class 。 However, this email a@bbb..com address seems to be valid according to MailAddress class. 但是,根据MailAddress类,此电子邮件a @ bbb..com地址似乎有效。
MSDN states that this are valid email address: MSDN声明这是有效的电子邮件地址:
The MailAddress class supports the following mail address formats: MailAddress类支持以下邮件地址格式:
- A simple address format of user@host. user @ host的简单地址格式。 If a DisplayName is not set, this is the mail address format generated. 如果未设置DisplayName,则这是生成的邮件地址格式。
- A standard quoted display name format of "display name" . 标准的带引号的显示名称格式“显示名称”。 If a DisplayName is set, this is the format generated. 如果设置了DisplayName,则这是生成的格式。
- Angle brackets are added around the User name, Host name for "display name" user@host if these are not included. 如果不包括尖括号,则在用户名,“显示名”的主机名user @ host周围添加括号。
- Quotes are added around the DisplayName for display name , if these are not included. 如果不包括引号,则会在显示名称的DisplayName周围添加引号。
- Unicode characters are supported in the DisplayName. DisplayName支持Unicode字符。 property. 属性。
- A User name with quotes. 带引号的用户名。 For example, "user name"@host. 例如,“用户名” @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 . 取自https://msdn.microsoft.com/zh-cn/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. 请注意7项目符号接近此问题,但它表示连续的点可以出现在用户名而不是域中。
Other resources like http://isemail.info ( http://isemail.info/a@bbb..com ) states that this is not a valid email address. 其他资源,例如http://isemail.info ( http://isemail.info/a@bbb..com )指出,这不是有效的电子邮件地址。
What do you think it should be the correct behaviour?. 您认为这应该是正确的行为吗? Here is a poc. 这是poc。
//C# Example
var emailAddress = @"a@bbb..com";
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
I think (my personal interpretation of RFC822 with help of this document https://www.cs.tut.fi/~jkorpela/rfc/822addr.html ) the address 我认为(我借助本文档https://www.cs.tut.fi/~jkorpela/rfc/822addr.html对RFC822的个人解释)是该地址
a@bbb..com
is NOT valid according to RFC 822 especially its LEXICAL TOKENS definition 根据RFC 822是无效的,尤其是其LEXICAL TOKENS定义
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: 根据@dkarp:
The "."
"."
means it's a literal dot, not another ABNF production. 表示这是一个文字点,而不是另一个ABNF生成。 So a domain
is generally atom
s separated by dots, and atom
s are at least one non- specials
character in a row. 所以一个domain
一般atom
S按点分隔,和atom
s为至少一个非specials
在一行字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.