[New-bugs-announce] [issue22666] email.Header no encoding of unicode strings containing newlines

Flavio Grossi report at bugs.python.org
Sat Oct 18 15:08:05 CEST 2014

New submission from Flavio Grossi:

When trying to encode an email header with a newline in it, correct encoding is done only for strings and not for unicode strings.
In fact, for unicode strings, encoding is only done if a non ascii character is contained in it.

The attached patch should fix the problem.

Simple example to reproduce the problem:
>>> from email.Header import Header as H

# correctly encoded
>>> H('two\r\nlines', 'utf-8').encode()

# unicode string not encoded
>>> H(u'two\r\nlines', 'utf-8').encode()

# unicode string with non ascii chars, correctly encoded
>>> H(u'two\r\nlines and \xe0', 'utf-8').encode()

components: email
files: fix_email_header_encoding_uses_ascii_before_selected_charset.diff
keywords: patch
messages: 229640
nosy: barry, flavio, r.david.murray
priority: normal
severity: normal
status: open
title: email.Header no encoding of unicode strings containing newlines
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file36959/fix_email_header_encoding_uses_ascii_before_selected_charset.diff

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list