From 6993721ae26381bf01d18ebb30c3af587c7cd3ab Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sun, 4 Oct 2020 12:49:27 +0200 Subject: [PATCH] disable email forwards/sending if user is disabled --- email_handler.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/email_handler.py b/email_handler.py index b1d68f39..ea5f6553 100644 --- a/email_handler.py +++ b/email_handler.py @@ -453,6 +453,12 @@ def handle_forward(envelope, msg: Message, rcpt_to: str) -> List[Tuple[bool, str LOG.d("alias %s cannot be created on-the-fly, return 550", address) return [(False, "550 SL E3 Email not exist")] + if alias.user.disabled: + LOG.exception( + "User %s disabled, disable forwarding emails for %s", alias.user, alias + ) + return [(False, "550 SL E20 Account disabled")] + mail_from = envelope.mail_from for mb in alias.mailboxes: # email send from a mailbox to alias @@ -713,6 +719,15 @@ def handle_reply(envelope, msg: Message, rcpt_to: str) -> (bool, str): user = alias.user mail_from = envelope.mail_from + if user.disabled: + LOG.exception( + "User %s disabled, disable sending emails from %s to %s", + user, + alias, + contact, + ) + return [(False, "550 SL E20 Account disabled")] + # bounce email initiated by Postfix # can happen in case emails cannot be delivered to user-email # in this case Postfix will try to send a bounce report to original sender, which is