Browse Source

avoid forward email to invalid mailbox

Son NK 5 years ago
parent
commit
53e9281204
1 changed files with 12 additions and 1 deletions
  1. 12 1
      email_handler.py

+ 12 - 1
email_handler.py

@@ -31,7 +31,6 @@ It should contain the following info:
 
 
 """
 """
 import email
 import email
-import os
 import time
 import time
 import uuid
 import uuid
 from email import encoders
 from email import encoders
@@ -79,6 +78,7 @@ from app.email_utils import (
     get_orig_message_from_spamassassin_report,
     get_orig_message_from_spamassassin_report,
     parseaddr_unicode,
     parseaddr_unicode,
     send_email_with_rate_control,
     send_email_with_rate_control,
+    get_email_domain_part,
 )
 )
 from app.extensions import db
 from app.extensions import db
 from app.greylisting import greylisting_needed
 from app.greylisting import greylisting_needed
@@ -405,6 +405,17 @@ def forward_email_to_mailbox(
     user,
     user,
 ) -> (bool, str):
 ) -> (bool, str):
     LOG.d("Forward %s -> %s -> %s", contact, alias, mailbox)
     LOG.d("Forward %s -> %s -> %s", contact, alias, mailbox)
+
+    # sanity check: make sure mailbox is not actually an alias
+    if get_email_domain_part(alias.email) == get_email_domain_part(mailbox.email):
+        LOG.error(
+            "Mailbox has the same domain as alias. %s -> %s -> %s",
+            contact,
+            alias,
+            mailbox,
+        )
+        return False, "550 SL E14"
+
     is_spam, spam_status = get_spam_info(msg)
     is_spam, spam_status = get_spam_info(msg)
     if is_spam:
     if is_spam:
         LOG.warning("Email detected as spam. Alias: %s, from: %s", alias, contact)
         LOG.warning("Email detected as spam. Alias: %s, from: %s", alias, contact)