Add BOUNCE_PREFIX, BOUNCE_SUFFIX config

This commit is contained in:
Son NK 2021-01-11 14:34:51 +01:00
parent 45ac548e2b
commit c83b146f14
4 changed files with 23 additions and 1 deletions

View File

@ -54,6 +54,12 @@ EMAIL_DOMAIN = os.environ["EMAIL_DOMAIN"].lower()
SUPPORT_EMAIL = os.environ["SUPPORT_EMAIL"]
SUPPORT_NAME = os.environ.get("SUPPORT_NAME", "Son from SimpleLogin")
ADMIN_EMAIL = os.environ.get("ADMIN_EMAIL")
# VERP: mail_from set to BOUNCE_PREFIX + email_log.id + BOUNCE_SUFFIX
BOUNCE_PREFIX = os.environ.get("BOUNCE_PREFIX") or "bounce+"
BOUNCE_SUFFIX = os.environ.get("BOUNCE_SUFFIX") or f"+{EMAIL_DOMAIN}"
BOUNCE_EMAIL = BOUNCE_PREFIX + "{}" + BOUNCE_SUFFIX
try:
MAX_NB_EMAIL_FREE_PLAN = int(os.environ["MAX_NB_EMAIL_FREE_PLAN"])
except Exception:

View File

@ -937,3 +937,7 @@ def should_disable(alias: Alias) -> bool:
if nb_bounced_last_24h > 5:
return True
return False
def parse_email_log_id_from_bounce(email_address: str) -> int:
return int(email_address[email_address.find("+") : email_address.rfind("+")])

View File

@ -39,6 +39,12 @@ SUPPORT_NAME=Son from SimpleLogin
# in case sender is different than SUPPORT_EMAIL
SENDER=sender@sl.local
# To use VERP
# prefix must end with + and suffix must start with +
# BOUNCE_PREFIX = "bounces+"
# BOUNCE_SUFFIX = "+@sl.local"
# all emails sent to sender are stored in this folder
SENDER_DIR=/tmp

View File

@ -1,7 +1,7 @@
import email
from email.message import EmailMessage
from app.config import MAX_ALERT_24H, EMAIL_DOMAIN
from app.config import MAX_ALERT_24H, EMAIL_DOMAIN, BOUNCE_EMAIL
from app.email_utils import (
get_email_domain_part,
can_create_directory_for_address,
@ -24,6 +24,7 @@ from app.email_utils import (
replace,
should_disable,
decode_text,
parse_email_log_id_from_bounce,
)
from app.extensions import db
from app.models import User, CustomDomain, Alias, Contact, EmailLog
@ -615,3 +616,8 @@ def test_should_disable(flask_client):
alias2 = Alias.create_new_random(user)
db.session.commit()
assert not should_disable(alias2)
def test_parse_email_log_id_from_bounce():
assert parse_email_log_id_from_bounce("bounces+1234+@local") == 1234
assert parse_email_log_id_from_bounce(BOUNCE_EMAIL.format(1234)) == 1234