diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2015-11-24 11:12:49 -0800 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2015-11-24 11:12:49 -0800 |
commit | 6259efbc44be3e21e42b29246941cd300e79200f (patch) | |
tree | 67532f37aeadc45e959fffd1d05ab45ecd72e114 /emailcanary/canary.py | |
parent | 51129fda2179286143921db55a69b3f4dba03c0e (diff) |
Adding emailcanary script
Adding the main launch script.
Adding the listAddress to the pings table.
Fixing the Makefile
Diffstat (limited to 'emailcanary/canary.py')
-rw-r--r-- | emailcanary/canary.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/emailcanary/canary.py b/emailcanary/canary.py index 49972db..e020349 100644 --- a/emailcanary/canary.py +++ b/emailcanary/canary.py @@ -1,5 +1,5 @@ import uuid, datetime, time -import email, emailutils +import email.message, emailutils import re class Canary: @@ -12,12 +12,20 @@ class Canary: chirpUUID = str(uuid.uuid4()) now = datetime.datetime.now() + receipients = self.db.get_recipients_for_list(listAddress) + if len(receipients) == 0: + raise Exception("No receipients for listAddress '%s'", (listAddress,)) + self.send(listAddress, now, chirpUUID) - for dest in self.db.get_recipients_for_list(listAddress): - self.db.ping(dest, now, chirpUUID) + for dest in receipients: + self.db.ping(listAddress, dest, now, chirpUUID) def check(self, listAddress): - for (listAddress, address, imapserver, password) in self.db.get_accounts(listAddress): + '''Check for messages from listAddress and return a list of missing chirps''' + accounts = self.db.get_accounts(listAddress) + if len(accounts) == 0: + raise Exception("No receipients for listAddress '%s'", (listAddress,)) + for (listAddress, address, imapserver, password) in accounts: mail = emailutils.get_imap(imapserver, address, password) these_subjects = [] for uid in emailutils.get_mail_uids(mail): @@ -25,6 +33,7 @@ class Canary: if self.processMessage(address, message): emailutils.delete_message(mail, uid) emailutils.close(mail) + return self.db.get_missing_pongs(listAddress) def processMessage(self, receipient, msg): match = re.match('Canary Email (.+)', msg['Subject']) @@ -35,7 +44,6 @@ class Canary: return True return False - def send(self, dest, date, chirpUUID): msg = email.message.Message() msg['From'] = self.fromaddress |