summaryrefslogtreecommitdiff
path: root/emailcanary/canarydb.py
diff options
context:
space:
mode:
Diffstat (limited to 'emailcanary/canarydb.py')
-rw-r--r--emailcanary/canarydb.py37
1 files changed, 35 insertions, 2 deletions
diff --git a/emailcanary/canarydb.py b/emailcanary/canarydb.py
index 112b8f5..59a2ea2 100644
--- a/emailcanary/canarydb.py
+++ b/emailcanary/canarydb.py
@@ -8,10 +8,45 @@ class CanaryDB:
# Create Tables if necessary
cursor = self.conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS pings (address, uuid, timesent timestamp, timereceived timestamp)")
+ cursor.execute("CREATE TABLE IF NOT EXISTS accounts (list, address, imapserver, password)")
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 (?, ?, ?, ?)", \
+ (listAddress, address, imapserver, password))
+ self.conn.commit()
+
+ def remove_account(self, address):
+ cursor = self.conn.cursor()
+ cursor.execute("DELETE FROM accounts WHERE address=?", (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,));
+ else:
+ cursor.execute("SELECT list, address, imapserver, password 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))
+ return results
+
+ def get_recipients_for_list(self, listAddress):
+ cursor = self.conn.cursor()
+ cursor.execute("SELECT address FROM accounts WHERE list=?", (listAddress,));
+ results = list()
+ for row in cursor:
+ results.append(row[0])
+ return results
+
def ping(self, address, time, uuid):
cursor = self.conn.cursor()
cursor.execute("INSERT INTO pings (address, timesent, uuid) VALUES (?, ?, ?)", \
@@ -29,7 +64,6 @@ class CanaryDB:
Each tupl contains (uuid, address, time since send)'''
cursor = self.conn.cursor()
cursor.execute("SELECT uuid, address, timesent FROM pings WHERE timereceived IS NULL");
-
now = datetime.now()
results = list()
for row in cursor:
@@ -37,5 +71,4 @@ class CanaryDB:
address = row[1]
delta = now - row[2]
results.append((uuid, address, delta))
-
return results