[英]Why System.Net.Mail.MailAddress constructor parses email with slash "/" in domain part?
We have following code:我们有以下代码:
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"
}
}
We expect MailAddress constructor to throw FormatException because "/" is not supported in domain name.我们希望 MailAddress 构造函数抛出 FormatException,因为域名不支持“/”。 Is there reason why MailAddress parses them? MailAddress 是否有理由解析它们?
.NET uses RFC 2822 standart for its validation process of e-mail addresses. .NET 使用RFC 2822标准进行电子邮件地址验证过程。
According to document forward slash ( / ) is a valid character for domain part.根据文档,正斜杠( / ) 是域部分的有效字符。
Please see address specification at RFC 2822 3.4.1 :请参阅RFC 2822 3.4.1 中的地址规范:
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 "\"
Domain can be dot-atom which is described at RFC 2822 3.2.4 :域可以是RFC 2822 3.2.4 中描述的点原子:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.