summaryrefslogtreecommitdiff
path: root/emailcanary
diff options
context:
space:
mode:
Diffstat (limited to 'emailcanary')
-rw-r--r--emailcanary/canary.py7
-rw-r--r--emailcanary/canarydb.py22
2 files changed, 20 insertions, 9 deletions
diff --git a/emailcanary/canary.py b/emailcanary/canary.py
index 93e9d42..2be8ccf 100644
--- a/emailcanary/canary.py
+++ b/emailcanary/canary.py
@@ -26,7 +26,8 @@ class Canary:
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:
+ result = []
+ for (listAddress, address, imapserver, password, mute) in accounts:
mail = emailutils.get_imap(imapserver, address, password)
these_subjects = []
for uid in emailutils.get_mail_uids(mail):
@@ -34,7 +35,9 @@ class Canary:
if message is not None and self.processMessage(address, message):
emailutils.delete_message(mail, uid)
emailutils.close(mail)
- return self.db.get_missing_pongs(listAddress)
+ if time.time() > mute:
+ result.extend(self.db.get_missing_pongs(listAddress, address))
+ return result
def processMessage(self, receipient, msg):
match = re.match('.*Canary Email (.+)', msg['Subject'])
diff --git a/emailcanary/canarydb.py b/emailcanary/canarydb.py
index 8bf944f..400fc6d 100644
--- a/emailcanary/canarydb.py
+++ b/emailcanary/canarydb.py
@@ -8,14 +8,14 @@ class CanaryDB:
# Create Tables if necessary
cursor = self.conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS pings (listAddress, address, uuid, timesent timestamp, timereceived timestamp)")
- cursor.execute("CREATE TABLE IF NOT EXISTS accounts (list, address, imapserver, password)")
+ cursor.execute("CREATE TABLE IF NOT EXISTS accounts (list, address, imapserver, password, mute)")
def close(self):
self.conn.close()
def add_account(self, listAddress, address, imapserver, password):
cursor = self.conn.cursor()
- cursor.execute("INSERT INTO accounts (list, address, imapserver, password) VALUES (?, ?, ?, ?)", \
+ cursor.execute("INSERT INTO accounts (list, address, imapserver, password, mute) VALUES (?, ?, ?, ?, 0)", \
(listAddress, address, imapserver, password))
self.conn.commit()
@@ -24,19 +24,25 @@ class CanaryDB:
cursor.execute("DELETE FROM accounts WHERE list=? AND address=?", (listAddress, address))
self.conn.commit()
+ def mute_account(self, listAddress, address, until):
+ cursor = self.conn.cursor()
+ cursor.execute("UPDATE accounts SET mute=? WHERE list=? AND address=?", (until, listAddress, address))
+ self.conn.commit()
+
def get_accounts(self, listAddress = None):
cursor = self.conn.cursor()
if listAddress:
- cursor.execute("SELECT list, address, imapserver, password FROM accounts WHERE list=?", (listAddress,));
+ cursor.execute("SELECT list, address, imapserver, password, mute FROM accounts WHERE list=?", (listAddress,));
else:
- cursor.execute("SELECT list, address, imapserver, password FROM accounts");
+ cursor.execute("SELECT list, address, imapserver, password, mute FROM accounts");
results = list()
for row in cursor:
listAddress = row[0]
address = row[1]
imapserver = row[2]
password = row[3]
- results.append((listAddress, address, imapserver, password))
+ mute = row[4]
+ results.append((listAddress, address, imapserver, password, mute))
return results
def get_recipients_for_list(self, listAddress):
@@ -59,11 +65,13 @@ class CanaryDB:
(time, address, uuid))
self.conn.commit()
- def get_missing_pongs(self, listAddress = None):
+ def get_missing_pongs(self, listAddress = None, address = None):
'''Return a list of tupls of missing pongs.
Each tupl contains (listAddress, uuid, address, time since send)'''
cursor = self.conn.cursor()
- if listAddress:
+ if listAddress and address:
+ cursor.execute("SELECT listAddress, uuid, address, timesent FROM pings WHERE timereceived IS NULL AND listAddress = ? AND address = ?", (listAddress, address,));
+ elif listAddress:
cursor.execute("SELECT listAddress, uuid, address, timesent FROM pings WHERE timereceived IS NULL AND listAddress = ?", (listAddress,));
else:
cursor.execute("SELECT listAddress, uuid, address, timesent FROM pings WHERE timereceived IS NULL");