import os
import email
def WalkDir(dir, file_callback=None):
i=0;
for root, dirs, files in os.walk(dir):
for f in files:
i=i+1
print "prosessing the email:"+f
file_path = os.path.join(root, f)
if file_callback:
file_callback(file_path)
def GetSenderInfo(file):
try:
ext = os.path.splitext(file)[1]
if ext in ('.EML', '.eml'):
femail = open(file)
msg = email.message_from_file(femail)
peopleFrom = email.utils.parseaddr(msg.get("from"))[1]
peopleTo = email.utils.parseaddr(msg.get("to"))[1]
ffrom.write(str(peopleFrom)+'\n')
fto.write(str(peopleTo)+'\n')
femail.close()
except:
pass
if __name__ == "__main__":
path = raw_input('Path: ')
ffrom = open('from.txt','w')
fto = open('to.txt','w')
WalkDir(path, GetSenderInfo)
ffrom.close()
fto.close()