convert from maildir to Cyrus DB

Craig Ringer craig at postnewspapers.com.au
Fri Feb 13 13:00:51 EST 2004


On Fri, 2004-02-13 at 21:59, Andrew J Caird wrote:

>   One keyword that should find at least one message in the thread to get
> you started is "mailutil".

While I agree with the above suggestion (read the archives, consider
using mailutil), I thought it'd be interesting to see if direct import
was possible. Cyrus uses a custom mailbox format (one file per message
like maildir, but otherwise unrelated to anything else AFAIK), so you
can't just copy over mailboxes directly. I thought I'd see how hard it
was to do so, though I question the utility and sensibility of doing so
for anything but testing.

It appears to be possible to import maildirs by renaming all messages to
the cyrus-style 'n.' format, moving the directory into the desired
location and fixing it's permissions. `reconstruct -r -f` didn't seem to
want to find the mailbox, but using cyradm to 'cm' the path then
reconstructing the mailbox seemed to work.

To do the renaming, this works:

#!/usr/bin/env python                                                   
import os,sys
msglist = os.listdir(sys.argv[1])
for (mdid, uid) in map( lambda x,y:(x,y), msglist, range(1,
len(msglist)+1 )):
        print "%s -> %s." % (mdid, uid)
        os.rename( mdid, "%s." % uid )

then just:
root#  mv $maildir $cyrus_partition/$target_mailbox
root#  chown -R cyrus.mail $cyrus_partition/$target_mailbox
cyrus$ [ using cyradm, 'add' the mailbox ]
cyrus$ reconstruct -r -f $parent_of_target_mailbox

I don't know if it's correct, it's definitely ugly, and it's probably a
really bad idea to do. It did, however, appear to work. 

So - a question to those who know about the innards of the Cyrus mailbox
handling: is it reasonable to import maildirs directly as a migration
option? Can significant problems be expected? Is it likely to be much
faster to copy directly rather than use IMAP? What about read status
(the ,2BLAH suffix in maildir)?

Oh, and allow me to repeat: if you use the method I've described above,
without confirmation that it's safe, you're insane.

Of course, if you can import maildir you can import mbox pretty easily,
too.

So - thoughts, anybody?

Craig Ringer

---
Home Page: http://asg.web.cmu.edu/cyrus
Wiki/FAQ: http://cyruswiki.andrew.cmu.edu
List Archives/Info: http://asg.web.cmu.edu/cyrus/mailing-list.html




More information about the Info-cyrus mailing list