mailbox module, Maildir, and flags

J

jesse.k.rosenthal

Dear all,

I'm trying to figure out if mailbox will let me get the flags of a
Maildir message without running get_message on it, and reading the
whole message. It seems like it should work by doing this:

But then,when I try to get_flags on msg, I get nothing
''

Instead, I have to ener

which reads the whole message. Then the flags show up (RS or
whatever). Given that there's 2102 messages in the folder, and some of
them have attachments, I'd rather run get_message on all of them.

To explain my motivation: I'm writing a curses email client as a
hobby. I started out with IMAP, and implemented a simple caching
behaviour, using a pickled cache. When it logs in to the IMAP server,
it checks only the uids and flags on the server, compares those to the
ones in the cache, and from that can figure out what has been added,
deleted, or changed. From that, it can figure out what headers to
download. Saves a *lot* of time at startup.

I'd like to implement something like this for Maildir. Figure out
which msgs it needs to get a new Message instance for, and only those.
The rest are in the cache. So after the first time, starting up on a
large maildir folder will be pretty quick. Following the same logic, I
just need the unique names and the flags. Now, I know the flags are in
the name, but I can't find anyway in the mailbox module to get them.

So, should I just run some text parsing on the filenames, using
os.listdir? Given:

'1110326951.M818715P9617V0000000000000307I001A45A4_1401.belacqua,S=960:2,RS'

it's easy enough to apply string.split(":2,"). But then I have to deal
with all the nastiness of the maildir standard. This is probably what
I'll end up doing, but I was wondering if the mailbox module had a way
to do it.

One other question. Given a mailbox.Maildir folder like the one above,
is there a way to run through it and just get the headers? Basically,
the opposite of get_payload? I know I can scew around with msg.keys(),
but is there something like

for msg in folder:
hdr = msg.get_header()

?

Thanks for all your help. Sorry if this was unclear or long-winded.

Best,
Jesse
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,734
Latest member
manin

Latest Threads

Top