emailhosts

Is it possible to include comments inside a non email host name?


I am working on a more complete email validator in java and came across an interesting ability to embed comments within an email both in the "username" and "address" portions.

The following snippet from http://www.dominicsayers.com/isemail/ has this to say about comments within an email.

Comments are text surrounded by parentheses (like these). These are OK but don't form part of the address. In other words mail sent to first.last@example.com will go to the same place as first(a).last(b)@example(c).com(d). Strange but true.

I tried entering an url such as "google(ignore).com" but firefox and some other browsers failed and i was wondering is this because its it wrong or is it because they dont know about host name comments ?


Solution

  • That syntax -- comments within an addr-spec -- was indeed permissible by the original email RFC, RFC 822. However, the placement of comments like you'd like to use them was deprecated when that RFC was revised by RFC 2822... 10 years ago. It's still marked as obsolete in the current version, RFC 5322. There's no good excuse for emitting anything using that syntax.

    Address parsers are supposed to be backwards-compatible in order to cover all conceivable cases, including 10-years-deprecated bits like the one you're trying to take advantage of here. But I'll bet that many, many receiving mail agents will fail to properly parse out those comments. So even though you may have technically found a loophole via the "obsolete addressing" section of the RFC, it's not likely to do you much good in practice.

    As for HTTP, the syntax rules aren't the same as email syntax rules. As you're seeing, the comment section from RFC 822 isn't applicable.