This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: email.message.Message.set_payload and as_string given charset 'us-ascii' plus 8bit data produces invalid message
Type: behavior Stage: test needed
Components: email Versions: Python 3.2, Python 3.3, Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: barry, mitya57, r.david.murray
Priority: normal Keywords:

Created on 2009-11-10 22:32 by r.david.murray, last changed 2022-04-11 14:56 by admin.

Messages (2)
msg95133 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-11-10 22:32
The following produces a non-conformant message, since the us-ascii
charset is strictly 7bit:

>>> import email.message
>>> m = email.message.Message()
>>> m.set_payload("""A few lines
... of 8-bit text
... One high bit character: ².
... """, 'us-ascii')
>>> print m.as_string()
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 8bit

A few lines
of 8-bit text

One high bit character: ².

msg156629 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-03-23 01:55
In Python2 the fix would be to use charset unknown-8bit instead of us-ascii.

In Python3 this actually puts unicode in the message body.  There we should default to utf-8, but this requires a more extensive change than the Python2 change, and probably should not be backported.

Once this is fixed in Python3 the utf-8 default check can be removed from MIMEText (issue 14380).
Date User Action Args
2022-04-11 14:56:54adminsetgithub: 51553
2012-06-06 08:33:05mitya57setnosy: + mitya57
2012-05-24 14:51:48r.david.murraysetassignee: r.david.murray ->
components: + email, - Library (Lib)
2012-03-23 01:55:44r.david.murraysetmessages: + msg156629
versions: + Python 3.3, - Python 3.1
2012-03-23 01:33:36r.david.murraysetassignee: r.david.murray
2010-07-11 10:20:55BreamoreBoysetnosy: + barry

versions: - Python 2.6
2009-11-10 22:32:46r.david.murraycreate