-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbare-bones.py
More file actions
187 lines (168 loc) · 5.56 KB
/
bare-bones.py
File metadata and controls
187 lines (168 loc) · 5.56 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python
#just a comment :P
import imaplib
import pyglet
import getpass
from email.parser import HeaderParser
import os
import socket
import time
import pickle
def check_for_new_mail():
new_status = open('lastmail.txt','r')
stat = new_status.read()
new_status.close()
inbox = conn.select('Inbox')
data = conn.fetch(int(inbox[1][0]),'(BODY[HEADER])')
raw_header = data[1][0][1]
parser = HeaderParser()
header = parser.parsestr(raw_header)
if stat == '':
update_new_stat = open('lastmail.txt','w')
pickle.dump(header['From'],update_new_stat) #Sender's name and mail-id
pickle.dump(header['Subject'],update_new_stat) #Subject of mail
pickle.dump(header['Received'].split()[7:10],update_new_stat) #Received Date ['day','month','year']
pickle.dump(header['Received'].split()[10],update_new_stat) #Received Time
update_new_stat.close()
last_sender = header['From']
last_subject = header['Subject']
last_date = header['Received'].split()[7:10]
last_time = header['Received'].split()[10]
else :
last_mail = open('lastmail.txt','r')
last_sender = pickle.load(last_mail)
last_subject = pickle.load(last_mail)
last_date = pickle.load(last_mail)
last_time = pickle.load(last_mail)
current_sender = header['From']
current_subject = header['Subject']
current_date = header['Received'].split()[7:10]
current_time = header['Received'].split()[10]
val1 = current_sender == last_sender
val2 = current_subject == last_subject
val3 = current_date == last_date
val4 = current_time == last_time
if current_sender == last_sender :
if current_subject == last_subject:
if current_date ==last_date:
if current_time == last_time:
pass
else:
preamp(header)
else:
preamp(header)
else:
preamp(header)
else :
preamp(header)
def preamp(header):
update_new_stat = open('lastmail.txt','w')
pickle.dump(header['From'],update_new_stat) #Sender's name and mail-id
pickle.dump(header['Subject'],update_new_stat) #Subject of mail
pickle.dump(header['Received'].split()[7:10],update_new_stat) #Received Date ['day','month','year']
pickle.dump(header['Received'].split()[10],update_new_stat) #Received Time
update_new_stat.close()
soundjob1(header['From'],header['Subject'],header['Received'].split()[7:10],header['Received'].split()[10])
def soundjob1(key1,key2,date,time):
p1_file = open('priority1.txt','r')
p2_file = open('priority2.txt','r')
p3_file = open('priority3.txt','r')
p4_file = open('priority4.txt','r')
p5_file = open('priority5.txt','r')
keys={'p1':p1_file.read().split(),'p2':p2_file.read().split(),'p3':p3_file.read().split(),'p4':p4_file.read().split(),'p5':p5_file.read().split()}
flag = 0
for ele in keys['p1']:
if ele in key1 or ele in key2:
flag =1
#print 'calling p1 soundjob()'
soundjob2('priority1.wav')
print "You have a priority1 message"
print "Sender :",key1
print "Subject:",key2
print "Date :",'%s-%s-%s'%(date[0],date[1],date[2])
print "Time :",time
print "______________________________________________"
break
if flag != 1:
for ele in keys['p2']:
if ele in key1 or ele in key2:
soundjob2('priority2.wav')
print "You have a priority2 message"
print "Sender :",key1
print "Subject:",key2
print "Date :",'%s-%s-%s'%(date[0],date[1],date[2])
print "Time :",time
print "______________________________________________"
break
if flag != 1:
for ele in keys['p3']:
if ele in key1 or ele in key2:
soundjob2('priority3.wav')
print "You have a priority3 message"
print "Sender :",key1
print "Subject:",key2
print "Date :",'%s-%s-%s'%(date[0],date[1],date[2])
print "Time :",time
print "______________________________________________"
break
if flag != 1:
for ele in keys['p4']:
if ele in key1 or ele in key2:
soundjob2('priority4.wav')
print "You have a priority4 message"
print "Sender :",key1
print "Subject:",key2
print "Date :",'%s-%s-%s'%(date[0],date[1],date[2])
print "Time :",time
print "______________________________________________"
break
if flag != 1:
for ele in keys['p5']:
if ele in key1 or ele in key2:
soundjob2('priority5.wav')
print "You have a priority5 message"
print "Sender :",key1
print "Subject:",key2
print "Date :",'%s-%s-%s'%(date[0],date[1],date[2])
print "Time :",time
print "______________________________________________"
break
def soundjob2(path):
sound = pyglet.media.load(path)
dumpster = sound.play()
pyglet.clock.schedule_once(exiter,sound.duration)
pyglet.app.run()
def exiter(dt):
pyglet.app.exit()
print 'Welcome to Prioritised Mail Alert!'
print 'Estabilishing connection with the gmail server...'
try:
conn = imaplib.IMAP4_SSL('imap.gmail.com')
except socket.gaierror:
print "Make sure you are connected to the internet and please try again!"
exit()
def check_for_logout():
stat_file= open('logout.txt','r')
stat = stat_file.read()
stat_file.close()
if 'LOGOUT' in stat or 'logout' in stat or 'Logout' in stat:
conn.logout()
cleaner = open('logout.txt','w')
cleaner.close()
print "Successfully Signed Out!"
exit()
def login_process():
username = raw_input("Enter username:")
password = getpass.getpass()
try:
conn.login(username,password)
except imaplib.IMAP4_SSL.error:
print "Wrong Credentials!\nPlease enter USERNAME AND PASSWORD again."
login_process()
login_process()
os.system('clear')
while True:
check_for_new_mail()
#print "looping"
time.sleep(5) #ten second gap between each execution of check_for_new_mail()
check_for_logout()