瀏覽代碼

special handling for case when alias can't be disabled

Son NK 5 年之前
父節點
當前提交
9cf807f7bd
共有 1 個文件被更改,包括 11 次插入11 次删除
  1. 11 11
      email_handler.py

+ 11 - 11
email_handler.py

@@ -976,8 +976,11 @@ def handle_bounce(contact: Contact, alias: Alias, msg: Message, user: User):
     )
 
     nb_bounced = EmailLog.filter_by(contact_id=contact.id, bounced=True).count()
+    if nb_bounced >= 2 and alias.cannot_be_disabled:
+        LOG.warning("%s cannot be disabled", alias)
+
     # inform user if this is the first bounced email
-    if nb_bounced == 1:
+    if nb_bounced == 1 or (nb_bounced >= 2 and alias.cannot_be_disabled):
         LOG.d(
             "Inform user %s about bounced email sent by %s to alias %s",
             user,
@@ -1010,16 +1013,13 @@ def handle_bounce(contact: Contact, alias: Alias, msg: Message, user: User):
         )
     # disable the alias the second time email is bounced
     elif nb_bounced >= 2:
-        if alias.cannot_be_disabled:
-            LOG.warning("%s cannot be disabled", alias)
-        else:
-            LOG.d(
-                "Bounce happens again with alias %s from %s. Disable alias now ",
-                alias,
-                contact.website_email,
-            )
-            alias.enabled = False
-            db.session.commit()
+        LOG.d(
+            "Bounce happens again with alias %s from %s. Disable alias now ",
+            alias,
+            contact.website_email,
+        )
+        alias.enabled = False
+        db.session.commit()
 
         send_email_with_rate_control(
             user,