473,378 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

mailbox module, Maildir, and flags

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

Sep 11 '07 #1
0 1407

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chuck Amadi | last post by:
Has anyone got a simple python script that will parse a linux mbox and create a large file to view . Cheers Chu
6
by: chuck amadi | last post by:
Hi , Im trying to parse a specific users mailbox (testwwws) and output the body of the messages to a file ,that file will then be loaded into a PostGresql DB at some point . I have read the...
3
by: noah | last post by:
Is there a way to figure out what filename an email object points to in a qmail style Maildir directory? Hmmm... I don't think so, but I'm hoping I wrong. I instantiated a Maildir mailbox and...
2
by: tinnews | last post by:
I am trying to write a utility to remove empty maildir mailboxes. It sounds like this should be very simple but it's proving really difficult. I'm doing this on a Fedora 7 system with python...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.