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.

Author mitya57
Recipients barry, mitya57
Date 2012-03-18.09:36:33
SpamBayes Score 0.0
Marked as misclassified No
Message-id <1332063395.16.0.293436373736.issue14360@psf.upfronthosting.co.za>
In-reply-to
Content
Currently my /usr/lib/python3.2/email/encoders.py has this code:

def _qencode(s):
    enc = _encodestring(s, quotetabs=True)
    # Must encode spaces, which quopri.encodestring() doesn't do
    return enc.replace(' ', '=20')

The problem is that _encodestring (which is just quopri.encodestring) always returns bytes, trying to run replace() on bytes raises "TypeError: expected an object with the buffer interface".

This leads to email.encoders.encode_quopri never working.

So, I think this should be changed to something like this:

    <...>
    return enc.decode().replace(' ', '=20')

Example log:

Python 3.2.3rc1 (default, Mar  9 2012, 23:02:43) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import email.encoders
>>> from email.mime.text import MIMEText
>>> msg = MIMEText(b'some text here')
>>> email.encoders.encode_quopri(msg)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.2/email/encoders.py", line 44, in encode_quopri
    encdata = _qencode(orig)
  File "/usr/lib/python3.2/email/encoders.py", line 23, in _qencode
    return enc.replace(' ', '=20')
TypeError: expected an object with the buffer interface

Reproduced on Ubuntu precise with Python 3.2.3rc1. Replacing encode_quopri with encode_base64 works fine.
History
Date User Action Args
2012-03-18 09:36:35mitya57setrecipients: + mitya57, barry
2012-03-18 09:36:35mitya57setmessageid: <1332063395.16.0.293436373736.issue14360@psf.upfronthosting.co.za>
2012-03-18 09:36:34mitya57linkissue14360 messages
2012-03-18 09:36:33mitya57create