Can I get message filename from a Maildir mailbox stream?

Noah noahspurrier at gmail.com
Tue Feb 22 18:59:52 EST 2005


This didn't work. I'm using the standard Python 2.3.4 library
mailbox.Maildir. I got an error that message instance
has no attribute 'fp'.

I ended up not using mailbox.Maildir at all.
It occured to me that since Maildir style mailboxes
is just a collection of files that it was simpler to write
a generator that walked the directory using os.listdir.

def Maildir_messages (path):
    d = os.listdir(path)
    for filename in d:
        fin = file (os.path.join(path, filename))
        yield (email.message_from_file(fin), filename)
        fin.close()

for msg, msg_filename in Maildir_messages ("/home/noah/Maildir/new"):
    print msg_filename
    print msg['Subject']

Yours,
Noah




More information about the Python-list mailing list