diff -r 65f2c92ed079 Lib/email/message.py --- a/Lib/email/message.py Sun Jul 07 23:30:24 2013 +0200 +++ b/Lib/email/message.py Wed Jul 10 23:53:43 2013 +0800 @@ -182,9 +182,9 @@ def get_payload(self, i=None, decode=False): """Return a reference to the payload. - The payload will either be a list object or a string. If you mutate - the list object, you modify the message's payload in place. Optional - i returns that index into the payload. + The payload will either be a list object, a string or a bytes + sequence. If you mutate the list object, you modify the message's + payload in place. Optional i returns that index into the payload. Optional decode is a flag indicating whether the payload should be decoded or not, according to the Content-Transfer-Encoding header @@ -245,6 +245,8 @@ # If it does happen, turn the string into bytes in a way # guaranteed not to fail. bpayload = payload.encode('raw-unicode-escape') + if isinstance(payload, bytes): + bpayload = payload if not decode: return payload if cte == 'quoted-printable': diff -r 65f2c92ed079 Lib/test/test_email/test_email.py --- a/Lib/test/test_email/test_email.py Sun Jul 07 23:30:24 2013 +0200 +++ b/Lib/test/test_email/test_email.py Wed Jul 10 23:53:43 2013 +0800 @@ -552,6 +552,15 @@ msg._payload = x self.assertEqual(msg.get_payload(decode=True), x) + def test_binary_quopri_payload(self): + # Although not documented, this is supposed to work. + msg = Message() + msg['content-type'] = 'text/plain; charset=latin-1' + msg['content-transfer-encoding'] = 'quoted-printable' + msg.set_payload(b'foo=e6=96=87bar') + self.assertEqual(msg.get_payload(decode=True), + b'foo\xe6\x96\x87bar') + # Issue 1078919 def test_ascii_add_header(self): msg = Message()