Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ def read_webhook_enabled_user_ids() -> Optional[List[int]]:
# It defaults to the regular DB_URI in case it's needed
EVENT_LISTENER_DB_URI = os.environ.get("EVENT_LISTENER_DB_URI", DB_URI)

MAX_BOUNCES_1D = int(os.environ.get("MAX_BOUNCES_1D", 12))
MAX_BOUNCES_1W = int(os.environ.get("MAX_BOUNCES_1W", 10))


def read_partner_dict(var: str) -> dict[int, str]:
partner_value = get_env_dict(var)
Expand Down
12 changes: 6 additions & 6 deletions app/email_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ class EmailCannotBeUsedReason(enum.Enum):


def email_can_be_used_as_mailbox_with_reason(
email_address: str
email_address: str,
) -> Optional[EmailCannotBeUsedReason]:
try:
domain = validate_email(
Expand Down Expand Up @@ -1229,11 +1229,11 @@ def should_disable(alias: Alias) -> (bool, str):
.count()
)
# if more than 12 bounces in 24h -> disable alias
if nb_bounced_last_24h > 12:
return True, "+12 bounces in the last 24h"
if nb_bounced_last_24h > config.MAX_BOUNCES_1D:
return True, f"More than {config.MAX_BOUNCES_1D} bounces in the last 24h"

# if more than 5 bounces but has +10 bounces last week -> disable alias
elif nb_bounced_last_24h > 5:
elif nb_bounced_last_24h > 1:
one_week_ago = arrow.now().shift(days=-7)
nb_bounced_7d_1d = (
Session.query(EmailLog)
Expand All @@ -1246,10 +1246,10 @@ def should_disable(alias: Alias) -> (bool, str):
.filter(EmailLog.alias_id == alias.id)
.count()
)
if nb_bounced_7d_1d > 10:
if nb_bounced_7d_1d > config.MAX_BOUNCES_1W:
return (
True,
"+5 bounces in the last 24h and +10 bounces in the last 7 days",
f"More than {config.MAX_BOUNCES_1W} bounces in the last 7 days",
)
else:
# alias level
Expand Down
Loading