﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27051	Exception when using only whitespace characters as e-mail subject	Moritz Sichert	nobody	"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.
"	Bug	closed	Core (Mail)	dev	Normal	wontfix	mail subject header		Unreviewed	0	0	0	0	0	0
