Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
custom_email: Add manage_preferences block to the plaintext version.
Prakhar Pratyushe8349aa5d705
diff --git a/templates/zerver/emails/custom_email_base.pre.manage_preferences_block.txt b/templates/zerver/emails/custom_email_base.pre.manage_preferences_block.txtnew file mode 100644index 00000000000..37d3c97e3a4--- /dev/null+++ b/templates/zerver/emails/custom_email_base.pre.manage_preferences_block.txt@@ -0,0 +1,15 @@++---+{% if remote_server_email %}+You are receiving this email to update you about important changes to Zulip's Terms of Service.++Unsubscribe: {{ unsubscribe_link }}+{% elif unsubscribe_link %}+{{ _("Manage email preferences") }}:++{{ realm_url }}/#settings/notifications++{{ _("Unsubscribe from marketing emails") }}:++{{ unsubscribe_link }}+{% endif %}diff --git a/zerver/lib/send_email.py b/zerver/lib/send_email.pyindex e1f512aa58c..88036728430 100644--- a/zerver/lib/send_email.py+++ b/zerver/lib/send_email.py@@ -560,6 +560,16 @@ def custom_email_sender(# vary user-to-userf.write(base_template.read().replace("{{ rendered_input }}", rendered_input))+ # Add the manage_preferences block content in the plain_text template.+ manage_preferences_block_template_path = (+ "templates/zerver/emails/custom_email_base.pre.manage_preferences_block.txt"+ )+ with (+ open(plain_text_template_path, "a") as f,+ open(manage_preferences_block_template_path) as manage_preferences_block,+ ):+ f.write(manage_preferences_block.read())+with open(subject_path, "w") as f:f.write(get_header(subject, parsed_email_template.get("subject"), "subject"))diff --git a/zerver/tests/test_email_notifications.py b/zerver/tests/test_email_notifications.pyindex ecf9507b0be..2a649130ffc 100644--- a/zerver/tests/test_email_notifications.py+++ b/zerver/tests/test_email_notifications.py@@ -90,6 +90,11 @@ class TestCustomEmails(ZulipTestCase):str(msg.alternatives[0][0]),)self.assertIn("Unsubscribe", str(msg.alternatives[0][0]))+ # Verify that the Text version contains the footer.+ self.assertIn(+ "You are receiving this email to update you about important changes to Zulip", msg.body+ )+ self.assertIn("Unsubscribe", msg.body)def test_send_custom_email_headers(self) -> None:hamlet = self.example_user("hamlet")@@ -107,7 +112,7 @@ class TestCustomEmails(ZulipTestCase):msg = mail.outbox[0]self.assertEqual(msg.subject, "Test subject")self.assertFalse(msg.reply_to)- self.assertEqual("Test body", msg.body)+ self.assertIn("Test body", msg.body)def test_send_custom_email_context(self) -> None:hamlet = self.example_user("hamlet")