-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPyMail.py
executable file
·118 lines (85 loc) · 2.16 KB
/
PyMail.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python
import imaplib2
from threading import *
import email
import Text
import time
import os
import SubProcessor
M = None
idler = None
thread = None
process = SubProcessor.SubProcessor(os.getcwd())
phonenum = ""
sender = ""
emailPass = ""
recipient = ""
def check():
try:
process_inbox()
except:
Text.sendText("Error", sender, emailPass, phonenum)
def process_inbox():
rv, data = M.search(None, "(UNSEEN)")
if rv != 'OK':
print "No Messages Found!"
return
for num in data[0].split():
rv, data = M.fetch(num, '(RFC822)')
if rv != 'OK':
print "Error getting message ", num
return
msg = email.message_from_string(data[0][1])
msg = msg.as_string()
msgBody = msg[msg.index('<td>') + 4: msg.index('</td>')].strip()
M.store(num, '+FLAGS', '\\Deleted')
response = ""
if(not process.authorized):
response = process.authorize(phonenum, msgBody)
else:
response = process.run(msgBody)
if(response.strip() != ""):
Text.sendText(response, sender, emailPass, phonenum)
else:
Text.sendText(msgBody + " was successfully called.", sender, emailPass, phonenum)
M.expunge()
print "Leaving Box"
def dosync():
print "Got an event!"
check()
def idle():
while True:
if event.isSet():
return
def callback(args):
if not event.isSet():
needsync = True
event.set()
M.idle(callback=callback)
event.wait()
if needsync:
event.clear()
dosync()
config = open('config.txt', 'r')
sender = config.readline()
emailPass = config.readline()
phonenum = config.readline().strip()
Text.sendText("Send password.", sender, emailPass, phonenum)
M = imaplib2.IMAP4_SSL('imap.gmail.com')
M.login(sender, emailPass)
M.select("inbox")
check()
#init
thread = Thread(target=idle)
event = Event()
#start
thread.start()
time.sleep(60*60)
#stop
event.set()
#join
thread.join()
M.expunge()
M.close()
M.logout()
print "DONE!"