[fix] Don't add emails to CC if no CC added from the UI. Fixes frappe/erpnext#4164

This commit is contained in:
Anand Doshi 2015-10-14 13:20:49 +05:30
parent 3e4707d0aa
commit 44e6c02516
6 changed files with 30 additions and 9 deletions

View file

@ -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

View file

@ -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 <human@example.com>"
filtered.append(email)
email_address_list.append(email_address)
email_address_list.append(email_address)
return filtered

View file

@ -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 here-->", 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 -->", 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,

View file

@ -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 {

View file

@ -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"]) ]) );
}

View file

@ -8,6 +8,7 @@
<body style="line-height: 1.5; color: #36414C;">
<!-- body -->
<div style="font-family: Helvetica, Arial, sans-serif; font-size: 14px; padding: 10px;">
<em><!-- cc message --></em>
{{ content }}
{{ signature }}
</div>