Opened 9 years ago
Closed 9 years ago
#27051 closed Bug (wontfix)
Exception when using only whitespace characters as e-mail subject
| Reported by: | Moritz Sichert | Owned by: | nobody |
|---|---|---|---|
| Component: | Core (Mail) | Version: | dev |
| Severity: | Normal | Keywords: | mail subject header |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Steps to reproduce:
Python 3.5.2 (default, Jun 28 2016, 08:46:01)
[GCC 6.1.1 20160602] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django.conf
>>> django.conf.settings.configure()
>>> from django.core import mail
>>> mail.EmailMessage(subject=' ', from_email='django@example.com').message()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/django/django/core/mail/message.py", line 311, in message
msg['Subject'] = self.subject
File "/home/user/django/django/core/mail/message.py", line 236, in __setitem__
name, val = forbid_multi_line_headers(name, val, self.encoding)
File "/home/user/django/django/core/mail/message.py", line 102, in forbid_multi_line_headers
val = Header(val).encode()
File "/usr/lib/python3.5/email/header.py", line 387, in encode
value = formatter._str(linesep)
File "/usr/lib/python3.5/email/header.py", line 423, in _str
self.newline()
File "/usr/lib/python3.5/email/header.py", line 435, in newline
self._lines[-1] += str(self._current_line)
IndexError: list index out of range
This error doesn't occur when directly setting msg['Subject'] = ' ' on a plain email.message.Message. Using subjects like ' foo' or 'foo ' also works.
It might still be a bug in Python, though, as the Exception isn't raised in Django's code but in the email module while trying to encode the Subject header.
Change History (2)
comment:1 by , 9 years ago
| Summary: | Exception when using a single space character as e-mail subject → Exception when using only whitespace characters as e-mail subject |
|---|
comment:2 by , 9 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
It seems to be a regression in Python 3. I created http://bugs.python.org/issue27737. I don't think the issue is so critical that we need to add a workaround in Django but if someone feels otherwise and wants to submit a patch, feel free to reopen.