mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
Normalize text/html alternative handling in BasePayload
This commit is contained in:
@@ -322,11 +322,16 @@ class BasePayload(object):
|
|||||||
|
|
||||||
def set_alternatives(self, alternatives):
|
def set_alternatives(self, alternatives):
|
||||||
for content, mimetype in alternatives:
|
for content, mimetype in alternatives:
|
||||||
|
if mimetype == "text/html":
|
||||||
|
# This assumes that there's at most one html alternative,
|
||||||
|
# and so it should be the html body. (Most ESPs don't
|
||||||
|
# support multiple html alternative parts anyway.)
|
||||||
|
self.set_html_body(content)
|
||||||
|
else:
|
||||||
self.add_alternative(content, mimetype)
|
self.add_alternative(content, mimetype)
|
||||||
|
|
||||||
def add_alternative(self, content, mimetype):
|
def add_alternative(self, content, mimetype):
|
||||||
raise NotImplementedError("%s.%s must implement add_alternative or set_alternatives" %
|
self.unsupported_feature("alternative part with type '%s'" % mimetype)
|
||||||
(self.__class__.__module__, self.__class__.__name__))
|
|
||||||
|
|
||||||
def set_attachments(self, attachments):
|
def set_attachments(self, attachments):
|
||||||
for attachment in attachments:
|
for attachment in attachments:
|
||||||
|
|||||||
@@ -117,15 +117,10 @@ class MandrillPayload(RequestsPayload):
|
|||||||
self.data["message"]["text"] = body
|
self.data["message"]["text"] = body
|
||||||
|
|
||||||
def set_html_body(self, body):
|
def set_html_body(self, body):
|
||||||
self.data["message"]["html"] = body
|
if "html" in self.data["message"]:
|
||||||
|
# second html body could show up through multiple alternatives, or html body + alternative
|
||||||
def add_alternative(self, content, mimetype):
|
|
||||||
if mimetype != 'text/html':
|
|
||||||
self.unsupported_feature("alternative part with mimetype '%s'" % mimetype)
|
|
||||||
elif "html" in self.data["message"]:
|
|
||||||
self.unsupported_feature("multiple html parts")
|
self.unsupported_feature("multiple html parts")
|
||||||
else:
|
self.data["message"]["html"] = body
|
||||||
self.set_html_body(content)
|
|
||||||
|
|
||||||
def add_attachment(self, attachment):
|
def add_attachment(self, attachment):
|
||||||
key = "images" if attachment.inline else "attachments"
|
key = "images" if attachment.inline else "attachments"
|
||||||
|
|||||||
Reference in New Issue
Block a user