Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Makes a mbox from all the files in the directory -- for example, used for recovering files in Mail.app's .OfflineCache.
import mailbox
import email.utils
import os
mbox = mailbox.mbox('recovered.mbox')
mbox.lock()
try:
for infile in os.listdir(os.path.dirname(os.path.abspath(__file__))):
if not '.' in infile:
print "processing: %s" % infile
fp = open(infile)
msg = email.message_from_file(fp)
fp.close()
mbox.add(msg)
mbox.flush()
finally:
mbox.unlock()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment