#35378: Incorrect folding of long address headers with special characters when
using 7bit Content-Transfer-Encoding in EmailMessage
-----------------------------+------------------------------------
     Reporter:  andres       |                    Owner:  (none)
         Type:  Bug          |                   Status:  new
    Component:  Core (Mail)  |                  Version:  dev
     Severity:  Normal       |               Resolution:
     Keywords:               |             Triage Stage:  Accepted
    Has patch:  0            |      Needs documentation:  0
  Needs tests:  0            |  Patch needs improvement:  1
Easy pickings:  0            |                    UI/UX:  0
-----------------------------+------------------------------------
Comment (by Mike Edmunds):

 [I'm responsible for the example cited above. Setting an existing
 message's `policy` attribute like that isn't documented anywhere, so
 probably shouldn't be considered a valid test case. Apologies for that.]

 I've come to the conclusion that any attempt to use modern
 email.policy.default to serialize an email.message.Message (which is
 constructed with legacy email.policy.compat32) is prone to errors, and
 probably just isn't supported by the Python email package. Additional
 information in https://github.com/anymail/django-
 anymail/issues/369#issuecomment-2184252097

 I would suggest ''not'' trying to fix this particular issue within Django.
 Long term, there would be a lot of advantages to upgrading
 django.core.mail to use modern email.message.EmailMessage (and
 email.policy.default). But that's a separate issue, and I think needs to
 happen all at once; trying to mix legacy and modern email code seems
 problematic.

 Here's an updated test, using only documented Python email package
 features (generator policy override). It has the same problem, but I think
 clarifies this is more of a Python email bug than a Django problem:

 {{{#!python
 import email.generator
 import email.policy
 import io
 import django.core.mail

 to = '"Người nhận a very very long, name" <t...@example.com>'
 mime_message = django.core.mail.EmailMessage(to=[to]).message()

 fp = io.BytesIO()
 g = email.generator.BytesGenerator(
     fp,
     policy=email.policy.default.clone(cte_type="7bit"),
 )
 g.flatten(mime_message)
 print(fp.getvalue().decode("ascii"))
 # [... other headers ...]
 # To: =?utf-8?b?TmfGsOG7nWkgbmjhuq1u?= a very very long, name
 <t...@example.com>
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35378#comment:8>
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/0107019042822890-135be665-7d99-4a35-9799-2af499672ff7-000000%40eu-central-1.amazonses.com.

Reply via email to