From c431abd917c6464a503b1942da3a6a3028196b85 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Wed, 13 Jan 2021 11:03:30 +0100 Subject: [PATCH] take into account alias.cannot_be_disabled in should_disable --- app/email_utils.py | 5 +++++ email_handler.py | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/email_utils.py b/app/email_utils.py index 03cdcad2..24a890d8 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -922,6 +922,11 @@ def normalize_reply_email(reply_email: str) -> str: def should_disable(alias: Alias) -> bool: """Disable an alias if it has more than 5 bounces in the last 24h""" + # Bypass the bounce rule + if alias.cannot_be_disabled: + LOG.warning("%s cannot be disabled", alias) + return False + yesterday = arrow.now().shift(days=-1) nb_bounced_last_24h = ( db.session.query(EmailLog) diff --git a/email_handler.py b/email_handler.py index cbe0a8e5..52438fb9 100644 --- a/email_handler.py +++ b/email_handler.py @@ -1325,10 +1325,6 @@ def handle_bounce_forward_phase(msg: Message, email_log: EmailLog): refused_email_url = f"{URL}/dashboard/refused_email?highlight_id={email_log.id}" - nb_bounced = EmailLog.filter_by(contact_id=contact.id, bounced=True).count() - if nb_bounced >= 2 and alias.cannot_be_disabled: - LOG.warning("%s cannot be disabled", alias) - # inform user of this bounce if not should_disable(alias): LOG.d(