summaryrefslogtreecommitdiff
path: root/emailcanary/canary.py
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2015-10-25 19:42:14 -0700
committerJesse Morgan <jesse@jesterpm.net>2015-10-25 19:42:14 -0700
commit51129fda2179286143921db55a69b3f4dba03c0e (patch)
treef09690727e5000af8e9e7bd9359fe37c81210fcd /emailcanary/canary.py
parent5319d2f0f013a340cb0fdc396bbe4f0ae8df5142 (diff)
Adding Canary Check and Accounts
Adding the canary check method and tests for the Canary class. Adding accounts to CanaryDB.
Diffstat (limited to 'emailcanary/canary.py')
-rw-r--r--emailcanary/canary.py47
1 files changed, 30 insertions, 17 deletions
diff --git a/emailcanary/canary.py b/emailcanary/canary.py
index d07e2e9..49972db 100644
--- a/emailcanary/canary.py
+++ b/emailcanary/canary.py
@@ -1,5 +1,5 @@
import uuid, datetime, time
-import email
+import email, emailutils
import re
class Canary:
@@ -8,26 +8,39 @@ class Canary:
self.smtp = smtp
self.fromaddress = fromaddress
- def chirp(self, list, expectedreceipients):
- uuid = uuid.uuid4()
+ def chirp(self, listAddress):
+ chirpUUID = str(uuid.uuid4())
now = datetime.datetime.now()
- self.send(list, now, uuid)
- for dest in expectedreceipients:
- self.db.ping(dest, now, uuid)
-
- def echo(self, receipient, msg):
- uuid = re.match('Canary Email (.+)', msg['Subject']).group(1)
- now = datetime.datetime.now()
-
- self.db.pong(receipient, now, uuid)
-
-
- def send(self, dest, date, uuid):
+ self.send(listAddress, now, chirpUUID)
+ for dest in self.db.get_recipients_for_list(listAddress):
+ self.db.ping(dest, now, chirpUUID)
+
+ def check(self, listAddress):
+ for (listAddress, address, imapserver, password) in self.db.get_accounts(listAddress):
+ mail = emailutils.get_imap(imapserver, address, password)
+ these_subjects = []
+ for uid in emailutils.get_mail_uids(mail):
+ message = emailutils.get_message(mail, uid)
+ if self.processMessage(address, message):
+ emailutils.delete_message(mail, uid)
+ emailutils.close(mail)
+
+ def processMessage(self, receipient, msg):
+ match = re.match('Canary Email (.+)', msg['Subject'])
+ if match:
+ chirpUUID = match.group(1)
+ now = datetime.datetime.now()
+ self.db.pong(receipient, now, chirpUUID)
+ return True
+ return False
+
+
+ def send(self, dest, date, chirpUUID):
msg = email.message.Message()
msg['From'] = self.fromaddress
msg['To'] = dest
- msg['Subject'] = "Canary Email " + str(uuid)
+ msg['Subject'] = "Canary Email " + chirpUUID
msg['Date'] = email.utils.formatdate(time.mktime(date.timetuple()))
- self.smtp.sendmail(self.fromaddress, dest, msg.as_string()) \ No newline at end of file
+ self.smtp.sendmail(self.fromaddress, dest, msg.as_string())