aboutsummaryrefslogtreecommitdiff
path: root/jobs/EmailChecker.py
diff options
context:
space:
mode:
authorTom Ritter <tom@ritter.vg>2016-01-25 21:24:41 -0500
committerTom Ritter <tom@ritter.vg>2016-01-25 21:24:41 -0500
commit9b25f65ca655a567873c66c2b015884a3e013276 (patch)
tree242b994394ebbbcfdcc72eba6241f4ea03cf921c /jobs/EmailChecker.py
Initial commit of checker
Diffstat (limited to 'jobs/EmailChecker.py')
-rwxr-xr-xjobs/EmailChecker.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/jobs/EmailChecker.py b/jobs/EmailChecker.py
new file mode 100755
index 0000000..51992bf
--- /dev/null
+++ b/jobs/EmailChecker.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+import os
+import base64
+import datetime
+
+import imaplib
+
+import JobBase
+
+class EmailChecker(JobBase.JobBase):
+ def executeEvery(self):
+ return JobBase.JobFrequency.HOUR
+ def execute(self):
+ USER = self.config.get('email', 'user')
+ PASS = self.config.get('email', 'pass')
+
+ #Generate a random subject
+ subj = base64.b64encode(os.urandom(20))
+
+ if not self.sendEmail(subj, "", USER):
+ return False
+
+ M = imaplib.IMAP4_SSL(self.config.get('email', 'imapserver'))
+ M.login(USER, PASS)
+
+ #If we have set up a filter to auto-delete messages from ourself
+ if self.config.get('email', 'ideletesentmessagesautomatically'):
+ M.select("[Gmail]/Trash")
+
+ criteria = '(FROM "'+USER+'" SINCE "'+datetime.date.today().strftime("%d-%b-%Y")+'")'
+ typ, data = M.search(None, criteria)
+
+ foundSubject = False
+ for num in data[0].split():
+ typ, data = M.fetch(num, '(BODY.PEEK[HEADER.FIELDS (Subject)])')
+ if subj in data[0][1]:
+ foundSubject = True
+ M.close()
+ M.logout()
+ if not foundSubject:
+ #This may not work, but try anyway
+ self.sendEmail("Email Fetch Failure", "Body")
+ return False
+ else:
+ return True \ No newline at end of file