mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
notifications: Don't spoof emails as from users by default.
The previous default configuration resulted in delivery problems if the Zulip server was authorized in the SPF records for the domains of all users on the Zulip server.
This commit is contained in:
@@ -270,12 +270,16 @@ def do_send_missedmessage_events_reply_in_zulip(user_profile, missed_messages, m
|
||||
plural_messages = 's' if len(missed_messages) > 1 else ''
|
||||
|
||||
subject = "Missed Zulip%s from %s" % (plural_messages, sender_str)
|
||||
if len(senders) > 1:
|
||||
from_email = '"%s (via Zulip)" <%s>' % (sender_str, settings.NOREPLY_EMAIL_ADDRESS)
|
||||
else:
|
||||
from_email = 'Zulip <%s>' % (settings.NOREPLY_EMAIL_ADDRESS,)
|
||||
if len(senders) == 1 and settings.SEND_MISSED_MESSAGE_EMAILS_AS_USER:
|
||||
# If this setting is enabled, you can reply to the Zulip
|
||||
# missed message emails directly back to the original sender.
|
||||
# However, one must ensure the Zulip server is in the SPF
|
||||
# record for the domain, or there will be spam/deliverability
|
||||
# problems.
|
||||
headers['Sender'] = from_email
|
||||
sender = missed_messages[0].sender
|
||||
from_email = '"%s" <%s>' % (sender_str, sender.email)
|
||||
headers['Sender'] = "Zulip <%s>" % (settings.NOREPLY_EMAIL_ADDRESS,)
|
||||
|
||||
text_content = loader.render_to_string('zerver/missed_message_email.txt', template_payload)
|
||||
html_content = loader.render_to_string('zerver/missed_message_email_html.txt', template_payload)
|
||||
|
@@ -6,7 +6,7 @@ from typing import Any, Callable, Dict, Iterable, List, Mapping, Tuple, TypeVar
|
||||
from mock import patch, MagicMock
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, override_settings
|
||||
|
||||
from zerver.lib.test_helpers import (
|
||||
queries_captured, simulated_empty_cache,
|
||||
@@ -1989,12 +1989,16 @@ class ExtractedRecipientsTest(TestCase):
|
||||
self.assertEqual(sorted(extract_recipients(s)), ['alice@zulip.com', 'bob@zulip.com'])
|
||||
|
||||
|
||||
# TODO: This class currently only tests the default-off
|
||||
# SEND_MISSED_MESSAGE_EMAILS_AS_USER=True case. We should refactor it
|
||||
# to test both cases (the False case being the most important).
|
||||
class TestMissedMessages(ZulipTestCase):
|
||||
def normalize_string(self, s):
|
||||
# type: (text_type) -> text_type
|
||||
s = s.strip()
|
||||
return re.sub(r'\s+', ' ', s)
|
||||
|
||||
@override_settings(SEND_MISSED_MESSAGE_EMAILS_AS_USER=True)
|
||||
@patch('zerver.lib.email_mirror.generate_random_token')
|
||||
def test_extra_context_in_missed_stream_messages(self, mock_random_token):
|
||||
# type: (MagicMock) -> None
|
||||
@@ -2033,6 +2037,7 @@ class TestMissedMessages(ZulipTestCase):
|
||||
self.normalize_string(mail.outbox[0].body),
|
||||
)
|
||||
|
||||
@override_settings(SEND_MISSED_MESSAGE_EMAILS_AS_USER=True)
|
||||
@patch('zerver.lib.email_mirror.generate_random_token')
|
||||
def test_extra_context_in_personal_missed_stream_messages(self, mock_random_token):
|
||||
# type: (MagicMock) -> None
|
||||
@@ -2059,6 +2064,7 @@ class TestMissedMessages(ZulipTestCase):
|
||||
self.assertIn('You and Othello, the Moor of Venice Extremely personal message!',
|
||||
self.normalize_string(msg.body))
|
||||
|
||||
@override_settings(SEND_MISSED_MESSAGE_EMAILS_AS_USER=True)
|
||||
@patch('zerver.lib.email_mirror.generate_random_token')
|
||||
def test_extra_context_in_huddle_missed_stream_messages(self, mock_random_token):
|
||||
# type: (MagicMock) -> None
|
||||
|
@@ -142,6 +142,7 @@ DEFAULT_SETTINGS = {'TWITTER_CONSUMER_KEY': '',
|
||||
'INLINE_IMAGE_PREVIEW': True,
|
||||
'CAMO_URI': '',
|
||||
'ENABLE_FEEDBACK': PRODUCTION,
|
||||
'SEND_MISSED_MESSAGE_EMAILS_AS_USER': False,
|
||||
'SERVER_EMAIL': None,
|
||||
'FEEDBACK_EMAIL': None,
|
||||
'WELCOME_EMAIL_SENDER': None,
|
||||
|
Reference in New Issue
Block a user