notifications: Fix incorrect advertising in missed-message emails.

Missed-message email replies using the reply-to of
noreply@zulipchat.com shouldn't advertise that "just replying" will
work.

Rebased and commit message rewritten by tabbott.

Fixes #3965.
This commit is contained in:
Rohitt Vashishtha 2017-03-08 09:16:49 +05:30 committed by Tim Abbott
parent 1c5e9ae7f6
commit 202389d4a7
2 changed files with 55 additions and 3 deletions

View File

@ -253,12 +253,24 @@ def do_send_missedmessage_events_reply_in_zulip(user_profile, missed_messages, m
'name': user_profile.full_name,
'messages': build_message_list(user_profile, missed_messages),
'message_count': message_count,
'reply_warning': False,
'mention': missed_messages[0].recipient.type == Recipient.STREAM,
'reply_to_zulip': True,
'unsubscribe_link': unsubscribe_link,
})
# If this setting (email mirroring integration) is enabled, only then
# can users reply to email to send message to Zulip. Thus, one must
# ensure to display warning in the template.
if settings.EMAIL_GATEWAY_PATTERN:
template_payload.update({
'reply_warning': False,
'reply_to_zulip': True,
})
else:
template_payload.update({
'reply_warning': True,
'reply_to_zulip': False,
})
headers = {}
from zerver.lib.email_mirror import create_missed_message_address
address = create_missed_message_address(user_profile, missed_messages[0])
@ -279,6 +291,10 @@ def do_send_missedmessage_events_reply_in_zulip(user_profile, missed_messages, m
headers['Sender'] = from_email
sender = missed_messages[0].sender
from_email = '"%s" <%s>' % (sender_str, sender.email)
template_payload.update({
'reply_warning': False,
'reply_to_zulip': False,
})
text_content = loader.render_to_string('zerver/missed_message_email.txt', template_payload)
html_content = loader.render_to_string('zerver/missed_message_email.html', template_payload)

View File

@ -32,7 +32,10 @@ class TestMissedMessages(ZulipTestCase):
othello = get_user_profile_by_email('othello@zulip.com')
hamlet = get_user_profile_by_email('hamlet@zulip.com')
handle_missedmessage_emails(hamlet.id, [{'message_id': msg_id}])
reply_to_addresses = [settings.EMAIL_GATEWAY_PATTERN % (u'mm' + t) for t in tokens]
if settings.EMAIL_GATEWAY_PATTERN != "":
reply_to_addresses = [settings.EMAIL_GATEWAY_PATTERN % (u'mm' + t) for t in tokens]
else:
reply_to_addresses = ["noreply@example.com"]
msg = mail.outbox[0]
sender = 'Zulip <{}>'.format(settings.NOREPLY_EMAIL_ADDRESS)
from_email = sender
@ -71,6 +74,30 @@ class TestMissedMessages(ZulipTestCase):
body = 'You and Othello, the Moor of Venice Extremely personal message!'
self._test_cases(tokens, msg_id, body, send_as_user)
@patch('zerver.lib.email_mirror.generate_random_token')
def _reply_to_email_in_personal_missed_stream_messages(self, send_as_user, mock_random_token):
# type: (bool, MagicMock) -> None
tokens = self._get_tokens()
mock_random_token.side_effect = tokens
msg_id = self.send_message("othello@zulip.com", "hamlet@zulip.com",
Recipient.PERSONAL,
'Extremely personal message!')
body = 'Or just reply to this email.'
self._test_cases(tokens, msg_id, body, send_as_user)
@patch('zerver.lib.email_mirror.generate_random_token')
def _reply_warning_in_personal_missed_stream_messages(self, send_as_user, mock_random_token):
# type: (bool, MagicMock) -> None
tokens = self._get_tokens()
mock_random_token.side_effect = tokens
msg_id = self.send_message("othello@zulip.com", "hamlet@zulip.com",
Recipient.PERSONAL,
'Extremely personal message!')
body = 'Please do not reply to this automated message.'
self._test_cases(tokens, msg_id, body, send_as_user)
@patch('zerver.lib.email_mirror.generate_random_token')
def _extra_context_in_huddle_missed_stream_messages(self, send_as_user, mock_random_token):
# type: (bool, MagicMock) -> None
@ -95,6 +122,15 @@ class TestMissedMessages(ZulipTestCase):
# type: () -> None
self._extra_context_in_missed_stream_messages(False)
def test_reply_to_email_in_personal_missed_stream_messages(self):
# type: () -> None
self._reply_to_email_in_personal_missed_stream_messages(False)
@override_settings(EMAIL_GATEWAY_PATTERN="")
def test_reply_warning_in_personal_missed_stream_messages(self):
# type: () -> None
self._reply_warning_in_personal_missed_stream_messages(False)
@override_settings(SEND_MISSED_MESSAGE_EMAILS_AS_USER=True)
def test_extra_context_in_personal_missed_stream_messages_as_user(self):
# type: () -> None