jstedfast / MimeKit

A .NET MIME creation and parser library with support for S/MIME, PGP, DKIM, TNEF and Unix mbox spools.
http://www.mimekit.net
MIT License
1.84k stars 373 forks source link

WIP: `FormatOptions`: Feature `ConvertPunycodeToIdn` #1060

Closed NicolaiSoeborg closed 1 month ago

NicolaiSoeborg commented 3 months ago

Is your feature request related to a problem? Please describe. A lot of places requires working with punycoded mails as the IDN form is not handled correctly. But when parsing, mails are turned into IDN form, i.e. MimeKit.MailboxAddress.Parse("X@xn--sb-lka.org").Address == "X@søb.org"

Describe the solution you'd like It would be nice with an option to keep the address in punycoded form.

Describe alternatives you've considered I guess users of this library can also do something like:

if (mailbox.IsInternational)
    mail = mailbox.LocalPart + "@" + MailboxAddress.IdnMapping.Encode(mailbox.Domain)

Additional context This is a suggestion for adding that. Comments are welcome!

jstedfast commented 3 months ago

FormatOptions.International is more-or-less meant for this already.

I guess users of this library can also do something like:

if (mailbox.IsInternational)
    mail = mailbox.LocalPart + "@" + MailboxAddress.IdnMapping.Encode(mailbox.Domain)

Alternatively, you can do this instead:

var email = MailboxAddress.EncodeAddrspec (mailbox.Address);

That said, perhaps the parser shouldn't decode International Domain Names and/or perhaps a InternationalAddress property could be added and Address could enforce a punycode encoded address?

The only issue with that is it would break existing expectations, so perhaps a better approach would be to add LegacyAddress or SafeAddress or something (not sure I like either property name, but you get the idea).

Before I jump out of the starting gate, though, what scenarios do you need supported, exactly?

Sounds like you want option 3, but what about the others?

Alternatively, is MailboxAddress.EncodeAddrspec (mailbox.Address) enough now that you know about that option?

jstedfast commented 3 months ago

BTW, if you only ever want punycode-encoded domains, another option is to swap out the MailboxAddress.IdnMapping implementation to one that doesn't encode/decode (or one that always converts into the encoded version).

You just need to implement the IPunycode interface: https://mimekit.net/docs/html/T_MimeKit_Encodings_IPunycode.htm

jstedfast commented 1 month ago

I'm going to close this because I haven't heard any response, but if there is still interest in this we can reopen and have more discussion on how best to meet your needs.