How to test for maildir 'folder' in Python?
Cameron Simpson
cs at cskk.id.au
Sat Jan 22 18:43:35 EST 2022
On 22Jan2022 21:26, Chris Green <cl at isbd.net> wrote:
>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.
I was hoping that the provided mailbox/Maildir class had something, but
apparently not.
So I suggest fetching my cs.mailutils module from PyPI and using its
ismaildir(path) function, which does exactly what you describe.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-list
mailing list