mirror of https://github.com/django/django.git
Fixed #24416 -- Added support for lazy email addresses.
This commit is contained in:
parent
d8de9a64d7
commit
5993b52e6d
|
@ -101,7 +101,7 @@ def forbid_multi_line_headers(name, val, encoding):
|
||||||
|
|
||||||
|
|
||||||
def sanitize_address(addr, encoding):
|
def sanitize_address(addr, encoding):
|
||||||
if isinstance(addr, six.string_types):
|
if not isinstance(addr, tuple):
|
||||||
addr = parseaddr(force_text(addr))
|
addr = parseaddr(force_text(addr))
|
||||||
nm, addr = addr
|
nm, addr = addr
|
||||||
nm = Header(nm, encoding).encode()
|
nm = Header(nm, encoding).encode()
|
||||||
|
@ -262,11 +262,11 @@ class EmailMessage(object):
|
||||||
msg = self._create_message(msg)
|
msg = self._create_message(msg)
|
||||||
msg['Subject'] = self.subject
|
msg['Subject'] = self.subject
|
||||||
msg['From'] = self.extra_headers.get('From', self.from_email)
|
msg['From'] = self.extra_headers.get('From', self.from_email)
|
||||||
msg['To'] = self.extra_headers.get('To', ', '.join(self.to))
|
msg['To'] = self.extra_headers.get('To', ', '.join(map(force_text, self.to)))
|
||||||
if self.cc:
|
if self.cc:
|
||||||
msg['Cc'] = ', '.join(self.cc)
|
msg['Cc'] = ', '.join(map(force_text, self.cc))
|
||||||
if self.reply_to:
|
if self.reply_to:
|
||||||
msg['Reply-To'] = self.extra_headers.get('Reply-To', ', '.join(self.reply_to))
|
msg['Reply-To'] = self.extra_headers.get('Reply-To', ', '.join(map(force_text, self.reply_to)))
|
||||||
|
|
||||||
# Email header names are case-insensitive (RFC 2045), so we have to
|
# Email header names are case-insensitive (RFC 2045), so we have to
|
||||||
# accommodate that when doing comparisons.
|
# accommodate that when doing comparisons.
|
||||||
|
|
|
@ -665,6 +665,31 @@ class BaseEmailBackendTests(HeadersCheckMixin, object):
|
||||||
self.assertEqual(message.get('from'), "tester")
|
self.assertEqual(message.get('from'), "tester")
|
||||||
self.assertEqual(message.get('to'), "django")
|
self.assertEqual(message.get('to'), "django")
|
||||||
|
|
||||||
|
def test_lazy_addresses(self):
|
||||||
|
"""
|
||||||
|
Email sending should support lazy email addresses (#24416).
|
||||||
|
"""
|
||||||
|
_ = ugettext_lazy
|
||||||
|
self.assertTrue(send_mail('Subject', 'Content', _('tester'), [_('django')]))
|
||||||
|
message = self.get_the_message()
|
||||||
|
self.assertEqual(message.get('from'), 'tester')
|
||||||
|
self.assertEqual(message.get('to'), 'django')
|
||||||
|
|
||||||
|
self.flush_mailbox()
|
||||||
|
m = EmailMessage(
|
||||||
|
'Subject', 'Content', _('tester'), [_('to1'), _('to2')],
|
||||||
|
cc=[_('cc1'), _('cc2')],
|
||||||
|
bcc=[_('bcc')],
|
||||||
|
reply_to=[_('reply')],
|
||||||
|
)
|
||||||
|
self.assertEqual(m.recipients(), ['to1', 'to2', 'cc1', 'cc2', 'bcc'])
|
||||||
|
m.send()
|
||||||
|
message = self.get_the_message()
|
||||||
|
self.assertEqual(message.get('from'), 'tester')
|
||||||
|
self.assertEqual(message.get('to'), 'to1, to2')
|
||||||
|
self.assertEqual(message.get('cc'), 'cc1, cc2')
|
||||||
|
self.assertEqual(message.get('Reply-To'), 'reply')
|
||||||
|
|
||||||
def test_close_connection(self):
|
def test_close_connection(self):
|
||||||
"""
|
"""
|
||||||
Test that connection can be closed (even when not explicitly opened)
|
Test that connection can be closed (even when not explicitly opened)
|
||||||
|
|
Loading…
Reference in New Issue