started mail rewrite
This commit is contained in:
parent
c71bc8574a
commit
ba6e13a2be
|
@ -9,12 +9,13 @@ import email
|
|||
import imaplib
|
||||
import report
|
||||
from user import User
|
||||
from bot import Bot
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Mailbot(object):
|
||||
class Mailbot(Bot):
|
||||
"""
|
||||
Bot which sends Mails if mentioned via twitter/mastodon, and tells
|
||||
other bots that it received mails.
|
||||
|
@ -26,15 +27,8 @@ class Mailbot(object):
|
|||
bots.
|
||||
|
||||
"""
|
||||
self.user = User(uid)
|
||||
|
||||
try:
|
||||
self.last_mail = self.user.get_seen_mail()
|
||||
except TypeError:
|
||||
self.last_mail = 0
|
||||
|
||||
try:
|
||||
self.mailinglist = self.user.get_mail()
|
||||
self.mailinglist = self.user.get_mailinglist()
|
||||
except TypeError:
|
||||
self.mailinglist = None
|
||||
|
||||
|
@ -67,11 +61,12 @@ class Mailbot(object):
|
|||
"""
|
||||
pass
|
||||
|
||||
def crawl(self):
|
||||
def crawl(self, user):
|
||||
"""
|
||||
crawl for new mails.
|
||||
:return: msgs: (list of report.Report objects)
|
||||
"""
|
||||
mailinglist = user.get_mailinglist()
|
||||
try:
|
||||
rv, data = self.mailbox.select("Inbox")
|
||||
except imaplib.IMAP4.abort:
|
||||
|
@ -90,7 +85,7 @@ class Mailbot(object):
|
|||
return msgs
|
||||
msg = email.message_from_bytes(data[0][1])
|
||||
|
||||
if not self.user.get_mail() in msg['From']:
|
||||
if not self.user.get_mailinglist() in msg['From']:
|
||||
# get a comparable date out of the email
|
||||
date_tuple = email.utils.parsedate_tz(msg['Date'])
|
||||
date_tuple = datetime.datetime.fromtimestamp(
|
||||
|
|
10
db.py
10
db.py
|
@ -97,7 +97,7 @@ class DB(object):
|
|||
tweet_id TEXT,
|
||||
FOREIGN KEY(user_id) REFERENCES user(id)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS mail (
|
||||
CREATE TABLE IF NOT EXISTS mailinglist (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
user_id INTEGER,
|
||||
email TEXT,
|
||||
|
@ -106,14 +106,6 @@ class DB(object):
|
|||
FOREIGN KEY(twitter_accounts_id)
|
||||
REFERENCES twitter_accounts(id)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS seen_mails (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
user_id INTEGER,
|
||||
mail_id INTEGER,
|
||||
mail_date INTEGER,
|
||||
FOREIGN KEY(user_id) REFERENCES user(id)
|
||||
FOREIGN KEY(mail_id) REFERENCES mail(id)
|
||||
);
|
||||
''')
|
||||
|
||||
def user_token(self, email, password):
|
||||
|
|
5
user.py
5
user.py
|
@ -108,8 +108,9 @@ class User(object):
|
|||
db.execute("UPDATE seen_tweets SET tweet_id = ? WHERE user_id = ?;",
|
||||
(tweet_id, self.uid))
|
||||
|
||||
def get_mail(self):
|
||||
db.execute("SELECT email FROM mail WHERE user_id = ?;", (self.uid, ))
|
||||
def get_mailinglist(self):
|
||||
db.execute("SELECT email FROM mailinglist WHERE user_id = ? AND active = 1;", (self.uid, ))
|
||||
return db.cur.fetchone()[0]
|
||||
|
||||
def get_seen_mail(self):
|
||||
db.execute("SELECT mail_date FROM seen_mails WHERE user_id = ?;", (self.uid, ))
|
||||
|
|
Loading…
Reference in a new issue