New submission from A.M. Kuchling <li...@amk.ca>:

The attached test program shows how parsing an e-mail message with the email 
package, then converting the resulting message to a string, fails to round-trip 
properly.  Instead it breaks the encoding of the subject line.

The root of the problem: the subject is RFC-2047 quoted, long enough to require 
line wrapping, and it contains one of the splitchars used by Header.encode() -- 
meaning a semi-colon or comma.  In my example, this is:

Subject: 
=?utf-8?Q?2010_Foundation_Salary_and_Benefits_Report;_Important_Legislative_Efforts?=

Parsing the message turns that into a string S.  
generator.Generator._write_headers() then outputs Header(S).encode(), so it 
keeps treating the value as an ASCII string, and therefore breaks the header at 
the semicolon, resulting in:
  
Subject: 
=?utf-8?Q?2010_Foundation_Salary_and_Benefits_Report;<NEWLINE><SPACE>_Important_Legislative_Efforts?=

Newline and space aren't legal in Q encoding, so MUAs give up and display all 
the =?utf-8?Q? stuff.

----------
assignee: barry
components: Library (Lib)
files: email-roundtrip-failure.py
keywords: patch
messages: 106100
nosy: akuchling, barry
priority: normal
severity: normal
status: open
title: Straightforward usage of email package fails to round-trip
versions: Python 2.7
Added file: http://bugs.python.org/file17410/email-roundtrip-failure.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8769>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to