diff --git a/templates/zerver/emails/digest/digest_email.txt b/templates/zerver/emails/digest/digest_email.txt index 5098ab7b6e..6dc67a3308 100644 --- a/templates/zerver/emails/digest/digest_email.txt +++ b/templates/zerver/emails/digest/digest_email.txt @@ -1,4 +1,3 @@ -{% load app_filters %} {# Mail sent to a user who hasn't logged in for 24 hours. #} @@ -32,20 +31,20 @@ been gone: {% endif %} {% for message_block in sender_block.content %}{{ message_block.plain }} {% endfor %}{% endfor %} -{% if convo.count > 0 %}+ {{ convo.count }} more message{{ convo.count|pluralize }} by {{ convo.participants|display_list:4 }}.{% endif %} +{% if convo.count > 0 %}+ {{ convo.count }} more message{{ convo.count|pluralize }} by {{ convo.participants|display_list(4) }}.{% endif %} {% endfor %}{% endfor %} Catch up on the rest of these conversations: https://{{ external_host }}.{% endif %} {% if new_users and new_streams.plain %}** Group updates **{% elif new_users %}** New users **{% elif new_streams.plain %}** New streams **{% endif %} -{% if new_streams.plain %}{% if new_stream_count > 1 %}A new stream was{% else %}Some new streams were{% endif %} created: +{% if new_streams.plain %}{% if new_stream_count and new_stream_count > 1 %}A new stream was{% else %}Some new streams were{% endif %} created: - {{ new_streams.plain|display_list:4 }}. + {{ new_streams.plain|display_list(4) }}. Visit your Streams page to subscribe: https://{{ external_host }}/#subscriptions.{% endif %} -{% if new_users %}{% if new_streams.plain or unread_pms or hot_conversations %}And finally, please{% else %}Please{% endif %} welcome {{ new_users|display_list:4 }} to Zulip!{% endif %} +{% if new_users %}{% if new_streams.plain or unread_pms or hot_conversations %}And finally, please{% else %}Please{% endif %} welcome {{ new_users|display_list(4) }} to Zulip!{% endif %} Click here to log in to Zulip and catch up: https://{{ external_host }}. diff --git a/templates/zerver/emails/digest/digest_email_html.txt b/templates/zerver/emails/digest/digest_email_html.txt index 57bb3754c7..2eabade0b0 100644 --- a/templates/zerver/emails/digest/digest_email_html.txt +++ b/templates/zerver/emails/digest/digest_email_html.txt @@ -1,4 +1,3 @@ -{% load app_filters %} {# Mail sent to a user who hasn't logged in for 24 hours. #} @@ -56,7 +55,7 @@ Here are some of the hot conversations that have happened while you've been gone {% endfor %} - {% if convo.count > 0 %}

+ {{ convo.count }} more message{{ convo.count|pluralize }} by {{ convo.participants|display_list:4 }}.

{% endif %} + {% if convo.count > 0 %}

+ {{ convo.count }} more message{{ convo.count|pluralize }} by {{ convo.participants|display_list(4) }}.

{% endif %} {% endfor %} {% endfor %} @@ -76,15 +75,15 @@ Here are some of the hot conversations that have happened while you've been gone {% endif %} {% if new_streams.html %} -

{% if new_stream_count > 1 %}A new stream was{% else %}Some new streams were{% endif %} created:

+

{% if new_stream_count and new_stream_count > 1 %}A new stream was{% else %}Some new streams were{% endif %} created:

-

{{ new_streams.html|display_list:4|safe }}.

+

{{ new_streams.html|display_list(4)|safe }}.

-

Click on {% if new_stream_count > 1 %}a{% else %}the{% endif %} name to check out some of the traffic, or visit your Streams page to subscribe.

+

Click on {% if new_stream_count and new_stream_count > 1 %}a{% else %}the{% endif %} name to check out some of the traffic, or visit your Streams page to subscribe.

{% endif %} {% if new_users %} -

{% if new_streams.html or unread_pms or hot_conversations %}And finally, please{% else %}Please{% endif %} welcome {{ new_users|display_list:4 }} to Zulip!

+

{% if new_streams.html or unread_pms or hot_conversations %}And finally, please{% else %}Please{% endif %} welcome {{ new_users|display_list(4) }} to Zulip!

{% endif %}
diff --git a/zerver/tests/test_email_mirror.py b/zerver/tests/test_email_mirror.py index b7798a4bb3..cb0b7488ea 100644 --- a/zerver/tests/test_email_mirror.py +++ b/zerver/tests/test_email_mirror.py @@ -22,6 +22,8 @@ from zerver.lib.email_mirror import ( create_missed_message_address, ) +from zerver.lib.digest import handle_digest_email + from zerver.lib.notifications import ( handle_missedmessage_emails, ) @@ -32,6 +34,7 @@ import datetime import time import re import ujson +import mock class TestStreamEmailMessagesSuccess(AuthedTestCase): @@ -183,3 +186,25 @@ class TestMissedHuddleMessageEmailMessages(AuthedTestCase): self.assertEqual(message.content, "TestMissedHuddleMessageEmailMessages Body") self.assertEqual(message.sender, get_user_profile_by_email("cordelia@zulip.com")) self.assertEqual(message.recipient.type, Recipient.HUDDLE) + +class TestDigestEmailMessages(AuthedTestCase): + @mock.patch('zerver.lib.digest.enough_traffic') + @mock.patch('zerver.lib.digest.send_future_email') + def test_receive_digest_email_messages(self, mock_send_future_email, mock_enough_traffic): + + # build dummy messages for missed messages email reply + # have Hamlet send Othello a PM. Othello will reply via email + # Hamlet will receive the message. + self.login("hamlet@zulip.com") + result = self.client.post("/json/messages", {"type": "private", + "content": "test_receive_missed_message_email_messages", + "client": "test suite", + "to": "othello@zulip.com"}) + self.assert_json_success(result) + + user_profile = get_user_profile_by_email("othello@zulip.com") + cutoff = time.mktime(datetime.datetime(year=2016, month=1, day=1).timetuple()) + handle_digest_email(user_profile.id, cutoff) + self.assertEqual(mock_send_future_email.call_count, 1) + self.assertEqual(mock_send_future_email.call_args[0][0][0]['email'], + u'othello@zulip.com') diff --git a/zproject/jinja2/__init__.py b/zproject/jinja2/__init__.py index 406ecb8c9f..827ed60e88 100644 --- a/zproject/jinja2/__init__.py +++ b/zproject/jinja2/__init__.py @@ -9,6 +9,7 @@ from django.http import HttpResponse from jinja2 import Environment from .compressors import compressed_css, minified_js +from zerver.templatetags.app_filters import display_list def render_to_response(*args, **kwargs): @@ -29,5 +30,6 @@ def environment(**options): env.filters['slugify'] = slugify env.filters['pluralize'] = pluralize + env.filters['display_list'] = display_list return env