Explorar o código

Create alias on-the-fly if the corresponding custom domain allows catch-all

Son NK %!s(int64=5) %!d(string=hai) anos
pai
achega
f08ca682c0
Modificáronse 1 ficheiros con 16 adicións e 1 borrados
  1. 16 1
      email_handler.py

+ 16 - 1
email_handler.py

@@ -44,6 +44,7 @@ from app.email_utils import (
     get_email_part,
     send_email,
     add_dkim_signature,
+    get_email_domain_part,
 )
 from app.extensions import db
 from app.log import LOG
@@ -108,7 +109,21 @@ class MailHandler:
         gen_email = GenEmail.get_by(email=alias)
         if not gen_email:
             LOG.d("alias %s not exist")
-            return "510 Email not exist"
+
+            # check if alias is custom-domain alias and if the custom-domain has catch-all enabled
+            alias_domain = get_email_domain_part(alias)
+            custom_domain = CustomDomain.get_by(domain=alias_domain)
+            if custom_domain and custom_domain.catch_all:
+                LOG.d("create alias %s for domain %s", alias, custom_domain)
+
+                gen_email = GenEmail.create(
+                    email=alias,
+                    user_id=custom_domain.user_id,
+                    custom_domain_id=custom_domain.id,
+                )
+                db.session.commit()
+            else:
+                return "510 Email not exist"
 
         user_email = gen_email.user.email