#25986: Django crashes on unicode characters in the local part of an e-mail address -------------------------------------+------------------------------------- Reporter: Sergei Maertens | Owner: Sergei | Maertens Type: Bug | Status: closed Component: Core (Mail) | Version: 1.9 Severity: Normal | Resolution: fixed Keywords: | Triage Stage: Accepted Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Comment (by Mike Edmunds):
Does anyone know of an email server or service where this sort of non- ASCII mailbox works? Sorry to unearth this ancient ticket. I'm hoping one of the original participants or cc's might have more info. This ticket attempted to add support for non-ASCII characters in the local part (username) of an email address: e.g., `j.lóp...@example.com` . But the implementation used an RFC 2047 encoded-word (`=?utf-8?b?ai5sw7NwZXo=?=@example.com`). RFC 2047 specifically prohibits that in an addr-spec (email address). And I've been unable to find any email systems that actually support this behavior. At best, the message bounces—and sometimes it just disappears without a trace. If anyone has an example where RFC 2047 encoded-word email addresses work, I'll put some effort into preserving the current behavior as part of updating to Python's modern email API (#35581). Or if nobody is actually using this successfully, I'm going to treat it as a bug. More info: * [https://datatracker.ietf.org/doc/html/rfc2047#section-5:~:text=An%20%27encoded%2Dword%27%20MUST%20NOT%20appear%20in%20any%20portion%20of%20an%20%27addr%2Dspec%27. RFC 2047 section 5(3)] specifies that: "An 'encoded-word' MUST NOT appear in any portion of an 'addr-spec'." (And I can't find any later RFC that removes this restriction.) * I can't find any email software or services that support RFC 2047 in an email localpart. The closest is Exim, which can [https://www.exim.org /exim-html-current/doc/html/spec_html/ch-internationalisation.html convert a localpart to/from an A-Label] (an [https://datatracker.ietf.org/doc/html/rfc5891 RFC 5891] IDNA encoding, a.k.a. "punycode": `j.xn--lpez-...@example.com`). But that's a different encoding, and this behavior seems to be unique to Exim. * From what I can tell, the only spec compliant way to use a non-ASCII localpart involves keeping utf-8 un-encoded in the headers, and then sending with the SMTPUTF8 extension ([https://datatracker.ietf.org/doc/html/rfc6530.html RFC 6530] / [https://datatracker.ietf.org/doc/html/rfc6531.html RFC 6531] / [https://datatracker.ietf.org/doc/html/rfc6532.html RFC 6532]). There doesn't seem to be any spec that allows a non-ASCII localpart with 7-bit header encoding. * The Python behavior seems to be a bug. Note that the same Python code also converts a non-ASCII domain name to an RFC 2047 encoded-word, which is definitely not deliverable: `juan@lópez.example.mx` → `juan@=?utf-8?q?l=C3=B3pez?=.example.mx`. This is an [https://github.com/python/cpython/issues/83938#issuecomment-1093859100 acknowledged bug] in Python's email package. (Incidentally, RFC 2047 encoded words ''are'' allowed in a ''display- name'': `J. López <jlo...@example.com>` → `J. =?utf-8?q?L=C3=B3pez?= <jlo...@example.com>`. That worked before and after this ticket, and won't be changed by #35581.) -- Ticket URL: <https://code.djangoproject.com/ticket/25986#comment:12> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/01070190c74b2df3-7b5f2a44-cb23-4c99-9a02-e0ae49626bbc-000000%40eu-central-1.amazonses.com.