本文介绍了在mailto:协议中使用%40代替@时出现UriFormatException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个默认的邮件客户端,以便在有人单击mailto:[email protected]

I am writing a default mail client to handle when someone clicks mailto:[email protected]

craigslist mailto链接的格式为mailto:bob%40example.com
使用此方法时会出现异常.
这是一些简单的代码,可以在c#

craigslist mailto links have the form mailto:bob%40example.com
I get an exception when this is used.
here is some simple code to repeat the problem in c#

System.Uri u1 = new Uri(@"mailto:[email protected]");  // ok so far
System.Uri u2 = new Uri(@"http://somewhere.foo/profile/username%40somewhere.foo"); // still ok
System.Uri u3 = new Uri(@"mailto:bob%40ms.com");  // crash here

问题1:
请勿mailto:bob%40example.com是有效的uri

问题2:
如果它是无效的uri,那么Outlook不会崩溃的原因.

question 1:
shoudn't mailto:bob%40example.com be a valid uri

question 2:
if it is an invalid uri then how is outlook not crashing on it.

我正在使用Visual Studio 2012

I am using visual studio 2012

推荐答案

RFC 6068( http://www.ietf.org/rfc/rfc6068.txt )(定义了mailto协议)没有指定%40是将@替换为用户名/域分隔符的有效语法

RFC 6068 (http://www.ietf.org/rfc/rfc6068.txt), which defines the mailto protocol, does not specify that %40 is a valid syntax to replace @ as a username/domain separator.

它确实指定如果用户名包含@,例如在hello@[email protected]情况下,则可以使用%40将其转义为hello%[email protected].但是没有地方指出hello%40domain.com是有效的mailto URI.

It does specify that if a username contains a @, such as in the case hello@[email protected], you can use %40 to escape it to hello%[email protected]. But nowhere does it state that hello%40domain.com would be a valid mailto URI.

如果Microsoft决定在Outlook中支持它,那仍然不会改变事实,即权威的RFC没有定义它-所以我想说,微软可能出于以下原因将其放入其中健壮性,或者这是它们为%xx语法解析任何URI的副作用...

And if Microsoft decided to support it in Outlook, that still doesn't change the fact that the RFC, which is authoritative, doesn't define it -- so I'd say, Microsoft probably put it in for reasons of robustness, or maybe it's a side-effect of them parsing any URI for %xx syntax...

这篇关于在mailto:协议中使用%40代替@时出现UriFormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 22:54