[Python] Access maildir inbox from Python

Discussão em 'Python' iniciado por Stack, Abril 20, 2025.

  1. Stack

    Stack Membro Participativo

    How do I access messages in the top-level folder of a maildir in Python?

    The top-level folder does not show iup in list_folders(), and iterating over the messages gives me messages in all folders, which I don't want.

    import mailbox
    import os
    dirpath = os.path.join(os.environ['HOME'], 'Maildir')
    mbox = mailbox.Maildir(dirpath, create=False)

    print(mbox.list_folders()) # Top-level folder does not show up
    folder = mbox.get_folder(???) # What do I put here?
    for msg in folder.itervalues():
    ...

    Continue reading...

Compartilhe esta Página