How to test for maildir 'folder' in Python?
Barry Scott
barry at barrys-emacs.org
Sun Jan 23 07:20:30 EST 2022
> On 22 Jan 2022, at 21:26, Chris Green <cl at isbd.net> wrote:
>
> 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.
You do not need to walk the tree.
The structure is
Maildir/cur, new, tmp - The INBOX
Maildir/<encoded-mail-folder>/cur, new, tmp
The encoding prefixed with a "." and uses a "." between folder name parts.
An example from my Maildir is ".Python.Users/" for a folder that client
shows as Python/Users
You can see this by doing:
ls -a ~/Maildir
Barry
>
> --
> Chris Green
> ยท
> --
> https://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list