C# 为什么System.Net.Mail.MailAddress构造函数使用斜杠“解析电子邮件”/&引用;在域部分?
我们有以下代码:C# 为什么System.Net.Mail.MailAddress构造函数使用斜杠“解析电子邮件”/&引用;在域部分?,c#,.net,email-validation,C#,.net,Email Validation,我们有以下代码: using System; using System.Net.Mail; public class Program { public static void Main() { var mailAddress = new MailAddress("username@domain/domain.com"); // Doesn't throw FormatException Console.WriteLine(mailAddre
using System;
using System.Net.Mail;
public class Program
{
public static void Main()
{
var mailAddress = new MailAddress("username@domain/domain.com"); // Doesn't throw FormatException
Console.WriteLine(mailAddress.Host); // Prints "domain/domain.com"
}
}
我们希望MailAddress构造函数引发FormatException,因为域名中不支持“/”。
MailAddress解析它们有什么原因吗?.NET使用RFC 2822标准来验证电子邮件地址 根据文档所述,正斜杠(/)是域部分的有效字符 请参见地址规范,网址为: 域可以是点原子,如下所述:
.NET使用RFC 2822标准来验证电子邮件地址 根据文档所述,正斜杠(/)是域部分的有效字符 请参见地址规范,网址为: 域可以是点原子,如下所述:
MailAddress c'tor没有承诺进行完整的验证,但事实并非如此(请参阅)。@KlausGütter为什么对MailAddressParser类有以下评论?“此类负责解析RFC 2822中所述的电子邮件地址。”它表示“解析”,而不是“验证”。MailAddress c'tor不承诺进行完整验证,但事实并非如此(请参阅)。@KlausGütter为什么对MailAddressParser类有以下评论?“此类负责解析RFC 2822中描述的电子邮件地址。”它表示“解析”,而不是“验证”。
addr-spec = local-part "@" domain
local-part = dot-atom / quoted-string / obs-local-part
domain = dot-atom / domain-literal / obs-domain
domain-literal = [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS]
dcontent = dtext / quoted-pair
dtext = NO-WS-CTL / ; Non white space controls
%d33-90 / ; The rest of the US-ASCII
%d94-126 ; characters not including "[",
; "]", or "\"
atext = ALPHA / DIGIT / ; Any character except controls,
"!" / "#" / ; SP, and specials.
"$" / "%" / ; Used for atoms
"&" / "'" /
"*" / "+" /
"-" / "/" /
"=" / "?" /
"^" / "_" /
"`" / "{" /
"|" / "}" /
"~"
atom = [CFWS] 1*atext [CFWS]
dot-atom = [CFWS] dot-atom-text [CFWS]
dot-atom-text = 1*atext *("." 1*atext)