Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > mailbox module, Maildir, and flags

Reply
Thread Tools

mailbox module, Maildir, and flags

 
 
jesse.k.rosenthal@gmail.com
Guest
Posts: n/a
 
      09-11-2007
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:

>>> import mailbox
>>> mybox = mailbox.Maildir('~/Maildir/', mailbox.MaildirMessage)
>>> myfolder = mybox.get_folder('School')
>>> len(myfolder)

2102
>>> msg = myfolder.next()


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

>>> msg.get_flags()

''

Instead, I have to ener

>>> msg=myfolder.get_message(key)


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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mailbox.mbox Status/X-Status flags RFC? Tim Chase Python 0 08-30-2012 05:49 PM
Re: Quetion about flags of socket.recv(bufsize, [flags]) Steve Holden Python 0 02-08-2009 04:09 PM
Javamail and followup flags aaronfude@gmail.com Java 2 04-28-2006 01:42 PM
Newbie question on available IE data and staus flags in Perl DG Perl 0 05-27-2004 08:37 PM



Advertisments