[1.5.2] Buglet in Mailbox-module?
Robert Amesz
rcameszREMOVETHIS at dds.removethistoo.nl
Fri Sep 29 19:17:13 EDT 2000
When trying to access some of my .MBX-files using the Mailbox-module
which came with Python 1.5.2, I quickly found out that module just
didn't work for me: the next() method just returned None each time, and
not the rfc822-object I expected. So I inspected the mailbox.py file in
the Python library, and my eye was drawn to the routine which
identified the From-line which is used to indicate the start of a new
message. Sure enough the r.e. which it uses didn't match those lines in
*my* MBX-files. The fix itself proved to be rather trivial, and
consisted of adding a '?' in the right place. As I don't like to mess
with standard library files I just made a new class:
import mailbox
class MyMailbox(mailbox.UnixMailbox):
_fromlinepattern = r"From \s*[^\s]+\s+\w\w\w?\s+\w\w\w\s+\d?\d\s+" \
r"\d?\d:\d\d(:\d\d)?(\s+[^\s]+)?\s+\d\d\d\d\s*$"
(Note that the last two lines should be indented an extra tab, but
otherwise these would get wrapped by my newsreader.)
(Also note that this is a bit weird if you're used to C++ or Java,
since those languages don't have virtual data members, just virtual
functions.)
(The extra '?' I spoke of is the one just after the 3rd \w.)
The problem is (or rather: was) that the library routine expects the
names of weekdays to be abbreviated to exactly 3 characters (mon, tue,
etc.), whereas in my files these are just two characters long (ma, di,
etc.). And no, there's nothing wrong with your eyes, it is Dutch, so it
might be a locale thing.
So, my question is, is the mailbox module too strict, or is are my MBX-
files just a little off? If this is indeed a small bug I might report
it, provided of course it isn't fixed already in 1.6 or 2b. If it isn't
a bug I hope the workaround may be useful for anyone with a similar
problem.
Also, I'd be interested to hear if anyone implemented reader classes
for more mailbox formats, or if there are modules for writing or
manipulating mailboxes.
Lastly, I'm afraid I'm less than impressed with the speed of the
mailbox module. A 736 K file, contaning 262 messages took 14 seconds to
read on my trusty P133-box. (Although, to be fair, this could be due to
the rfc822-module which it uses.) Any thoughts on that?
Robert Amesz
More information about the Python-list
mailing list