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

STINNER Victor report at bugs.python.org
Wed Jan 26 01:58:51 CET 2011

STINNER Victor <victor.stinner at haypocalc.com> added the comment:

 - open files in binary mode not as text
 - parse as bytes not as Unicode
 - replace email.generator.Generator() by email.generator.BytesGenerator()
 - use .message_from_bytes() instead of .message_from_str()
 - use .message_from_binary_file() instead of .message_from_file()
 - use BytesIO() instead of StringIO()
 - add more methods to _ProxyFile: readable, writable, seekable, flush, closed
 - don't use universal newline (not supported by binary files): I don't remember if the email binary parser supports directly universal newline

I don't know anything about the mailbox module. I just replaced str functions by bytes functions.

Keep Unicode for some things: MH.get_sequence() reads the file using UTF-8 encoding, labels and sequences.

The patch have to be tested on Windows (Windows uses \r\n newline). I only tested on Linux.

keywords: +patch
Added file: http://bugs.python.org/file20522/mailbox.patch

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list