take into account a mailbox can be deleted in the meantime

This commit is contained in:
Son NK 2020-09-25 10:06:50 +02:00
parent 53f66d0f3c
commit bb6a5bf0b3
1 changed files with 12 additions and 1 deletions

13
cron.py
View File

@ -288,9 +288,20 @@ def sanity_check():
Different sanity checks
- detect if there's mailbox that's using a invalid domain
"""
for mailbox in Mailbox.filter_by(verified=True).all():
mailbox_ids = db.session.query(Mailbox.id).filter(Mailbox.verified == True).all()
mailbox_ids = [e[0] for e in mailbox_ids]
# iterate over id instead of mailbox directly
# as a mailbox can be deleted during the sleep time
for mailbox_id in mailbox_ids:
mailbox = Mailbox.get(mailbox_id)
# a mailbox has been deleted
if not mailbox:
continue
# hack to not query DNS too often
sleep(1)
if not email_domain_can_be_used_as_mailbox(mailbox.email):
mailbox.nb_failed_checks += 1
nb_email_log = nb_email_log_for_mailbox(mailbox)