gpt4 book ai didi

c# - "a@bbb..com"是有效的电子邮件地址吗?根据 MailAddress 类,它是

转载 作者:太空狗 更新时间:2023-10-29 19:45:16 29 4
gpt4 key购买 nike

为了验证电子邮件地址,我们正在转发 MailAddress Class .但是,根据 MailAddress 类,此电子邮件 a@bbb..com 地址似乎是有效的。

MSDN 指出这是有效的电子邮件地址:

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.

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

请注意,7 号项目符号与此问题很接近,但它表示连续的点可以出现在用户名中,而不是域中。

其他资源,如 http://isemail.info ( http://isemail.info/a@bbb..com ) 声明这不是有效的电子邮件地址。

您认为正确的行为应该是什么?。这是一个 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

最佳答案

我认为(我个人借助本文档对 RFC822 的解释 https://www.cs.tut.fi/~jkorpela/rfc/822addr.html)地址

a@bbb..com

根据 RFC 822 无效特别是它的LEXICAL TOKENS定义

您将地址的域部分定义为

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

所以点字符是一个特殊字符,需要用引号引起来,否则它是“域”部分中定义的分隔符。

根据@dkarp:

"." 表示它是一个字面上的点,而不是另一个 ABNF 产品。所以一个domain一般是用点分隔的atomatom至少是一个非specials字符连续。

关于c# - "a@bbb..com"是有效的电子邮件地址吗?根据 MailAddress 类,它是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29503486/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com