[issue9124] Mailbox module should use binary I/O, not text I/O

R. David Murray report at bugs.python.org
Fri Jan 28 21:58:23 CET 2011


R. David Murray <rdmurray at bitdance.com> added the comment:

Well, that's a bunch of code, and I'm afraid I don't know what your answer to my question was.  What error do you get now if you use the new version of mailbox3.patch?

If you feed the new mailbox/email bytes, it will preserve the bytes as is, as long as you don't try to convert the invalid headers to strings.  If you convert them to string (by accessing them through the Message object), it will encode them as 'unknown-8bit' using quopri or base64 as appropriate (ie: depending on how many non-ascii chars there are).  If you want instead to guess that they are latin-1, you can call decode_header on the stringified version to get back the original bytes, and then substitute your preferred guessed charset for the 'unknown-8bit' charset and go from there to unicode.  (For Python3.3 I plan to provide tools to make this kind of processing much simpler.)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9124>
_______________________________________


More information about the Python-bugs-list mailing list