From 2b2512e775ea0782bf9220927a6fb3ee8e13e1cd Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Fri, 21 Aug 2020 10:41:50 +0200 Subject: [PATCH] no need to create a copy of message when there's only 1 mailbox --- email_handler.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/email_handler.py b/email_handler.py index 82340049..ba2e65b9 100644 --- a/email_handler.py +++ b/email_handler.py @@ -397,12 +397,23 @@ async def handle_forward( user = alias.user ret = [] - for mailbox in alias.mailboxes: + mailboxes = alias.mailboxes + # no need to create a copy of message + if len(mailboxes) == 1: + mailbox = mailboxes[0] ret.append( await forward_email_to_mailbox( - alias, copy(msg), email_log, contact, envelope, smtp, mailbox, user + alias, msg, email_log, contact, envelope, smtp, mailbox, user ) ) + # create a copy of message for each forward + else: + for mailbox in mailboxes: + ret.append( + await forward_email_to_mailbox( + alias, copy(msg), email_log, contact, envelope, smtp, mailbox, user + ) + ) return ret