[英]What is the format accepted by System.Net.Mail.MailAddress' parser?
I'm working on an app that's using System.Net.Mail.MailAddress and friends for sending emails. 我正在使用一个使用System.Net.Mail.MailAddress和朋友发送电子邮件的应用程序。 Does that parser implement the full RFC5322 or a subset or what? 该解析器是实现完整的RFC5322还是子集或什么? The MSDN is not very forthcoming on this topic. 关于这个话题,MSDN并不是很乐意。
Any hints appreciated. 任何提示赞赏。
I've wrote a little snippet to test the function: 我写了一个小片段来测试函数:
foreach (int i in Enumerable.Range(32,128-32))
{
char c = (char)i;
string addr = String.Format("par.t1{0}pa.r{0}t2@example.com", c);
try
{
var mailAddr = new MailAddress(addr);
}
catch
{
Console.WriteLine("MailAddress failed '{0}' ({1}): {2}", c, i, addr);
}
}
With the following results on 3.5 SP1: 在3.5 SP1上有以下结果:
MailAddress failed ' ' (32): par.t1 pa.r t2@example.com MailAddress failed '"' (34): par.t1"pa.r"t2@example.com MailAddress failed '(' (40): par.t1(pa.r(t2@example.com MailAddress failed ')' (41): par.t1)pa.r)t2@example.com MailAddress failed ',' (44): par.t1,pa.r,t2@example.com MailAddress failed ':' (58): par.t1:pa.r:t2@example.com MailAddress failed ';' (59): par.t1;pa.r;t2@example.com MailAddress failed '<' (60): par.t1<pa.r<t2@example.com MailAddress failed '>' (62): par.t1>pa.r>t2@example.com MailAddress failed '@' (64): par.t1@pa.r@t2@example.com MailAddress failed '[' (91): par.t1[pa.r[t2@example.com MailAddress failed '\' (92): par.t1\pa.r\t2@example.com MailAddress failed ']' (93): par.t1]pa.r]t2@example.com MailAddress failed '⌂' (127): par.t1⌂pa.r⌂t2@example.com
Also it doesn't seem to support "quoted-string" local-parts, like "blah"@example.com
. 此外,它似乎不支持“quoted-string”本地部分,如“ "blah"@example.com
。
I don't think a validator could accept any less before becoming unusable. 我认为验证者在变得无法使用之前不会接受任何更少的验证。
In the discussion thread on Dominic Sayers isemail article , Jerry O'Brien said that he read Dominic's RFC compliance test cases against the System.Net.MailAddress
class: 在关于Dominic Sayers isemail文章的讨论主题中,Jerry O'Brien说他阅读了针对System.Net.MailAddress
类的Dominic的RFC兼容性测试案例:
System.Net.MailAddress
is only 59% compliant with the RFC specifications.System.Net.MailAddress
仅符合RFC规范59%。 Follow-up comments noted the specific cases where it generated false positives and false negatives. 后续评论指出了产生误报和漏报的具体情况。
The RFCs are extremely weak on what constitutes a valid email email address. RFC对于有效的电子邮件地址构成极其微弱。 They allow a range of unusual and unpopular formats. 它们允许一系列不寻常和不受欢迎的格式。 So I guess the real question is, is System.Net.MailAddress
good enough in a majority of real-world situations? 所以我想真正的问题是, System.Net.MailAddress
在大多数现实情况下是否足够好?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.