usr bin python from email import message_from_string from poplib impor

 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
#!/usr/bin/python
from email import message_from_string
from poplib import POP3
from mailbox import mbox
from datetime import date
from time import strftime, strptime
msg = ""
dtnow = date.today()
dtn = dtnow.replace(day=dtnow.day-2)
dtw = dtn.strftime("%Y/%m/%d")
inbox = mbox('mbox')
M = POP3('192.168.1.7')
M.user("prog2")
M.pass_("linuxserver")
nmsg = len(M.list()[1])
for i in xrange(nmsg):
msg = ""
if i==463:print "---"
else:
for j in M.retr(i+1)[1]:
msg = msg + j + "\n"
_msg_ = message_from_string(msg)
h = _msg_["Received"].split(";")
p = h[1].strip()
dt = strftime("%Y/%m/%d", strptime(p, "%a, %d %b %Y %H:%M:%S +0400"))
if dt < dtw:
print str(i) + ". "+dt#+" "+str(len(msg))
#inbox.add(_msg_)