usr bin python import os from email import message_from_string from po

 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
#!/usr/bin/python
import os
from email import message_from_string
from poplib import POP3
from mailbox import mbox
from datetime import date
from time import strftime, strptime
from string import strip
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 range(nmsg):
msg = ""
for j in M.retr(i+1)[1]:
msg = msg + j + "\n"
_msg_ = message_from_string(msg)
h = _msg_.__getitem__("Received").split(";")
p = strip(h[1])
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_)