Created
April 16, 2018 13:05
-
-
Save bkram/9b74fa5b6ca63c0e99a9c72906b099e2 to your computer and use it in GitHub Desktop.
Migrate Cyrus directory structure to a Kopano user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 | |
import os | |
import kopano | |
userfolder = '/var/spool/cyrus/mail/i/user/cyrususer' | |
kuser = kopano.user('kopanouser') | |
IGNORE = ['cyrus.cache', 'cyrus.index', 'cyrus.header'] | |
for d in os.walk(userfolder): | |
dest = d[0].replace(userfolder, '') | |
if not len(dest): | |
dest = 'mapi.inbox' | |
else: | |
dest = dest.replace('/', '', 1) | |
if dest == 'mapi.inbox': | |
kdest = kuser.inbox | |
else: | |
kdest = kuser.subtree.folder(dest, create=True) | |
print('Processing "{}" as "{}"'.format(d[0] + '/', kdest.name)) | |
files = d[2] | |
for file in files: | |
if file not in IGNORE: | |
fname = d[0] + '/' + file | |
eml = open(fname, 'rb').read() | |
try: | |
newitem = kdest.create_item(eml=eml) | |
kuser.store.item(newitem.entryid).mapiobj.SetReadFlag(0) | |
except Exception as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment