lessen alias automatic disable check

This commit is contained in:
Son 2022-03-07 15:50:58 +01:00
parent 99dc45e09a
commit 350f498b94
3 changed files with 7 additions and 8 deletions

View file

@ -1143,11 +1143,11 @@ def should_disable(alias: Alias) -> (bool, str):
) )
# if more than 12 bounces in 24h -> disable alias # if more than 12 bounces in 24h -> disable alias
if nb_bounced_last_24h > 12: if nb_bounced_last_24h > 12:
return True, "more than 12 bounces in the last 24h" return True, "+12 bounces in the last 24h"
# if more than 5 bounces but has bounces last week -> disable alias # if more than 5 bounces but has +10 bounces last week -> disable alias
elif nb_bounced_last_24h > 5: elif nb_bounced_last_24h > 5:
one_week_ago = arrow.now().shift(days=-8) one_week_ago = arrow.now().shift(days=-7)
nb_bounced_7d_1d = ( nb_bounced_7d_1d = (
Session.query(EmailLog) Session.query(EmailLog)
.filter( .filter(
@ -1159,10 +1159,10 @@ def should_disable(alias: Alias) -> (bool, str):
.filter(EmailLog.alias_id == alias.id) .filter(EmailLog.alias_id == alias.id)
.count() .count()
) )
if nb_bounced_7d_1d > 1: if nb_bounced_7d_1d > 10:
return ( return (
True, True,
"more than 5 bounces in the last 24h and more than 1 bounces in the last 7 days", "+5 bounces in the last 24h and +10 bounces in the last 7 days",
) )
else: else:
# alias level # alias level

View file

@ -1395,7 +1395,6 @@ def handle_bounce_forward_phase(msg: Message, email_log: EmailLog):
refused_email_url = f"{URL}/dashboard/refused_email?highlight_id={email_log.id}" refused_email_url = f"{URL}/dashboard/refused_email?highlight_id={email_log.id}"
# inform user of this bounce
alias_will_be_disabled, reason = should_disable(alias) alias_will_be_disabled, reason = should_disable(alias)
if alias_will_be_disabled: if alias_will_be_disabled:
LOG.w( LOG.w(

View file

@ -721,8 +721,8 @@ def test_should_disable_bounce_consecutive_days(flask_client):
) )
assert not should_disable(alias)[0] assert not should_disable(alias)[0]
# create 2 bounces in the last 7 days: alias should be disabled # create +10 bounces in the last 7 days: alias should be disabled
for _ in range(2): for _ in range(11):
EmailLog.create( EmailLog.create(
user_id=user.id, user_id=user.id,
contact_id=contact.id, contact_id=contact.id,