Skip to content

Instantly share code, notes, and snippets.

@jcrobak
Created April 2, 2011 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcrobak/899970 to your computer and use it in GitHub Desktop.
Save jcrobak/899970 to your computer and use it in GitHub Desktop.
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