tags:

views:

117

answers:

1

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?

+1  A: 

The folder /home/foo/Maildir/new is not a Maildir, it is part of the maildir. If you want to use mailbox.Maildir, you need to ignore the subdirectories and files which are part of the spec. Otherwise, you will not be treating it as a Maildir at all.

The Maildir module should read messages from new and cur, and may optionally move messages from new to cur when you close() or flush(). To know how this implementation does it, you will have to look at the code.

References:

vezult