System.Net.Mail.MailAddress的解析器接受的格式是什么? [英] What is the format accepted by System.Net.Mail.MailAddress' parser?

查看:298
本文介绍了System.Net.Mail.MailAddress的解析器接受的格式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用的应用程序System.Net.Mail.MailAddress 和发送电子邮件的朋友。该解析器是否实现完整的 RFC5322 或子集或什么?

解决方案

我已经写了一个小代码来测试这个函数:

  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);
}
}

在3.5 SP1上显示以下结果:

 
MailAddress失败(32):par.t1 pa.r t2@example.com
MailAddress失败''(34) :par.t1pa.rt2@example.com
MailAddress failed'('(40))par.t1(pa.r(t2@example.com
MailAddress failed')'( 41):par.t1)pa.r)t2@example.com
MailAddress失败','(44):par.t1,pa.r,t2 @ example.com
MailAddress failed': '(58):par.t1:pa.r:t2@example.com
MailAddress失败';'(59):par.t1; pa.r; t2@example.com
MailAddress失败'<'(60):par.t1< pa.r< t2@example.com
MailAddress失败'>'(62):par.t1> pa.r> t2@example.com
MailAddress失败'@'(64):par.t1 @ pa.r @ t2 @ example.com
MailAddress失败'['(91):par.t1 [pa.r [t2@example.com
MailAddress失败'\'(92):par.t1\pa.r\t2@example.com
MailAddress失败']'(93):par.t1] pa.r] t2@example.com
MailAddres失败了'⌂'(127):par.t1⌂pa.r⌂t2@example.com

支持quoted-string本地零件,如blah@ example.com



不要认为验证器在不可用之前可以接受更少。


I'm working on an app that's using System.Net.Mail.MailAddress and friends for sending emails. Does that parser implement the full RFC5322 or a subset or what? The MSDN is not very forthcoming on this topic.

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:

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.

I don't think a validator could accept any less before becoming unusable.

这篇关于System.Net.Mail.MailAddress的解析器接受的格式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆