What does the list_folders() method of mailbox.Maildir actually do (if anything)?

Jeff McNeil jeff at jmcneil.net
Fri Sep 25 21:47:16 CEST 2009


On Sep 25, 3:22 pm, tinn... at isbd.co.uk wrote:
> I can't get the list_folders() method of the mailbox.Maildir class to
> do anything remotely useful.  It seems to do nothing at all.  I have a
> directory which contains a number of maildir malboxes:-
>
>     chris$ ls -l /home/chris/Mail/apex
>     total 24
>     drwx------ 5 chris chris 4096 2009-04-30 09:45 charles.rustin
>     drwx------ 5 chris chris 4096 2009-04-30 09:45 greg
>     drwx------ 5 chris chris 4096 2009-04-30 09:45 maureenMcgoldrick
>     drwx------ 5 chris chris 4096 2009-04-30 09:45 ram
>     drwx------ 5 chris chris 4096 2009-04-30 09:46 sarahLagley
>     drwx------ 5 chris chris 4096 2009-04-30 09:46 symonSmith
>     chris$ ls -l /home/chris/Mail/apex/ram
>     total 12
>     drwx------ 2 chris chris 4096 2009-04-30 09:45 cur
>     drwx------ 2 chris chris 4096 2009-04-30 09:45 new
>     drwx------ 2 chris chris 4096 2009-04-30 09:45 tmp
>
> If I run the following code:-
>
>     #!/usr/bin/python
>     #
>     #
>     # Mail archiving utility
>     #
>     import mailbox
>
>     topLevel=mailbox.Maildir("/home/chris/Mail/apex")
>     print topLevel.list_folders()
>
> It just outputs "[]".
>
> Am I doing something totally wrong or is list_folders() completely broken?
>
> --
> Chris Green

The Maildir++ spec states that folders need to begin with a period.
The list_folders method enforces that:

    def list_folders(self):
        """Return a list of folder names."""
        result = []
        for entry in os.listdir(self._path):
            if len(entry) > 1 and entry[0] == '.' and \
               os.path.isdir(os.path.join(self._path, entry)):
                result.append(entry[1:])
        return result

The above example is from 2.6.  Your structure is simply a list of
Maildir compliant directories below '/home/chris/Mail/apex.' They're
not, in the Maildir++ sense of the word, folders.

--
Thanks,

Jeff
mcjeff.blospot.com



More information about the Python-list mailing list