diff --git a/frappe/email/queue.py b/frappe/email/queue.py index aed9ae8b0f..da59a44124 100755 --- a/frappe/email/queue.py +++ b/frappe/email/queue.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import frappe import HTMLParser -import smtplib +import smtplib, quopri from frappe import msgprint, throw, _ from frappe.email.smtp import SMTPServer, get_outgoing_email_account from frappe.email.email_body import get_email, get_formatted_html @@ -174,7 +174,7 @@ def get_unsubscribe_message(unsubscribe_message, expose_recipients): text = "\n" else: text = "" - text += "\n\n{unsubscribe_message}: ".format(unsubscribe_message=unsubscribe_message) + text += "\n\n{unsubscribe_message}: \n".format(unsubscribe_message=unsubscribe_message) return frappe._dict({ "html": html, @@ -359,7 +359,7 @@ def prepare_message(email, recipient, recipients_list): if email.reference_doctype: # is missing the check for unsubscribe message but will not add as there will be no unsubscribe url unsubscribe_url = get_unsubcribed_url(email.reference_doctype, email.reference_name, recipient, email.unsubscribe_method, email.unsubscribe_params) - message = message.replace("", unsubscribe_url) + message = message.replace("", quopri.encodestring(unsubscribe_url)) if email.expose_recipients == "header": pass @@ -375,7 +375,7 @@ def prepare_message(email, recipient, recipients_list): email_sent_message = _("This email was sent to {0} and copied to {1}").format(email_sent_to,email_sent_cc) else: email_sent_message = _("This email was sent to {0}").format(email_sent_to) - message = message.replace("", email_sent_message) + message = message.replace("", quopri.encodestring(email_sent_message)) message = message.replace("", recipient) return message diff --git a/frappe/tests/test_email.py b/frappe/tests/test_email.py index 86d652a72d..fc639e77e9 100644 --- a/frappe/tests/test_email.py +++ b/frappe/tests/test_email.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals -import unittest, frappe, re +import unittest, frappe, re, email from frappe.test_runner import make_test_records make_test_records("User") @@ -87,6 +87,7 @@ class TestEmail(unittest.TestCase): self.assertTrue('This email was sent to test@example.com and copied to test1@example.com' in frappe.flags.sent_mail) def test_expose(self): + from frappe.utils.verified_command import verify_request frappe.sendmail(recipients=['test@example.com'], cc=['test1@example.com'], sender="admin@example.com", @@ -103,9 +104,14 @@ class TestEmail(unittest.TestCase): where status='Sent'""", as_dict=1)[0].message self.assertTrue('' in message) - frappe.local.flags.signed_query_string = re.search('(?<=/api/method/frappe.email.queue.unsubscribe\?).*(?=\n)', frappe.flags.sent_mail).group(0) - from frappe.utils.verified_command import verify_request - self.assertTrue(verify_request()) + email_obj = email.message_from_string(frappe.flags.sent_mail) + for part in email_obj.walk(): + content = part.get_payload(decode=True) + + if content: + frappe.local.flags.signed_query_string = re.search('(?<=/api/method/frappe.email.queue.unsubscribe\?).*(?=\n)', content).group(0) + self.assertTrue(verify_request()) + break def test_expired(self): self.test_email_queue()