-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadmail.py
More file actions
54 lines (47 loc) · 918 Bytes
/
readmail.py
File metadata and controls
54 lines (47 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
"""
@author: TsingJyujing
"""
import email
import re
class eml():
def loadfile(self,file_name):
try:
fp = open(file_name,'r');
self.msg = email.message_from_file(fp);
fp.close();
return True
except:
return False
def getinfo(self,key):
try:
return self.msg.get(key)
except:
return ""
def getfrom(self):
str = self.getinfo("from")
if str==None:
return []
user = re.findall("<.*?>",str,re.DOTALL)
if len(user)<=0:
return []
else:
return [user[0][1:-1]]
def getto(self):
str = self.getinfo("to")
if str==None:
return []
users = re.findall("<.*?>",str,re.DOTALL)
if len(users)<=0:
return []
else:
rtnval = [];
for user in users:
rtnval.append(user[1:-1])
return rtnval
if __name__=="__main__":
fn = 'dnc_mails/3.eml';
msg = eml();
print msg.loadfile(fn)
print msg.getfrom()
print msg.getto()