-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendat.py
More file actions
35 lines (33 loc) · 990 Bytes
/
sendat.py
File metadata and controls
35 lines (33 loc) · 990 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
import smtptools
import imaptools
from config import *
from dateutil import parser
import re
import datetime
def parseAt(msg):
m = re.search('^\[at\s*(.*?)\]\s*(.*)$', imaptools.headerUnicode(msg['Subject']))
if m:
return parser.parse(m.group(1)), m.group(2)
return None, msg['Subject']
S = smtptools.MySMTP(smtp_host, smtp_port, smtp_username, smtp_password)
M = imaptools.MyIMAP(imap_host, imap_port)
M.login(imap_username, imap_password)
nums = M.nums("[Gmail]/Drafts")
deletable = []
for num in nums:
msg = M.asMIMEText(num)
at, subject = parseAt(msg)
if at:
print "SEND "+subject.encode('UTF-8')+" AT "+str(at),
if at < datetime.datetime.now():
print "NOW"
S.refresh(msg, subject)
S.sendmime(msg)
deletable.append(num)
else:
print "LATER"
else:
print "SKIP "+imaptools.headerUnicode(subject).encode('UTF-8')
map(M.delete, deletable)
M.logout()
S.logout()