Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.