Getting all new messages from a Maildir in python
Posted
by Jesper
on Stack Overflow
See other posts from Stack Overflow
or by Jesper
Published on 2010-04-19T16:32:32Z
Indexed on
2010/04/19
17:03 UTC
Read the original article
Hit count: 409
I have a mail dir:
foo@foo:~/Maildir$ ls -l
total 288
drwx------ 2 foo foo 155648 2010-04-19 15:19 cur
-rw------- 1 foo foo 440 2010-03-20 08:50 dovecot.index.log
-rw------- 1 foo foo 112 2010-03-20 08:49 dovecot-uidlist
-rw------- 1 foo foo 8 2010-03-20 08:49 dovecot-uidvalidity
-rw------- 1 foo foo 0 2010-03-20 08:49 dovecot-uidvalidity.4ba48c0e
drwx------ 2 foo foo 114688 2010-04-19 16:07 new
drwx------ 2 foo foo 4096 2010-04-19 16:07 tmp
And in python I'm trying to get all new messages (Python 2.6.5rc2). First, getting "Maildir" works:
>>> import mailbox
>>> md = mailbox.Maildir('/home/foo/Maildir')
>>> md.iterkeys().next()
'1269924477.Vfc01I4249fM708004.foo'
But how do I access "Maildir/new"? This does not work:
>>> md = mailbox.Maildir('/home/foo/Maildir/new')
>>> md.iterkeys().next()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/mailbox.py", line 346, in iterkeys
self._refresh()
File "/usr/lib/python2.6/mailbox.py", line 467, in _refresh
for entry in os.listdir(subdir_path):
OSError: [Errno 2] No such file or directory: '/home/foo/Maildir/new/new'
>>>
Any ideas?
© Stack Overflow or respective owner