Fixed #27469 -- Prevented sending email to empty addresses
Thanks Jarek Glowacki for the report.
This commit is contained in:
parent
ac0cf97cb4
commit
8858631498
|
@ -328,7 +328,7 @@ class EmailMessage(object):
|
||||||
Returns a list of all recipients of the email (includes direct
|
Returns a list of all recipients of the email (includes direct
|
||||||
addressees as well as Cc and Bcc entries).
|
addressees as well as Cc and Bcc entries).
|
||||||
"""
|
"""
|
||||||
return self.to + self.cc + self.bcc
|
return [email for email in (self.to + self.cc + self.bcc) if email]
|
||||||
|
|
||||||
def send(self, fail_silently=False):
|
def send(self, fail_silently=False):
|
||||||
"""Sends the email message."""
|
"""Sends the email message."""
|
||||||
|
|
|
@ -100,6 +100,22 @@ class MailTests(HeadersCheckMixin, SimpleTestCase):
|
||||||
self.assertEqual(message['From'], 'from@example.com')
|
self.assertEqual(message['From'], 'from@example.com')
|
||||||
self.assertEqual(message['To'], 'to@example.com, other@example.com')
|
self.assertEqual(message['To'], 'to@example.com, other@example.com')
|
||||||
|
|
||||||
|
def test_recipients_with_empty_strings(self):
|
||||||
|
"""
|
||||||
|
Empty strings in various recipient arguments are always stripped
|
||||||
|
off the final recipient list.
|
||||||
|
"""
|
||||||
|
email = EmailMessage(
|
||||||
|
'Subject', 'Content', 'from@example.com', ['to@example.com', ''],
|
||||||
|
cc=['cc@example.com', ''],
|
||||||
|
bcc=['', 'bcc@example.com'],
|
||||||
|
reply_to=['', None],
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
email.recipients(),
|
||||||
|
['to@example.com', 'cc@example.com', 'bcc@example.com']
|
||||||
|
)
|
||||||
|
|
||||||
def test_cc(self):
|
def test_cc(self):
|
||||||
"""Regression test for #7722"""
|
"""Regression test for #7722"""
|
||||||
email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com'], cc=['cc@example.com'])
|
email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com'], cc=['cc@example.com'])
|
||||||
|
|
Loading…
Reference in New Issue