From 44e6c02516fb4ac31290beca57ce2fa737e6c2ab Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 14 Oct 2015 13:20:49 +0530 Subject: [PATCH] [fix] Don't add emails to CC if no CC added from the UI. Fixes frappe/erpnext#4164 --- frappe/__init__.py | 4 ++-- .../core/doctype/communication/communication.py | 17 ++++++++++++----- frappe/email/bulk.py | 10 +++++++++- .../public/js/frappe/ui/toolbar/awesome_bar.js | 5 +++++ frappe/public/js/frappe/views/communication.js | 2 +- frappe/templates/emails/standard.html | 1 + 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index 536e721048..c6825ae7e6 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -310,7 +310,7 @@ def sendmail(recipients=(), sender="", subject="No Subject", message="No Message as_markdown=False, bulk=False, reference_doctype=None, reference_name=None, unsubscribe_method=None, unsubscribe_params=None, unsubscribe_message=None, attachments=None, content=None, doctype=None, name=None, reply_to=None, - cc=(), message_id=None, as_bulk=False, send_after=None, expose_recipients=False, + cc=(), show_as_cc=(), message_id=None, as_bulk=False, send_after=None, expose_recipients=False, bulk_priority=1): """Send email using user's default **Email Account** or global default **Email Account**. @@ -339,7 +339,7 @@ def sendmail(recipients=(), sender="", subject="No Subject", message="No Message subject=subject, message=content or message, reference_doctype = doctype or reference_doctype, reference_name = name or reference_name, unsubscribe_method=unsubscribe_method, unsubscribe_params=unsubscribe_params, unsubscribe_message=unsubscribe_message, - attachments=attachments, reply_to=reply_to, cc=cc, message_id=message_id, send_after=send_after, + attachments=attachments, reply_to=reply_to, cc=cc, show_as_cc=show_as_cc, message_id=message_id, send_after=send_after, expose_recipients=expose_recipients, bulk_priority=bulk_priority) else: import frappe.email diff --git a/frappe/core/doctype/communication/communication.py b/frappe/core/doctype/communication/communication.py index e56b69c9df..a8dca84b6d 100644 --- a/frappe/core/doctype/communication/communication.py +++ b/frappe/core/doctype/communication/communication.py @@ -115,6 +115,7 @@ class Communication(Document): frappe.sendmail( recipients=(recipients or []) + (cc or []), + show_as_cc=(cc or []), expose_recipients=True, sender=self.sender, reply_to=self.incoming_email_account, @@ -230,8 +231,8 @@ class Communication(Document): cc = split_emails(self.cc) if self.reference_doctype and self.reference_name: - if not cc or fetched_from_email_account: - # if CC is not mentioned from the UI or is a fetched email, add follows to CC + if fetched_from_email_account: + # if it is a fetched email, add follows to CC cc.append(self.get_owner_email()) cc += self.get_assignees() cc += self.get_starrers() @@ -261,7 +262,7 @@ class Communication(Document): exclude += [d[0] for d in frappe.db.get_all("Email Unsubscribe", ["email"], {"reference_doctype": self.reference_doctype, "reference_name": self.reference_name}, as_list=True)] - cc = self.filter_email_list(cc, exclude) + cc = self.filter_email_list(cc, exclude, is_cc=True) if getattr(self, "send_me_a_copy", False) and self.sender not in cc: self.all_email_addresses.append(self.sender) @@ -269,7 +270,7 @@ class Communication(Document): return cc - def filter_email_list(self, email_list, exclude): + def filter_email_list(self, email_list, exclude, is_cc=False): # temp variables filtered = [] email_address_list = [] @@ -284,12 +285,18 @@ class Communication(Document): if email_address in exclude: continue + + if is_cc: + is_user_enabled = frappe.db.get_value("User", email_address, "enabled") + if is_user_enabled==0: + # don't send to disabled users + continue # make sure of case-insensitive uniqueness of email address if email_address not in email_address_list: # append the full email i.e. "Human " filtered.append(email) - email_address_list.append(email_address) + email_address_list.append(email_address) return filtered diff --git a/frappe/email/bulk.py b/frappe/email/bulk.py index 9b69458526..dadc615bed 100644 --- a/frappe/email/bulk.py +++ b/frappe/email/bulk.py @@ -16,7 +16,7 @@ class BulkLimitCrossedError(frappe.ValidationError): pass def send(recipients=None, sender=None, subject=None, message=None, reference_doctype=None, reference_name=None, unsubscribe_method=None, unsubscribe_params=None, unsubscribe_message=None, - attachments=None, reply_to=None, cc=(), message_id=None, send_after=None, + attachments=None, reply_to=None, cc=(), show_as_cc=(), message_id=None, send_after=None, expose_recipients=False, bulk_priority=1): """Add email to sending queue (Bulk Email) @@ -88,6 +88,14 @@ def send(recipients=None, sender=None, subject=None, message=None, reference_doc email_content = email_content.replace("", unsubscribe_link.html) email_text_context += unsubscribe_link.text + + # show as cc + cc_message = "" + if email in show_as_cc: + cc_message = _("This email was sent to you as CC") + + email_content = email_content.replace("", cc_message) + email_text_context = cc_message + "\n" + email_text_context # add to queue add(email, sender, subject, email_content, email_text_context, reference_doctype, diff --git a/frappe/public/js/frappe/ui/toolbar/awesome_bar.js b/frappe/public/js/frappe/ui/toolbar/awesome_bar.js index 721b8cefc9..8e448e0054 100644 --- a/frappe/public/js/frappe/ui/toolbar/awesome_bar.js +++ b/frappe/public/js/frappe/ui/toolbar/awesome_bar.js @@ -190,6 +190,11 @@ frappe.search.verbs = [ // doctype list function(txt) { + if (txt.toLowerCase().indexOf(" list")) { + // remove list keyword + txt = txt.replace(/ list/ig, "").trim(); + } + frappe.search.find(frappe.boot.user.can_read, txt, function(match) { if(in_list(frappe.boot.single_types, match)) { return { diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js index 3db2d32bb0..33ddca2422 100644 --- a/frappe/public/js/frappe/views/communication.js +++ b/frappe/public/js/frappe/views/communication.js @@ -435,7 +435,7 @@ frappe.views.CommunicationComposer = Class.extend({ callback: function(r) { if(!r.exc) { if(form_values.send_email && r.message["emails_not_sent_to"]) { - msgprint( __("Email not sent to {0}", + msgprint( __("Email not sent to {0} (unsubscribed / disabled)", [ frappe.utils.escape_html(r.message["emails_not_sent_to"]) ]) ); } diff --git a/frappe/templates/emails/standard.html b/frappe/templates/emails/standard.html index fa8981a37b..4a9cf795bb 100644 --- a/frappe/templates/emails/standard.html +++ b/frappe/templates/emails/standard.html @@ -8,6 +8,7 @@
+ {{ content }} {{ signature }}