This repository has been archived by the owner on May 29, 2023. It is now read-only.
forked from codedance/Retaliation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailutil.py
executable file
·92 lines (67 loc) · 2.25 KB
/
emailutil.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
#!/usr/bin/python
import sys
import os
import imaplib
import email
import time
import json
import re
from bs4 import BeautifulSoup
import retaliation
coordMap = {
}
def getEmail():
body = ""
try:
mail = imaplib.IMAP4('anthonyrhowell.net')
except:
return body
mail.login('retaliation', 'savvis')
mail.select("inbox") # connect to inbox.
result, data = mail.search(None, "ALL")
ids = data[0] # data is a list.
id_list = ids.split() # ids is a space separated string
if(len(id_list) > 0):
latest_email_id = id_list[-1] # get the latest
result, data = mail.fetch(latest_email_id, "(RFC822)") # fetch the email body (RFC822) for the given ID
mail.store(latest_email_id, '+FLAGS', '\\Deleted')
mail.expunge()
raw_email = data[0][1]
msg = email.message_from_string(raw_email)
if msg.is_multipart():
for payload in msg.get_payload():
# if payload.is_multipart(): ...
rawBody = payload.get_payload()
else:
rawBody = msg.get_payload()
body = BeautifulSoup(rawBody).get_text()
mail.logout()
return body
def main(args):
while(True):
body = getEmail()
if(body != ""):
coordsFile = open(os.path.dirname(__file__) + "/coords.json")
coordMap = json.loads(coordsFile.read())
coordsFile.close()
culprit = parseEmail(body)
if coordMap[culprit] is not None:
print "firing on " + culprit
coordinates = coordMap[culprit]
argStr = "led 1 " + coordMap[culprit] + " fire 1 led 0 reset"
args = argStr.split()
args.insert(0, "retaliation.py")
try:
print "retaliation.py " + argStr
retaliation.main(args)
except:
print "Something went wrong in retaliation.py"
time.sleep(5)
def parseEmail(emailBody):
culprit = re.findall(re.compile("\[\w*\]"), emailBody)
if len(culprit) != 0:
culprit = culprit[0]
culprit = culprit.replace("[", "").replace("]", "")
return culprit
if __name__ == '__main__':
main(sys.argv)