From 344f8e67d28bf7f9f6c3ab9c4fec9bd5f3bd823d Mon Sep 17 00:00:00 2001 From: Son Nguyen Kim Date: Fri, 17 Sep 2021 17:43:12 +0200 Subject: [PATCH] take into account custom_domain.auto_create_regex in try_auto_create_catch_all_domain() --- app/alias_utils.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/alias_utils.py b/app/alias_utils.py index 37464953..8b67402c 100644 --- a/app/alias_utils.py +++ b/app/alias_utils.py @@ -133,10 +133,22 @@ def try_auto_create_catch_all_domain(address: str) -> Optional[Alias]: return None # custom_domain exists - if not custom_domain.catch_all: + if not custom_domain.catch_all and not custom_domain.auto_create_regex: return None - # custom_domain has catch-all enabled + if custom_domain.auto_create_regex: + local = get_email_local_part(address) + regex = re.compile(custom_domain.auto_create_regex) + if not re.fullmatch(regex, local): + LOG.d( + "%s can't be auto created on %s as it fails regex %s", + address, + custom_domain, + custom_domain.auto_create_regex, + ) + return None + + # custom_domain has catch-all enabled or the address passes the regex domain_user: User = custom_domain.user if not domain_user.can_create_new_alias():