From 70de5d05f2d00b9799db482af352fa4a4dd5ae87 Mon Sep 17 00:00:00 2001 From: ljain112 Date: Thu, 25 May 2023 17:57:19 +0530 Subject: [PATCH] fix: don't mutate notification when getting cc and bcc --- .../doctype/notification/notification.py | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/frappe/email/doctype/notification/notification.py b/frappe/email/doctype/notification/notification.py index 2efbf597ec..aee68aa4e5 100644 --- a/frappe/email/doctype/notification/notification.py +++ b/frappe/email/doctype/notification/notification.py @@ -282,19 +282,8 @@ def get_context(context): email_ids = email_ids_value.replace(",", "\n") recipients = recipients + email_ids.split("\n") - if recipient.cc and "{" in recipient.cc: - recipient.cc = frappe.render_template(recipient.cc, context) - - if recipient.cc: - recipient.cc = recipient.cc.replace(",", "\n") - cc = cc + recipient.cc.split("\n") - - if recipient.bcc and "{" in recipient.bcc: - recipient.bcc = frappe.render_template(recipient.bcc, context) - - if recipient.bcc: - recipient.bcc = recipient.bcc.replace(",", "\n") - bcc = bcc + recipient.bcc.split("\n") + cc.extend(get_emails_from_template(recipient.cc, context)) + bcc.extend(get_emails_from_template(recipient.bcc, context)) # For sending emails to specified role if recipient.receiver_by_role: @@ -485,3 +474,11 @@ def get_assignees(doc): recipients = [d.allocated_to for d in assignees] return recipients + + +def get_emails_from_template(template, context): + if not template: + return () + + emails = frappe.render_template(template, context) if "{" in template else template + return filter(None, emails.replace(",", "\n").split("\n"))