[Python-bugs-list] [ python-Bugs-586899 ] email package does not work with mailbox

noreply@sourceforge.net noreply@sourceforge.net
Fri, 26 Jul 2002 08:59:18 -0700


Bugs item #586899, was opened at 2002-07-26 05:19
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=586899&group_id=5470

Category: Python Library
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Paul Moore (pmoore)
>Assigned to: Barry A. Warsaw (bwarsaw)
Summary: email package does not work with mailbox

Initial Comment:
The email.message_from_file function does not seem to 
work correctly when used as the "factory" argument to 
the mailbox.UnixMailbox function. The "From_" 
separator line gets included in the preceding mail 
message.

For a demonstration of this, see the attached zip file. 
The Python code loads the first message in the mailbox 
file and then displays the final line. This shows the 
From_ line from the subsequent message (correctly 
quoted with a ">"!!!).

This is with Python 2.2 on Windows 2000. The Python 
banner line is

Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit 
(Intel)] on win32

----------------------------------------------------------------------

>Comment By: Barry A. Warsaw (bwarsaw)
Date: 2002-07-26 11:59

Message:
Logged In: YES 
user_id=12800

I don't have time to comment except to say that
email.message_from_file() definitely works as the factory
function for mailbox.UnixMailbox.  As proof, I have the
following code in Mailman:

class Mailbox(mailbox.PortableUnixMailbox):
    def __init__(self, fp):
        mailbox.PortableUnixMailbox.__init__(self, fp,
email.message_from_file)

so I know it works. :)

I'll look at the comments Paul's made when I get a chance. 
I'm assigning this bug report to me.

----------------------------------------------------------------------

Comment By: Paul Moore (pmoore)
Date: 2002-07-26 10:06

Message:
Logged In: YES 
user_id=113328

This is a text vs binary file issue with the mailbox module, not 
with email. The "fp" parameter to the [Portable]UnixMailbox 
class must be opened in binary mode, or incorrect results are 
obtained.

This is caused by the implementation of _Subfile.read() in 
mailbox.py, which assumes that number of characters read is 
the same as the difference between tell() values, an 
assumption which fails for text mode files on Windows.

I would consider this behaviour a bug, and would prefer it to 
be fixed. However, if it is not to be fixed, the documentation 
should be changed to note that the "fp" parameter for the 
mailbox constructor must be opened in binary mode.

For MMDF and Babyl format mailboxes, it's arguably correct, 
as the file format is binary. For Unix mailboxes, the file is text 
format, so opening the file in text mode is not unreasonable.

Question: is the universal newline support in Python 2.3 going 
to mess this up further?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=586899&group_id=5470