I am writing a default mail client to handle when someone clicks mailto:firstname.lastname@example.org<br />
craigslist mailto links have the form mailto:bob%40example.com<br /> I get an exception when this is used.<br /> here is some simple code to repeat the problem in c#<br />
System.Uri u1 = new Uri(@"mailto:email@example.com"); // 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
question 1:<br /> shoudn't mailto:bob%40example.com be a valid uri question 2:<br /> if it is an invalid uri then how is outlook not crashing on it.<br />
I am using visual studio 2012<br />Answer1:
RFC 6068 (<a href="http://www.ietf.org/rfc/rfc6068.txt" rel="nofollow">http://www.ietf.org/rfc/rfc6068.txt</a>), which defines the mailto protocol, does <strong>not</strong> specify that %40 is a valid syntax to replace @ as a username/domain separator.
It does specify that if a <em>username</em> contains a @, such as in the case
hello@firstname.lastname@example.org, you can use %40 to escape it to
email@example.com. But nowhere does it state that
hello%40domain.com would be a valid mailto 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...