diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-02-05 15:49:49 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-02-05 15:49:49 (GMT) |
commit | f581b372003de0ae604c14a1f1dc2e8c36ea277b (patch) | |
tree | ed6202c27c0c8f2fb739acdfa6e3b6eaaed620d2 /Lib/email/charset.py | |
parent | 43536e9e373f395a047403831c08acedf3c5f258 (diff) | |
download | cpython-f581b372003de0ae604c14a1f1dc2e8c36ea277b.zip cpython-f581b372003de0ae604c14a1f1dc2e8c36ea277b.tar.gz cpython-f581b372003de0ae604c14a1f1dc2e8c36ea277b.tar.bz2 |
#16948: Fix quopri encoding of non-latin1 character sets.
Diffstat (limited to 'Lib/email/charset.py')
-rw-r--r-- | Lib/email/charset.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/email/charset.py b/Lib/email/charset.py index f22be2c..c106649 100644 --- a/Lib/email/charset.py +++ b/Lib/email/charset.py @@ -392,6 +392,19 @@ class Charset: string = string.encode(self.output_charset) return email.base64mime.body_encode(string) elif self.body_encoding is QP: + # quopromime.body_encode takes a string, but operates on it as if + # it were a list of byte codes. For a (minimal) history on why + # this is so, see changeset 0cf700464177. To correctly encode a + # character set, then, we must turn it into pseudo bytes via the + # latin1 charset, which will encode any byte as a single code point + # between 0 and 255, which is what body_encode is expecting. + # + # Note that this clause doesn't handle the case of a _payload that + # is already bytes. It never did, and the semantics of _payload + # being bytes has never been nailed down, so fixing that is a + # longer term TODO. + if isinstance(string, str): + string = string.encode(self.output_charset).decode('latin1') return email.quoprimime.body_encode(string) else: if isinstance(string, str): |