From 6e42e536dbabda5dffcd9a523897420434bf5731 Mon Sep 17 00:00:00 2001 From: Son Nguyen Kim Date: Fri, 10 Sep 2021 18:15:22 +0200 Subject: [PATCH] ignore email sent from a mailbox to its alias if user.ignore_loop_email --- app/email/status.py | 2 ++ email_handler.py | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/email/status.py b/app/email/status.py index 28e95ae7..5e2b7b59 100644 --- a/app/email/status.py +++ b/app/email/status.py @@ -13,6 +13,8 @@ E207 = "250 SL E207 No bounce report" E208 = "250 SL E208 Hotmail complaint handled" +E209 = "250 SL E209 Email Loop" + # 4** errors # E401 = "421 SL E401 Retry later" E402 = "421 SL E402 Encryption failed - Retry later" diff --git a/email_handler.py b/email_handler.py index e7f1dcbb..fa4bd926 100644 --- a/email_handler.py +++ b/email_handler.py @@ -574,13 +574,14 @@ def handle_forward(envelope, msg: Message, rcpt_to: str) -> List[Tuple[bool, str else: return [(False, status.E504)] - # mail_from = envelope.mail_from - # for mb in alias.mailboxes: - # # email send from a mailbox to alias - # if mb.email == mail_from: - # LOG.w("cycle email sent from %s to %s", mb, alias) - # handle_email_sent_to_ourself(alias, mb, msg, user) - # return [(True, "250 Message accepted for delivery")] + if user.ignore_loop_email: + mail_from = envelope.mail_from + for mb in alias.mailboxes: + # email send from a mailbox to its alias + if mb.email == mail_from: + LOG.w("cycle email sent from %s to %s", mb, alias) + handle_email_sent_to_ourself(alias, mb, msg, user) + return [(True, status.E209)] from_header = get_header_unicode(msg["From"]) LOG.d("Create or get contact for from_header:%s", from_header)