[Tutor] Directory Structure

Chris chris2014 at postbox.xyz
Sat Sep 30 01:56:15 EDT 2017


Thank you for your detailed reply! I've tried to explain in my mails to
Alan and Mats what I'm trying to achieve.

On Sat, 30 Sep 2017 11:32:57 +1000
Steven D'Aprano <steve at pearwood.info> wrote:

> On Fri, Sep 29, 2017 at 07:02:07PM +0200, Chris wrote:
> 
> > Background: Maildirs with mails older than five years should be
> > archived. The folder structure should be kept in the target.  
> 
> Archived to what?

A separate Maildir on tape.

> > I was very surprised, that there seems no readily usable module
> > available. (In Perl neither).  
> 
> Reusable module to do what *precisely*? If you cannot explain what
> you need, how do you expect somebody to have anticipated your
> requirements and written a module to do it?

Represent the structure in memory.
 
> > What's the best way to save them?  
> 
> Depends on what you are doing. But coding the paths in your source
> code is almost certainly not what you want to do. Surely you want to
> read the paths from the maildir itself, as it *actually* exists,
> rather than try to hard-code what you expect it to be in your source
> code?

Well, if I had the structure in memory, I could save additional
information and could print different lists, e.g. sorted by attachment
size, sorted by project. A project can appear in different places
in the tree.

> Have you looked at the contents of a maildir? Its actually an almost 
> flat structure. Nested mail folders are not nested on the disk: a 
> user's mail folder structure that looks like:
> 
> inbox
> sent
> trash
> personal
> ├── family
> └── friends
> work
> ├── critical
> ├── important
> └── low
> 
> 
> is stored on disk as:
> 
> Maildir/
> ├──  .sent/
> ├──  .trash/
> ├──  .personal/
> ├──  .personal.family/
> ├──  .person.friends/
> ├──  .work
> ├──  .work.critical
> ├──  .work.important
> └──  .work.low

Good objection. You can make dovecot use the first layout on disk.
Probably not a gain in disguise.
 
> So all you really need is to record the path to the top level maildir 
> directories (the original, and the place where you are archiving
> them). The subdirectories, you read from the disk as you go.

Ok, I could even do this with the first structure. 
 
> Actually, *you* don't read them at all. Have you looked at the
> mailbox module in the standard library? It supports Maildir. I expect
> that what you would do is something like:
> 
> source = Maildir('path/to/source')
> archive = Maildir('path/to/archive')
> for each directory in source:
>     for each mail in directory:
>         if mail older than five years:
>             copy mail to archive
>             delete mail from source

I've used os.walk. I'll have a look at the Maildir library.


- Chris


More information about the Tutor mailing list