email: Convert send_email to use formataddr.

Changed the requirements for UserProfile in order to allow use of
the formataddr function in send_mail.py.

Converted send_email to use formataddr in conjunction with the commit
that strengthened requirements for full_name, such that they can now be
used in the to field of emails.

Fixes #4676.
This commit is contained in:
Conner Bondurant
2019-06-28 22:41:13 -04:00
committed by Tim Abbott
parent c25dcf048d
commit 4d4b6b8319
3 changed files with 8 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
from contextlib import contextmanager
from email.utils import parseaddr
from typing import (cast, Any, Dict, Iterable, Iterator, List, Optional,
Tuple, Union, Set)
@@ -360,6 +361,7 @@ class ZulipTestCase(TestCase):
"""
if full_name is None:
full_name = email.replace("@", "_")
payload = {
'full_name': full_name,
'password': password,
@@ -383,7 +385,7 @@ class ZulipTestCase(TestCase):
# This is a bit of a crude heuristic, but good enough for most tests.
url_pattern = settings.EXTERNAL_HOST + r"(\S+)>"
for message in reversed(outbox):
if email_address in message.to:
if email_address in parseaddr(message.to)[1]:
return re.search(url_pattern, message.body).groups()[0]
else:
raise AssertionError("Couldn't find a confirmation email.")