How to move/reorganise existing e-mails to yearly subfolders

R. Diez rdiezmail-2006 at yahoo.de
Mon Oct 19 16:48:53 EEST 2020


Hi all:

I am new to e-mail servers and I am evaluating Dovecot. Not really the best combination. 8-)

I am trying to find a balance between legal data retention requirements and online mailbox size. I do not want huge online mailboxes, as doing 
offline, rotating data backups could then take forever (among other reasons). I would rather avoid online (cloud) backups (data protection etc.).

If I set a mailbox size limit, users will have to delete old mails by themselves. Or I could somehow script the deletion of attachments from old 
e-mails, as attachments are usually the main cause of huge mailboxes. Incidentally, can anyone point me to an easy way to achieve this? Preferably 
over with IMAP, otherwise with Dovecot tools.

With regards to legal data retention (which I am no expert about either), I thought I could use some Postfix BCC feature I heard about in order to 
copy all incoming and outgoing e-mails to a single "data retention" mailbox. Or maybe several of them. I could then archive e-mails from that mailbox 
on a yearly basis.

I would like to automatically organise e-mails inside that mailbox into subfolders like this:

2019/alice
2019/bob
2020/alice
2020/bob

That is: [year]/[username]

With such a folder structure, it is easier to see what is going on.

Is there a tool that can reorganise existing e-mails into such a folder structure?

I found some tools on the Internet to backup and export mails from IMAP to IMAP or maildir destinations. But I could not find a tool that just 
reorganises (moves) e-mails in such a manner inside an existing mailbox, maybe with a user-defined pattern for the destination folders.

I guess moving e-mails around on the same mailbox would be much faster than exporting and reimporting them in some clever way.

I could always write a Perl script, but that takes time. Such a tool may already exist. Or perhaps somebody could mention a similar, good-written 
script I can use as a starting point. I am sure there are many small gotchas to avoid. At the moment, I am only confident with Perl and Java. Maybe 
JavaScript.

It would be best to reorganise the e-mails over IMAP. This way, I am independent of the e-mail server. But a Dovecot-specific solution would also be 
helpful.

I could use such a reorganisation tool not just for archiving or data retention purposes, but to reorganise other mailboxes too, like my personal mailbox.

I would rather have a script. Clicking around in Thunderbird does not scale.

I have seen that you can use a "sieve" in Dovecot to achieve this. But I guess that would only apply to new e-mails. And that would probably apply 
just to incoming mails, and not to outgoing ones. If I migrate from the existing e-mail servers, the e-mails will probably be mass-imported without 
going through any "sieve", right?

Besides, I already have a few huge mailboxes with many years of e-mails, stored in a different e-mail server, and it would be nice to be able to 
reorganise them as they are. That way, I could archive the existing older e-mails before migrating to Dovecot, which would reduce the disk size and 
the export/import time for the migration.

Many thanks in advance,
   rdiez


More information about the dovecot mailing list