Browse Source

Merge pull request #2631 from KanchanChauhan/unsubscribe-url-fix

[Fix] Unsubscribe url fix
version-14
rohitwaghchaure 8 years ago
committed by GitHub
parent
commit
c02df70d13
2 changed files with 14 additions and 8 deletions
  1. +4
    -4
      frappe/email/queue.py
  2. +10
    -4
      frappe/tests/test_email.py

+ 4
- 4
frappe/email/queue.py View File

@@ -4,7 +4,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
import HTMLParser import HTMLParser
import smtplib
import smtplib, quopri
from frappe import msgprint, throw, _ from frappe import msgprint, throw, _
from frappe.email.smtp import SMTPServer, get_outgoing_email_account from frappe.email.smtp import SMTPServer, get_outgoing_email_account
from frappe.email.email_body import get_email, get_formatted_html 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<!--cc message-->" text = "\n<!--cc message-->"
else: else:
text = "" text = ""
text += "\n\n{unsubscribe_message}: <!--unsubscribe url-->".format(unsubscribe_message=unsubscribe_message)
text += "\n\n{unsubscribe_message}: <!--unsubscribe url-->\n".format(unsubscribe_message=unsubscribe_message)


return frappe._dict({ return frappe._dict({
"html": html, "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 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, unsubscribe_url = get_unsubcribed_url(email.reference_doctype, email.reference_name, recipient,
email.unsubscribe_method, email.unsubscribe_params) email.unsubscribe_method, email.unsubscribe_params)
message = message.replace("<!--unsubscribe url-->", unsubscribe_url)
message = message.replace("<!--unsubscribe url-->", quopri.encodestring(unsubscribe_url))


if email.expose_recipients == "header": if email.expose_recipients == "header":
pass 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) email_sent_message = _("This email was sent to {0} and copied to {1}").format(email_sent_to,email_sent_cc)
else: else:
email_sent_message = _("This email was sent to {0}").format(email_sent_to) email_sent_message = _("This email was sent to {0}").format(email_sent_to)
message = message.replace("<!--cc message-->", email_sent_message)
message = message.replace("<!--cc message-->", quopri.encodestring(email_sent_message))


message = message.replace("<!--recipient-->", recipient) message = message.replace("<!--recipient-->", recipient)
return message return message


+ 10
- 4
frappe/tests/test_email.py View File

@@ -3,7 +3,7 @@


from __future__ import unicode_literals from __future__ import unicode_literals


import unittest, frappe, re
import unittest, frappe, re, email


from frappe.test_runner import make_test_records from frappe.test_runner import make_test_records
make_test_records("User") 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) 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): def test_expose(self):
from frappe.utils.verified_command import verify_request
frappe.sendmail(recipients=['test@example.com'], frappe.sendmail(recipients=['test@example.com'],
cc=['test1@example.com'], cc=['test1@example.com'],
sender="admin@example.com", sender="admin@example.com",
@@ -103,9 +104,14 @@ class TestEmail(unittest.TestCase):
where status='Sent'""", as_dict=1)[0].message where status='Sent'""", as_dict=1)[0].message
self.assertTrue('<!--recipient-->' in message) self.assertTrue('<!--recipient-->' 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): def test_expired(self):
self.test_email_queue() self.test_email_queue()


Loading…
Cancel
Save