mirror of https://github.com/django/django.git
Merge pull request #991 from stockr-labs/feature/email-backends-generators
Fixed #20194 -- Adds generators support for email backends that do not support it.
This commit is contained in:
commit
5ac7f777cd
|
@ -16,6 +16,7 @@ class EmailBackend(BaseEmailBackend):
|
||||||
"""Write all messages to the stream in a thread-safe way."""
|
"""Write all messages to the stream in a thread-safe way."""
|
||||||
if not email_messages:
|
if not email_messages:
|
||||||
return
|
return
|
||||||
|
msg_count = 0
|
||||||
with self._lock:
|
with self._lock:
|
||||||
try:
|
try:
|
||||||
stream_created = self.open()
|
stream_created = self.open()
|
||||||
|
@ -24,9 +25,10 @@ class EmailBackend(BaseEmailBackend):
|
||||||
self.stream.write('-' * 79)
|
self.stream.write('-' * 79)
|
||||||
self.stream.write('\n')
|
self.stream.write('\n')
|
||||||
self.stream.flush() # flush after each message
|
self.stream.flush() # flush after each message
|
||||||
|
msg_count += 1
|
||||||
if stream_created:
|
if stream_created:
|
||||||
self.close()
|
self.close()
|
||||||
except:
|
except:
|
||||||
if not self.fail_silently:
|
if not self.fail_silently:
|
||||||
raise
|
raise
|
||||||
return len(email_messages)
|
return msg_count
|
||||||
|
|
|
@ -6,4 +6,4 @@ from django.core.mail.backends.base import BaseEmailBackend
|
||||||
|
|
||||||
class EmailBackend(BaseEmailBackend):
|
class EmailBackend(BaseEmailBackend):
|
||||||
def send_messages(self, email_messages):
|
def send_messages(self, email_messages):
|
||||||
return len(email_messages)
|
return len(list(email_messages))
|
||||||
|
|
|
@ -20,7 +20,9 @@ class EmailBackend(BaseEmailBackend):
|
||||||
|
|
||||||
def send_messages(self, messages):
|
def send_messages(self, messages):
|
||||||
"""Redirect messages to the dummy outbox"""
|
"""Redirect messages to the dummy outbox"""
|
||||||
|
msg_count = 0
|
||||||
for message in messages: # .message() triggers header validation
|
for message in messages: # .message() triggers header validation
|
||||||
message.message()
|
message.message()
|
||||||
|
msg_count += 1
|
||||||
mail.outbox.extend(messages)
|
mail.outbox.extend(messages)
|
||||||
return len(messages)
|
return msg_count
|
||||||
|
|
Loading…
Reference in New Issue