New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
email.quoprimime.body_encode can't handle characters that encodings.quopri_codec can #61697
Comments
When using email.charset.Charset to encode MIME bodie as quoted-printable, some characters that are encodable with the quopri_codec cause a KeyError in email.quoprimime: Python 3.3.0 (default, Oct 7 2012, 14:43:21)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> text_encoded = b'mo \xe2\x82\xac'
>>> text = text_encoded.decode('utf-8')
>>> print(text)
mo €
>>> import codecs
>>> codecs.getencoder('quopri_codec')(text_encoded)[0]
b'mo=20=E2=82=AC'
>>> from email import charset
>>> c = charset.Charset('utf-8')
>>> c.header_encoding = charset.QP
>>> c.body_encoding = charset.QP
>>> c.header_encode(text)
'=?utf-8?q?mo_=E2=82=AC?='
>>> c.body_encode(text)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.3/email/charset.py", line 395, in body_encode
return email.quoprimime.body_encode(string)
File "/usr/lib/python3.3/email/quoprimime.py", line 240, in body_encode
if body_check(ord(c)):
File "/usr/lib/python3.3/email/quoprimime.py", line 81, in body_check
return chr(octet) != _QUOPRI_BODY_MAP[octet]
KeyError: 8364 |
What is the reason that email.quoprimime doesn't use codecs.getencoder('quopri_codec') to do the actual character encoding? |
There is a long history behind quoprime in the email package, and I don't know all of it. It is on my list of things to sort out (there is also potential duplication with the binascii module), but I haven't gotten to it yet. The issue you report, though is a duplicate of bpo-16948 and is already fixed in the repo. You checked off 2.7. Did you actually see a failure in 2.7? It shouldn't be broken there. |
I thought I had tested it under 2.7, but I'm not entirely sure. |
OK, if you find it is a bug on 2.7 you can reopen. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: