contrib/convert-mbox-maildir.py
author Adrian Buehlmann <adrian@cadifra.com>
Sun, 03 Apr 2011 11:51:01 +0200
changeset 55 59814494f238
parent 23 aux/convert-mbox-maildir.py@a42b9c661bc1
permissions -rw-r--r--
rename aux directory to contrib On Windows, aux is a reserved name and can't be used for files or directories.

import mailbox, glob, os.path, os
import artemis
from mercurial import ui, hg

repo = hg.repository(ui.ui())

issue_filenames = glob.glob(os.path.join(artemis.issues_dir, '*'))
for fn in issue_filenames:
    mb = mailbox.mbox(fn)
    messages = [m for m in mb]
    mb.close()
    os.unlink(fn)
    repo.remove([fn])
    md = mailbox.Maildir(fn)
    md.lock()
    keys = [md.add(m) for m in messages]
    md.close()
    for k in keys: repo.add([fn + '/new/' + k])