#35378: Bad UTF-8 "To" header encoding in EmailMessage
---------------------------------------+------------------------
               Reporter:  andres       |          Owner:  nobody
                   Type:  Bug          |         Status:  new
              Component:  Core (Mail)  |        Version:  5.0
               Severity:  Normal       |       Keywords:
           Triage Stage:  Unreviewed   |      Has patch:  0
    Needs documentation:  0            |    Needs tests:  0
Patch needs improvement:  0            |  Easy pickings:  0
                  UI/UX:  0            |
---------------------------------------+------------------------
 Hi!

 I'm getting errors when trying to send email messages when the "to" header
 has non-ASCII chars.
 The problem seems to happen when all these conditions are true at the same
 time:

 - the readable name part of the recipient is big (e.g. "A very long and
 big name for this recipient" <[email protected]>)
 - there is at least one non-ASCII char
 - there is at least one "special char" (only seems to happen with comma or
 parenthesis)
 - the special char isn't close to or between no-ASCII chars

 Code example:
 {{{
 import email
 from django.core.mail import EmailMessage

 recipient = '"A véry long name with non-ASCII char and, comma"
 <[email protected]>'

 msg = EmailMessage(from_email='[email protected]',
 to=[recipient]).message()
 msg.policy = email.policy.default.clone(cte_type='7bit')
 print(msg.as_bytes())
 }}}

 That prints a bytes string with:

 `\nTo: A =?utf-8?q?v=C3=A9ry?= long name with non-ASCII char and, comma\n
 <[email protected]>\n`

 It has an unprotected comma, and the message is rejected by ESPs.
 Using default policy fix this problem, but possibly causes other bad
 consequences:

 `\nTo: =?utf-8?q?A_v=C3=A9ry_long_name_with_non-
 ASCII_char_and=2C_comma?=\n <[email protected]>\n`

 More details here: https://github.com/anymail/django-anymail/issues/369
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35378>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018ee761e795-51096eab-3e53-488b-a8e1-08d086724148-000000%40eu-central-1.amazonses.com.

Reply via email to