Created
May 14, 2012 12:01
-
-
Save solsticedhiver/2693582 to your computer and use it in GitHub Desktop.
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 characters
#!/usr/bin/python3 | |
import sys | |
import re | |
import os | |
import mailbox | |
def convert(maildir, mbox_name): | |
mbox = mailbox.mbox(mbox_name) | |
total = len(maildir.keys()) | |
print('Processing', total, 'emails in', mbox_name, file=sys.stderr) | |
count = 0 | |
for key in sorted(maildir.keys()): | |
# print progress | |
print(':: {:2}% done\r'.format(int((count/total)*100)), file=sys.stderr, end='') | |
count += 1 | |
mbox.add(maildir.get_message(key)) | |
mbox.flush() | |
mbox.close() | |
print('Done. ') | |
if __name__ == '__main__': | |
maildir = mailbox.Maildir('.') | |
main = os.getcwd().split('/')[-1] | |
print(main) | |
convert(maildir, '/tmp/{}.mbox'.format(main)) | |
for folder in maildir.list_folders(): | |
submaildir = maildir.get_folder(folder) | |
if len(submaildir.keys()) > 0: | |
convert(submaildir, '/tmp/{}.{}.mbox'.format(main, folder)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment