0

I have a lot of eml files, archived from an account, and stored in a bunch of folders, one per month. It's not a standard maildir structure, and the files don't have special names, they're just like:

2015-01/
 foo.eml
 bar.eml
 ...
2015-02/
 baz.eml
 qux.eml
 ...
etc

I would like to make them accessible, read-only, over IMAP, preferably using dovecot, without changing the structure/naming if possible. It would be great if all the emails can appear together in the inbox, but separate folders by month (as they are structured on disk) are ok too.

aditsu
  • 386
  • 1
  • 4
  • 10

2 Answers2

3

To make this work you'll have to at least move these messages into a MailDir like structure. My Dovecot maildir looks like this for the account ahoy@iswhale.com

./iswhale.com/ahoy/.Drafts/tmp
./iswhale.com/ahoy/.Drafts/new
./iswhale.com/ahoy/.Drafts/cur
./iswhale.com/ahoy/cur
./iswhale.com/ahoy/new
./iswhale.com/ahoy/tmp

If you make a new sub-folder, say 'Archive' it would look like this:

./ahoy/.Archive/tmp
./ahoy/.Archive/new
./ahoy/.Archive/cur

The tmp, new and cur are directories created by Dovecot when you make this new folder in a client (eg: Roundcube). When a new sub-folder of Archive is created the directory structure becomes:

./ahoy/.Archive.Sub-Folder/tmp
./ahoy/.Archive.Sub-Folder/new
./ahoy/.Archive.Sub-Folder/cur

So, you will need to adjust your directory paths to make '2015-01' become something like:

./user/.Archive.2015-01/tmp
./user/.Archive.2015-01/new
./user/.Archive.2015-01/cur

Then, once these directories are created you'll copy the '.eml' files (which I hope are just plain-text email of the type expected by Dovecot) into the target 'new' directory. Connect with your preferred IMAP client and all is well.

edoceo
  • 185
  • 3
  • Thanks, but that's exactly the kind of thing I'm trying to avoid... – aditsu May 09 '15 at 22:28
  • @aditsu You can also design your own mailformat and modify dovecot accordingly. I don't recommend to do that, edoceo provides the solution for your problem. You can also link the directories or files to the new structure. – sebix May 10 '15 at 10:48
1

I think I found a way to set up a maildir structure without making any changes to the folders and files I have. I made a separate maildir folder in a different place, and used symlinks to point to my mail-containing folders, like this:

maildir
├─ .2015-01
│  └─ cur -> path/to/2015-01
└─ .2015-02
   └─ cur -> path/to/2015-02

I gave dovecot write permissions to the maildir and its subdirs so that it can write its index files, new and tmp folders and whatnot, but it has no write permissions for the actual mail archive folders.

For the dovecot configuration (I'm only serving these files on this server, nothing else) I set mail_location = maildir:/path/to/my/maildir and used a static passdb and userdb.

This setup worked, but I also encountered a few problems:

  • All emails show up as unread

Solution: run doveadm flags add '\Seen' mailbox 201x-xx

  • The mail client can change flags, such as seen and deleted

Solution: added a global ACL file containing: * owner lr

So far so good, I'll update if anything else comes up.

aditsu
  • 386
  • 1
  • 4
  • 10