[Fix] Unsubscribe url fix
This commit is contained in:
parent
fd506d3c12
commit
07d33c5c8e
2 changed files with 14 additions and 8 deletions
|
|
@ -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<!--cc message-->"
|
||||
else:
|
||||
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({
|
||||
"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-->", unsubscribe_url)
|
||||
message = message.replace("<!--unsubscribe url-->", 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("<!--cc message-->", email_sent_message)
|
||||
message = message.replace("<!--cc message-->", quopri.encodestring(email_sent_message))
|
||||
|
||||
message = message.replace("<!--recipient-->", recipient)
|
||||
return message
|
||||
|
|
|
|||
|
|
@ -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('<!--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):
|
||||
self.test_email_queue()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue