emails: Groundwork to personalize reply-to name of missed message emails.

This commit is contained in:
Rishi Gupta 2017-06-26 13:43:32 -04:00 committed by Tim Abbott
parent 388cef900e
commit 1291ac9eff
4 changed files with 16 additions and 8 deletions

View File

@ -17,6 +17,7 @@ from zerver.lib.redis_utils import get_redis_client
from zerver.lib.upload import upload_message_image
from zerver.lib.utils import generate_random_token
from zerver.lib.str_utils import force_text
from zerver.lib.send_email import FromAddress
from zerver.models import Stream, Recipient, \
get_user_profile_by_id, get_display_recipient, get_recipient, \
Message, Realm, UserProfile, get_system_bot
@ -105,7 +106,7 @@ def create_missed_message_address(user_profile, message):
if settings.EMAIL_GATEWAY_PATTERN == '':
logging.warning("EMAIL_GATEWAY_PATTERN is an empty string, using "
"NOREPLY_EMAIL_ADDRESS in the 'from' field.")
return settings.NOREPLY_EMAIL_ADDRESS.split()[-1]
return FromAddress.NOREPLY
if message.recipient.type == Recipient.PERSONAL:
# We need to reply to the sender so look up their personal recipient_id

View File

@ -274,7 +274,11 @@ def do_send_missedmessage_events_reply_in_zulip(user_profile, missed_messages, m
})
from zerver.lib.email_mirror import create_missed_message_address
address = create_missed_message_address(user_profile, missed_messages[0])
reply_to_address = create_missed_message_address(user_profile, missed_messages[0])
if reply_to_address == FromAddress.NOREPLY:
reply_to_name = None
else:
reply_to_name = "Zulip"
senders = list(set(m.sender for m in missed_messages))
if (missed_messages[0].recipient.type == Recipient.HUDDLE):
@ -323,12 +327,13 @@ def do_send_missedmessage_events_reply_in_zulip(user_profile, missed_messages, m
'reply_warning': False,
'reply_to_zulip': False,
})
email_dict = {
'template_prefix': 'zerver/emails/missed_message',
'to_email': display_email(user_profile),
'from_name': from_name,
'from_address': from_address,
'reply_to_email': address,
'reply_to_email': formataddr((reply_to_name, reply_to_address)),
'context': context}
queue_json_publish("missedmessage_email_senders", email_dict, send_email_from_dict)

View File

@ -31,7 +31,7 @@ from zerver.lib.email_mirror import (
)
from zerver.lib.digest import handle_digest_email
from zerver.lib.send_email import FromAddress
from zerver.lib.notifications import (
handle_missedmessage_emails,
)
@ -253,7 +253,7 @@ class TestEmptyGatewaySetting(ZulipTestCase):
usermessage = most_recent_usermessage(user_profile)
with self.settings(EMAIL_GATEWAY_PATTERN=''):
mm_address = create_missed_message_address(user_profile, usermessage.message)
self.assertEqual(mm_address, settings.NOREPLY_EMAIL_ADDRESS)
self.assertEqual(mm_address, FromAddress.NOREPLY)
def test_encode_email_addr(self):
# type: () -> None

View File

@ -18,6 +18,7 @@ from zerver.lib.notifications import handle_missedmessage_emails
from zerver.lib.actions import render_incoming_message, do_update_message
from zerver.lib.message import access_message
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.send_email import FromAddress
from zerver.models import (
Recipient,
UserMessage,
@ -41,17 +42,18 @@ class TestMissedMessages(ZulipTestCase):
handle_missedmessage_emails(hamlet.id, [{'message_id': msg_id}])
if settings.EMAIL_GATEWAY_PATTERN != "":
reply_to_addresses = [settings.EMAIL_GATEWAY_PATTERN % (u'mm' + t) for t in tokens]
reply_to_emails = [formataddr(("Zulip", address)) for address in reply_to_addresses]
else:
reply_to_addresses = ["noreply@zulip.example.com"]
reply_to_emails = ["noreply@zulip.example.com"]
msg = mail.outbox[0]
from_email = formataddr(("Zulip", settings.NOREPLY_EMAIL_ADDRESS))
from_email = formataddr(("Zulip", FromAddress.NOREPLY))
self.assertEqual(len(mail.outbox), 1)
if send_as_user:
from_email = '"%s" <%s>' % (othello.full_name, othello.email)
self.assertEqual(msg.from_email, from_email)
self.assertEqual(msg.subject, subject)
self.assertEqual(len(msg.reply_to), 1)
self.assertIn(msg.reply_to[0], reply_to_addresses)
self.assertIn(msg.reply_to[0], reply_to_emails)
self.assertIn(body, self.normalize_string(msg.body))
@patch('zerver.lib.email_mirror.generate_random_token')