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
#!/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
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=""
for j in M.retr(i+1)[1]:
msg = msg + j + "\n"
hmsg = message_from_string(msg)
h = hmsg["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
inbox.add(msg)