From 8079746e47f3d171a2e180f54223320f6253ec0d Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sun, 30 Aug 2020 19:22:21 +0200 Subject: [PATCH] handle case where alias mailbox is invalid --- email_handler.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/email_handler.py b/email_handler.py index 32b0d7f9..4e70f2c9 100644 --- a/email_handler.py +++ b/email_handler.py @@ -422,8 +422,9 @@ def handle_email_sent_to_ourself(alias, mailbox, msg: Message, user): async def handle_forward( envelope, smtp: SMTP, msg: Message, rcpt_to: str ) -> List[Tuple[bool, str]]: - """return whether an email has been delivered and - the smtp status ("250 Message accepted", "550 Non-existent email address", etc) + """return an array of SMTP status (is_success, smtp_status) + is_success indicates whether an email has been delivered and + smtp_status is the SMTP Status ("250 Message accepted", "550 Non-existent email address", etc) """ address = rcpt_to.lower().strip() # alias@SL @@ -459,6 +460,11 @@ async def handle_forward( ret = [] mailboxes = alias.mailboxes + + # no valid mailbox + if not mailboxes: + return [(False, "550 SL E16 invalid mailbox")] + # no need to create a copy of message if len(mailboxes) == 1: mailbox = mailboxes[0]