Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
send_email: Substitute body directly, not via Jinja2.
Alex Vandiverae51fbdda263
diff --git a/zerver/lib/send_email.py b/zerver/lib/send_email.pyindex 5fa63d9a98d..ff34e8afc75 100644--- a/zerver/lib/send_email.py+++ b/zerver/lib/send_email.py@@ -542,7 +542,13 @@ def send_custom_email(# And then extend it with our standard email headers.with open(html_template_path, "w") as f:with open(markdown_email_base_template_path) as base_template:- f.write(base_template.read())+ # We use an ugly string substitution here, because we want to:+ # 1. Only run Jinja once on the supplied content+ # 2. Allow the supplied content to have jinja interpolation in it+ # 3. Have that interpolation happen in the context of+ # each individual email we send, so the contents can+ # vary user-to-user+ f.write(base_template.read().replace("{{ rendered_input }}", rendered_input))with open(subject_path, "w") as f:f.write(get_header(options.get("subject"), parsed_email_template.get("subject"), "subject"))@@ -555,7 +561,6 @@ def send_custom_email("realm_uri": user_profile.realm.uri,"realm_name": user_profile.realm.name,"unsubscribe_link": one_click_unsubscribe_link(user_profile, "marketing"),- "rendered_input": rendered_input,}with suppress(EmailNotDeliveredError):send_email(diff --git a/zerver/tests/test_email_notifications.py b/zerver/tests/test_email_notifications.pyindex 94b8e98597c..8a15fb0cb31 100644--- a/zerver/tests/test_email_notifications.py+++ b/zerver/tests/test_email_notifications.py@@ -54,9 +54,12 @@ class TestCustomEmails(ZulipTestCase):self.assertNotIn("{% block content %}", msg.body)self.assertIn("# Some heading", msg.body)self.assertIn("Zulip Dev", msg.body)+ self.assertNotIn("{{ realm_name }}", msg.body)+ self.assertNotIn("</div>", msg.body)assert isinstance(msg, EmailMultiAlternatives)self.assertIn("Some heading</h1>", str(msg.alternatives[0][0]))+ self.assertNotIn("{{ realm_name }}", str(msg.alternatives[0][0]))def test_send_custom_email_remote_server(self) -> None:email_subject = "subject_test"