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.

classification
Title: email.mime.text.MIMEText: QP encoding broken with charset!=ISO-8859-1
Type: behavior Stage: resolved
Components: email, Library (Lib) Versions: Python 3.2, Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: barry, jwilk, python-dev, r.david.murray
Priority: normal Keywords:

Created on 2013-01-12 18:52 by jwilk, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg179826 - (view) Author: Jakub Wilk (jwilk) Date: 2013-01-12 18:52
If you try to create MIMEText object with text containing characters outside the ISO-8859-1 range,
the quoted-printable encoder fails with KeyError:

Python 3.2.3 (default, Sep 10 2012, 12:58:42) 
[GCC 4.7.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import email.mime.text
>>> email.mime.text.MIMEText('\u017c', 'plain', 'ISO-8859-2')
Traceback (most recent call last):
  File "/usr/lib/python3.2/email/message.py", line 331, in set_charset
    cte(self)
TypeError: 'str' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.2/email/mime/text.py", line 30, in __init__
    self.set_payload(_text, _charset)
  File "/usr/lib/python3.2/email/message.py", line 296, in set_payload
    self.set_charset(charset)
  File "/usr/lib/python3.2/email/message.py", line 333, in set_charset
    self._payload = charset.body_encode(self._payload)
  File "/usr/lib/python3.2/email/charset.py", line 395, in body_encode
    return email.quoprimime.body_encode(string)
  File "/usr/lib/python3.2/email/quoprimime.py", line 240, in body_encode
    if body_check(ord(c)):
  File "/usr/lib/python3.2/email/quoprimime.py", line 81, in body_check
    return chr(octet) != _QUOPRI_BODY_MAP[octet]
KeyError: 380
msg181456 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-02-05 16:35
New changeset 801cb3918212 by R David Murray in branch '3.2':
#16948: Fix quopri encoding of non-latin1 character sets.
http://hg.python.org/cpython/rev/801cb3918212

New changeset e644058e8e7b by R David Murray in branch '3.3':
Merge: #16948: Fix quopri encoding of non-latin1 character sets.
http://hg.python.org/cpython/rev/e644058e8e7b

New changeset 009dc81e8bc9 by R David Murray in branch 'default':
Merge: #16948: Fix quopri encoding of non-latin1 character sets.
http://hg.python.org/cpython/rev/009dc81e8bc9
msg181458 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-02-05 16:37
Fixed.  I'm glad you caught this before the final release of 3.2.  This is a bit of an embarrassing bug :(.
History
Date User Action Args
2022-04-11 14:57:40adminsetgithub: 61152
2013-03-20 19:12:55r.david.murraylinkissue17495 superseder
2013-02-05 16:37:14r.david.murraysetstatus: open -> closed
type: behavior
messages: + msg181458

resolution: fixed
stage: resolved
2013-02-05 16:35:02python-devsetnosy: + python-dev
messages: + msg181456
2013-01-12 18:57:06r.david.murraysetnosy: + barry, r.david.murray

components: + email
versions: + Python 3.3, Python 3.4
2013-01-12 18:52:55jwilkcreate