How to test for maildir 'folder' in Python?

Chris Green cl at isbd.net
Sat Jan 22 16:26:37 EST 2022


I have a script that walks a quite deep tree of mail messages to find
and archive old messages.  I'm trying to convert it from mbox to
maildir (as I now store my mail in maildir format).

So I need to test whether a point I have reached in the hierarchy is a
maildir mailbox or not.  Using mbox format it's easy because 'folders'
are directories and mailboxes are files.  However with maildir the
'folders' have directories within them so the simple tree walking goes
down a level too far and finds 'folders' which aren't mailboxes called
'cur', 'new' and 'tmp'.

Is there any 'ready made' way in python to tell whether a directory is
a maildir mailbox?  If not I suppose I'll simply have to check if
there are 'cur', 'new' and 'tmp' directories within the directory
which may or may not be a maildir.

-- 
Chris Green
·


More information about the Python-list mailing list