Created
December 19, 2014 21:23
-
-
Save arpagon/51d2824a2120723d8110 to your computer and use it in GitHub Desktop.
Revisions
-
arpagon created this gist
Dec 19, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ #!/usr/bin/env python import zarafa import mailbox import os import shutil from zarafa import Folder ignored_folders = [ 'Suggested Contacts', 'Quick Step Settings', 'Conversation Action Settings', 'RSS Feeds', 'Junk E-mail', 'Tasks', 'Notes', 'Journal', 'Calendar', 'Contacts', 'Deleted Items', 'Outbox' ] def mymbox(self, location): maildir = location.add_folder(self.name) maildir.lock() for item in self.items(): maildir.add(item.eml()) maildir.unlock() Folder.mbox = mymbox def format(): wp = os.getcwd() for folder in os.listdir(wp): wd = wp wd = wd +'/'+ folder os.mkdir(wd + '/Maildir') #Remove this if you do not want to mark mails as read for dirname, dirnames, filenames in os.walk(wd): for subdirname in dirnames: if 'new' in subdirname: for file in os.listdir(os.path.join(dirname, subdirname)): shutil.move(os.path.join(dirname, subdirname) + '/' + file, os.path.join(dirname, 'cur') + '/' + file + ':2,S') for folder in os.listdir(wd): if (folder == ".Sent Items"): shutil.move (wd + '/' + folder, wd + '/Maildir/.Sent') elif (folder == '.Inbox'): for file in os.listdir(wd + '/' + folder): shutil.move(wd + '/' + folder + '/' + file, wd + '/Maildir/') elif (folder != 'cur' and folder != 'new' and folder != 'tmp' and folder != 'Maildir'): shutil.move (wd + '/' + folder, wd + '/Maildir/' + folder) def main(): s = zarafa.Server() for user in s.users(remote=False): print 'user:', user.name if user.name in ('manuel.restrepo','sebastian.rojo'): if user.store: maildir = mailbox.Maildir(user.name) for folder in user.store.folders(recurse=True, parse=True): if folder.name in ignored_folders: continue print ' folder: count=%s size=%s %s%s' % (str(folder.count).ljust(8), str(folder.size).ljust(10), folder.depth*' ', folder.name) folder.mbox(maildir) if __name__ == '__main__': main() format()