mailbot: keep mbox open
This commit is contained in:
parent
f4edfba532
commit
f62357b828
|
@ -15,19 +15,28 @@ logger = logging.getLogger("main")
|
|||
|
||||
class Mailbot(Bot):
|
||||
|
||||
mails = None
|
||||
|
||||
# returns a list of Report objects
|
||||
def crawl(self, user):
|
||||
reports = []
|
||||
# todo: adjust to actual mailbox
|
||||
if mails is None:
|
||||
try:
|
||||
mails = mailbox.mbox("/var/mail/" + config['mail']['mbox_user'])
|
||||
except FileNotFoundError:
|
||||
logger.error("No mbox file found.")
|
||||
mails = None
|
||||
return reports
|
||||
try:
|
||||
mails = mailbox.mbox("/var/mail/" + config['mail']['mbox_user'])
|
||||
except FileNotFoundError:
|
||||
logger.error("No mbox file found.")
|
||||
return reports
|
||||
for msg in mails:
|
||||
if get_date_from_header(msg['Date']) > user.get_seen_mail():
|
||||
if user.get_city().lower() in msg['To'].lower():
|
||||
reports.append(make_report(msg, user))
|
||||
mails.lock()
|
||||
for msg in mails:
|
||||
if get_date_from_header(msg['Date']) > user.get_seen_mail():
|
||||
if user.get_city().lower() in msg['To'].lower():
|
||||
reports.append(make_report(msg, user))
|
||||
mails.unlock()
|
||||
except ExternalClashError:
|
||||
logger.warning("Unable to lock mbox")
|
||||
return reports
|
||||
|
||||
# post/boost Report object
|
||||
|
|
Loading…
Reference in a new issue