#31784: Emails name over 75 characters are incompatible with the latest
versions of
python.
-----------------------------+------------------------------------
Reporter: Nick Orr | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 2.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Comment (by Florian Apolloner):
Oh, it needs a non-ascii character to trigger encoding in the first place:
{{{
from django.conf import settings
settings.configure()
from django.core.mail.message import EmailMessage
e = EmailMessage('subject', 'content', '[email protected]', ['"TestUser
รค%s" <[email protected]>' % ('0' * 100)])
print(e.message().as_string())
}}}
raises
{{{
Traceback (most recent call last):
File "/home/florian/sources/django.git/django/core/mail/message.py",
line 62, in forbid_multi_line_headers
val.encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode character '\xe4' in
position 10: ordinal not in range(128)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "testing.py", line 7, in <module>
print(e.message().as_string())
File "/home/florian/sources/django.git/django/core/mail/message.py",
line 242, in message
self._set_list_header_if_not_empty(msg, 'To', self.to)
File "/home/florian/sources/django.git/django/core/mail/message.py",
line 397, in _set_list_header_if_not_empty
msg[header] = value
File "/home/florian/sources/django.git/django/core/mail/message.py",
line 154, in __setitem__
name, val = forbid_multi_line_headers(name, val, self.encoding)
File "/home/florian/sources/django.git/django/core/mail/message.py",
line 65, in forbid_multi_line_headers
val = ', '.join(sanitize_address(addr, encoding) for addr in
getaddresses((val,)))
File "/home/florian/sources/django.git/django/core/mail/message.py",
line 65, in <genexpr>
val = ', '.join(sanitize_address(addr, encoding) for addr in
getaddresses((val,)))
File "/home/florian/sources/django.git/django/core/mail/message.py",
line 107, in sanitize_address
parsed_address = Address(nm, username=localpart, domain=domain)
File "/usr/lib64/python3.7/email/headerregistry.py", line 37, in
__init__
raise ValueError("invalid arguments; address parts cannot contain CR
or LF")
ValueError: invalid arguments; address parts cannot contain CR or LF
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31784#comment:11>
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/067.f889b6abe55a4a804015f94146a0a811%40djangoproject.com.