Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
emails: Fix style regression for dynamically generated content.
Daniil Fadeevd79f4d4f46d0
diff --git a/templates/zerver/emails/digest.html b/templates/zerver/emails/digest.htmlindex db4d4fea92a..774b4ef08c1 100644--- a/templates/zerver/emails/digest.html+++ b/templates/zerver/emails/digest.html@@ -17,25 +17,25 @@{% endfor %}</div></div>- {% if convo.count > 0 %}<p>+ {{ convo.count }} more message{{ convo.count|pluralize }} by {{ convo.participants|display_list(4) }}.</p>{% endif %}+ {% if convo.count > 0 %}<p class="digest_paragraph">+ {{ convo.count }} more message{{ convo.count|pluralize }} by {{ convo.participants|display_list(4) }}.</p>{% endif %}{% endfor %}</div>{% endfor %}{% endif %}{% if new_streams.html %}- <p><b>{% trans %}New streams{% endtrans %}</b></p>+ <p class="digest_paragraph"><b>{% trans %}New streams{% endtrans %}</b></p>- <p>{{ new_streams.html|display_list(1000)|safe }}.</p>+ <p class="digest_paragraph">{{ new_streams.html|display_list(1000)|safe }}.</p>{% endif %}<br />- <p><a href="{{ realm_uri }}">{% trans %}Click here to log in to Zulip and catch up.{% endtrans %}</a></p>+ <p class="digest_paragraph"><a href="{{ realm_uri }}">{% trans %}Click here to log in to Zulip and catch up.{% endtrans %}</a></p>{% endblock %}{% block manage_preferences %}-<p>+<p class="digest_paragraph"><a href="{{ realm_uri }}/#settings/notifications">{% trans %}Manage email preferences{% endtrans %}</a> |<a href="{{ unsubscribe_link }}">{% trans %}Unsubscribe from digest emails{% endtrans %}</a></p>diff --git a/templates/zerver/emails/email.css b/templates/zerver/emails/email.cssindex bd061f41c57..3f7165f3af1 100644--- a/templates/zerver/emails/email.css+++ b/templates/zerver/emails/email.css@@ -1,9 +1,11 @@/* stylelint-disable color-no-hex, media-feature-range-notation */-/* hex color codes are used instead of our standard of hsl colors,-because hex color codes are rendered by all email clients-consistently. Whereas HSL colors don't work with Hotmail. */-img {+/* Hex color codes are used instead of our standard of hsl colors,+ because hex color codes are rendered by all email clients+ consistently; HSL colors aren't supported by Hotmail. */++.illustration img,+img.bottom-illustration {border: none;-ms-interpolation-mode: bicubic;max-width: 100%;@@ -20,26 +22,27 @@ body {-webkit-text-size-adjust: 100%;}-pre {- font-family: sans-serif;- font-size: 14px;-}--table {+/* These .layout tables are used to create sections within the email;+ see for example: https://templates.mailchimp.com/development/html/+*/+table.layout {border-collapse: separate;mso-table-lspace: 0;mso-table-rspace: 0;width: 100%;}-table td {+table.layout > tbody > tr > td {font-family: sans-serif;font-size: 14px;vertical-align: top;}+/* After email clients strip the actual <body> tag out of the email, the+ .body element will be the equivalent of our outer element. */.body {width: 100%;+ background-color: #f5f9f8;}.container {@@ -49,10 +52,14 @@ table td {padding: 10px;}+/* Our newsletters/marketing emails use a wider content width, to+ support more complex content with text to the side of images. */.container.wide-container {max-width: 700px;}+/* Mystery: .container contains .content, but the max-widths for this+ element are 80px wider than those for .container. */.content {box-sizing: border-box;display: block;@@ -65,17 +72,22 @@ table td {max-width: 780px;}+/*+ The main content region for the email; excludes the preheader and footer.+*/.main {background-color: #fff;border-radius: 3px;width: 100%;}+/* Right/left padding to keep content away from edges of email client winder. */.wrapper {box-sizing: border-box;padding: 0 20px 20px;}+/* Footer section, containing unsubscribe links and the like. */.footer {clear: both;padding-top: 10px;@@ -84,65 +96,58 @@ table td {margin-top: 20px;}-.footer td,-.footer span {+/*+ Apple mail and other popular email clients will convert the physical+ address into a link, so we set link color on it.+*/+.footer-content-block,+.physical-address {color: #5f5ec7;font-size: 12px;text-align: center;}-h1,-h2,-h3,-h4 {- color: #4e4d4d !important;- font-family: sans-serif;- font-weight: 600;- line-height: 1.4;- margin-bottom: 30px;-}--h1 {- font-size: 35px;- font-weight: 300;- text-align: center;- text-transform: capitalize;-}--h2 {- font-size: 24px;- margin-top: 20px;- margin-bottom: 10px;-}--ul,-ol {+.content ul,+.content ol {/* Override excessive indentation seen in Gmail. */padding-left: 5px;}-p,-ul,-ol {+.body p,+p.digest_paragraph,+.content ul,+.content ol {font-family: sans-serif;font-size: 14px;font-weight: normal;margin: 10px 0;}-p li,-ul li,-ol li {+.body p li,+.content ul li,+.content ol li {list-style-position: outside;margin-left: 15px;}-a {+/* Link color styling carefully tuned to not apply to user content+ inside missed-message emails. */+.body a,+.digest_paragraph a,+.sponsorship_request_link,+.support_request_link,+.email-preferences a,+.missed_message.no-content-explanation a {color: #5f5ec7;text-decoration: underline;}-a:hover {+.body a:hover,+.digest_paragraph a:hover,+.sponsorship_request_link:hover,+.support_request_link:hover,+.email-preferences a:hover,+.missed_message.no_content a:hover {color: #434388;}@@ -150,7 +155,7 @@ a:hover {border-bottom: 3px solid #d4e3e8;}-.button {+.body .button {display: block;padding: 10px 0;margin: 20px auto;@@ -167,12 +172,15 @@ a:hover {text-shadow: none;}-a.button:hover {+.body a.button:hover {background-color: #5f5ec7;color: #fff;text-decoration: none;}+/* The preheader is an invisible region that is used to control what+ email clients display as the textual preview of the email's content+ in inbox views. */.preheader {color: transparent;display: none;@@ -186,12 +194,16 @@ a.button:hover {width: 0;}+/* Illustrations appear over the top of the boundary between the+ blank space at the top of the email and the content box; for+ that reason they need a high z-index. */.illustration {pointer-events: none;cursor: default !important;z-index: 100;}+/* CSS for digest email content. */#private-messages {width: 600px;font-size: 12px;@@ -299,6 +311,7 @@ a.button:hover {font-weight: normal;}+/* Text and link colors for missed-message emails. */.email-preferences {color: #666;}@@ -320,11 +333,15 @@ a.button:hover {color: #15c;}+/* Quoted block for text written by an organization administrator to+ explain to the end user why their account got deactivated. */.deactivated-user-text {padding: 0 0 0 15px;margin: 0 0 20px;border-left: 5px solid #eee;white-space: pre-line;+ font-family: sans-serif;+ font-size: 14px;}@media only screen and (max-width: 620px) {@@ -381,6 +398,8 @@ a.button:hover {}@media all {+ /* See https://templates.mailchimp.com/development/css/client-specific-styles/;+ ExternalClass is something Microsoft Outlook adds to emails. */.ExternalClass {width: 100%;}@@ -394,8 +413,10 @@ a.button:hover {line-height: 100%;}- /* iOS converts addresses in emails to links automatically */- .apple-link a {+ /* iOS converts physical addresses in emails to links automatically,+ so this CSS has an effect on iOS even though we don't actually+ have a link inside the .physical-address element. */+ .physical-address a {color: inherit !important;font-family: inherit !important;font-size: inherit !important;@@ -405,6 +426,7 @@ a.button:hover {}}+/* Mechanism for images alongside content, mainly for use in newsletters. */.float-right-image {float: right;}diff --git a/templates/zerver/emails/email_base_default.html b/templates/zerver/emails/email_base_default.htmlindex c29c2a0bf08..1e874609a1d 100644--- a/templates/zerver/emails/email_base_default.html+++ b/templates/zerver/emails/email_base_default.html@@ -7,7 +7,7 @@<title>Zulip</title></head><body>- <table border="0" cellpadding="0" cellspacing="0" class="body">+ <table border="0" cellpadding="0" cellspacing="0" class="body layout"><tr><td> </td><td class="container">@@ -18,25 +18,25 @@<span class="preheader">{% block preheader %}{% endblock %}</span>- <table class="main">+ <table class="main layout"><tr><td class="wrapper">- <table border="0" cellpadding="0" cellspacing="0">+ <table border="0" cellpadding="0" cellspacing="0" class="layout"><tr><td>{% block content %}{% endblock %}</td></tr></table>- <img src="{{ email_images_base_uri }}/footer.png" alt="{{ _('Swimming fish') }}"/>+ <img class="bottom-illustration" src="{{ email_images_base_uri }}/footer.png" alt="{{ _('Swimming fish') }}"/></td></tr></table><div class="footer">- <table border="0" cellpadding="0" cellspacing="0">+ <table border="0" cellpadding="0" cellspacing="0" class="layout"><tr>- <td class="content-block">- <span class="apple-link">{{physical_address}}</span>+ <td class="footer-content-block">+ <span class="physical-address">{{physical_address}}</span>{% block manage_preferences %}{% endblock %}</td></tr>diff --git a/templates/zerver/emails/email_base_marketing.html b/templates/zerver/emails/email_base_marketing.htmlindex f2bc0a53f85..47105ac1ea3 100644--- a/templates/zerver/emails/email_base_marketing.html+++ b/templates/zerver/emails/email_base_marketing.html@@ -7,7 +7,7 @@<title>Zulip</title></head><body>- <table border="0" cellpadding="0" cellspacing="0" class="body">+ <table border="0" cellpadding="0" cellspacing="0" class="body layout"><tr><td> </td><td class="container wide-container">@@ -18,10 +18,10 @@<span class="preheader">{% block preheader %}{% endblock %}</span>- <table class="main">+ <table class="main layout"><tr><td class="wrapper">- <table border="0" cellpadding="0" cellspacing="0">+ <table border="0" cellpadding="0" cellspacing="0" class="layout"><tr><td>{% block content %}{% endblock %}@@ -33,10 +33,10 @@</tr></table><div class="footer">- <table border="0" cellpadding="0" cellspacing="0">+ <table border="0" cellpadding="0" cellspacing="0" class="layout"><tr>- <td class="content-block">- <span class="apple-link">{{physical_address}}</span>+ <td class="footer-content-block">+ <span class="physical-address">{{physical_address}}</span>{% block manage_preferences %}{% endblock %}</td></tr>diff --git a/templates/zerver/emails/missed_message.html b/templates/zerver/emails/missed_message.htmlindex 4374ca1b8f9..53dbfe45fbe 100644--- a/templates/zerver/emails/missed_message.html+++ b/templates/zerver/emails/missed_message.html@@ -12,7 +12,7 @@{% endfor %}{% endfor %}{% else %}- <div class="missed_message">+ <div class="missed_message no-content-explanation">{% if message_content_disabled_by_realm %}{% trans help_url=realm_uri + "/help/hide-message-content-in-emails" %}This email does not include message content because your organization has disabled <a class="content_disabled_help_link" href="{{ help_url }}">message content appearing in email notifications</a>.{% endtrans %}{% elif message_content_disabled_by_user %}diff --git a/templates/zerver/emails/sponsorship_request.html b/templates/zerver/emails/sponsorship_request.htmlindex 84d917bd937..e40e366eca1 100644--- a/templates/zerver/emails/sponsorship_request.html+++ b/templates/zerver/emails/sponsorship_request.html@@ -1,11 +1,11 @@{% extends "zerver/emails/email_base_messages.html" %}{% block content %}-<b>Support URL</b>: <a href="{{ support_url }}">{{ support_url }}</a>+<b>Support URL</b>: <a class="sponsorship_request_link" href="{{ support_url }}">{{ support_url }}</a><br /><br />-<b>Website</b>: <a href="{{ website }}">{{ website }}</a>+<b>Website</b>: <a class="sponsorship_request_link" href="{{ website }}">{{ website }}</a><br /><br />diff --git a/templates/zerver/emails/support_request.html b/templates/zerver/emails/support_request.htmlindex 66ee14de5e6..2f805fe9363 100644--- a/templates/zerver/emails/support_request.html+++ b/templates/zerver/emails/support_request.html@@ -1,7 +1,7 @@{% extends "zerver/emails/email_base_messages.html" %}{% block content %}-<b>Support URL</b>: <a href="{{ support_url }}">{{ support_url }}</a>+<b>Support URL</b>: <a class="support_request_link" href="{{ support_url }}">{{ support_url }}</a><br /><br />diff --git a/zerver/tests/test_email_notifications.py b/zerver/tests/test_email_notifications.pyindex 971a8bf8653..125d6110fd5 100644--- a/zerver/tests/test_email_notifications.py+++ b/zerver/tests/test_email_notifications.py@@ -564,10 +564,6 @@ class TestMissedMessages(ZulipTestCase):s = s.strip()return re.sub(r"\s+", " ", s)- def remove_style_attribute(self, s: str) -> str:- pattern = r'\sstyle="[^"]+"'- return re.sub(pattern, "", s)-def _get_tokens(self) -> List[str]:return ["mm" + str(random.getrandbits(32)) for _ in range(30)]@@ -582,7 +578,6 @@ class TestMissedMessages(ZulipTestCase):verify_body_does_not_include: Sequence[str] = [],trigger: str = "",mentioned_user_group_id: Optional[int] = None,- remove_style: bool = False,) -> None:othello = self.example_user("othello")hamlet = self.example_user("hamlet")@@ -621,8 +616,6 @@ class TestMissedMessages(ZulipTestCase):for text in verify_body_include:assert isinstance(msg.alternatives[0][0], str)html = self.normalize_string(msg.alternatives[0][0])- if remove_style:- html = self.remove_style_attribute(html)self.assertIn(text, html)else:for text in verify_body_include:@@ -1384,7 +1377,7 @@ class TestMissedMessages(ZulipTestCase):f"http://zulip.testserver/user_avatars/{realm.id}/emoji/images/{realm_emoji_id}.png")verify_body_include = [- f'<img alt=":green_tick:" src="{realm_emoji_url}" title="green tick">'+ f'<img alt=":green_tick:" src="{realm_emoji_url}" style="height: 20px;" title="green tick">']email_subject = "DMs with Othello, the Moor of Venice"self._test_cases(@@ -1393,7 +1386,6 @@ class TestMissedMessages(ZulipTestCase):email_subject,send_as_user=False,verify_html_body=True,- remove_style=True,)def test_emojiset_in_missed_message(self) -> None:@@ -1406,7 +1398,7 @@ class TestMissedMessages(ZulipTestCase):"Extremely personal message with a hamburger :hamburger:!",)verify_body_include = [- '<img alt=":hamburger:" src="http://testserver/static/generated/emoji/images-twitter-64/1f354.png" title="hamburger">'+ '<img alt=":hamburger:" src="http://testserver/static/generated/emoji/images-twitter-64/1f354.png" style="height: 20px;" title="hamburger">']email_subject = "DMs with Othello, the Moor of Venice"self._test_cases(@@ -1415,7 +1407,6 @@ class TestMissedMessages(ZulipTestCase):email_subject,send_as_user=False,verify_html_body=True,- remove_style=True,)def test_stream_link_in_missed_message(self) -> None:@@ -1436,7 +1427,6 @@ class TestMissedMessages(ZulipTestCase):email_subject,send_as_user=False,verify_html_body=True,- remove_style=True,)def test_pm_link_in_missed_message_header(self) -> None:@@ -1477,7 +1467,7 @@ class TestMissedMessages(ZulipTestCase):# If message content starts with <p> tag the sender name is appended inside the <p> tag.self.assertIn('<p><b>Iago</b>: <span class="user-mention"',- self.remove_style_attribute(mail.outbox[0].alternatives[0][0]),+ mail.outbox[0].alternatives[0][0],)assert isinstance(mail.outbox[1], EmailMultiAlternatives)@@ -1486,7 +1476,7 @@ class TestMissedMessages(ZulipTestCase):# If message content does not starts with <p> tag sender name is appended before the <p> tagself.assertIn(" <b>Iago</b>: <div><ul>\n<li>1<br>\n *2</li>\n</ul></div>\n",- self.remove_style_attribute(mail.outbox[1].alternatives[0][0]),+ mail.outbox[1].alternatives[0][0],)assert isinstance(mail.outbox[2], EmailMultiAlternatives)@@ -1495,7 +1485,7 @@ class TestMissedMessages(ZulipTestCase):# Sender name is not appended to message for PM missed messagesself.assertIn(">\n \n <div><p>Hello</p></div>\n",- self.remove_style_attribute(mail.outbox[2].alternatives[0][0]),+ mail.outbox[2].alternatives[0][0],)def test_multiple_missed_personal_messages(self) -> None: