I've made some slight changes, so you can now easily provide the folder path as an argument (where the juno file is in), thus if you save the code in a file as e.g. juno_mail_extractor.py, you can run it like this
Code:
python ./juno_mail_extractor.py path_to_folder
or if you make it executable, just
Code:
./juno_mail_extractor.py path_to_folder
(or just ./juno_mail_extractor path_to_folder if you remove the .py extension altogether)
Code:
#! /usr/bin/python
# -*- coding: utf-8 -*-
"""
Created on Sat May 28 09:53:24 2011
@author: endolith@gmail.com
"""
import mailbox
import OleFileIO_PL
from collections import defaultdict
import sys
import os.path
if len(sys.argv) == 1:
print >> sys.stderr, "You need to provide the paths to the folder"
sys.exit(1)
filename = os.path.expanduser(sys.argv[1])
def frm_to_dict(filename):
source = OleFileIO_PL.OleFileIO(filename + '.frm')
messages = defaultdict(dict)
for file in source.listdir():
if len(file) == 2: # Messages, not 'Directory'
msg_num = int(file[0])
msg_type = file[1]
stream = source.openstream(file).readlines()
messages[msg_num].update({msg_type: stream})
return messages
def dict_to_mbox(messages, filename):
destination = mailbox.mbox(filename + '.mbox')
for msg_num, streams in messages.iteritems():
content = streams['Header'] + streams['Body']
content = ''.join(content)
message = mailbox.mboxMessage(content)
destination.add(message)
destination.close()
messages = frm_to_dict(filename)
dict_to_mbox(messages, filename)
print "Operation completed, and it was probably successfull"
You probably need to download the OleFileIO_PL module from here. You don't need to install it, but you can extract it and then just place your juno_mail_extractor.py file in the same folder as the module files and call it from there.
Hope that helps.
EDIT: sorry I meant the folder path, not the file path..
Bookmarks