mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41: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):
|
||||
for content, mimetype in alternatives:
|
||||
self.add_alternative(content, mimetype)
|
||||
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)
|
||||
|
||||
def add_alternative(self, content, mimetype):
|
||||
raise NotImplementedError("%s.%s must implement add_alternative or set_alternatives" %
|
||||
(self.__class__.__module__, self.__class__.__name__))
|
||||
self.unsupported_feature("alternative part with type '%s'" % mimetype)
|
||||
|
||||
def set_attachments(self, attachments):
|
||||
for attachment in attachments:
|
||||
|
||||
@@ -117,15 +117,10 @@ class MandrillPayload(RequestsPayload):
|
||||
self.data["message"]["text"] = body
|
||||
|
||||
def set_html_body(self, body):
|
||||
self.data["message"]["html"] = body
|
||||
|
||||
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"]:
|
||||
if "html" in self.data["message"]:
|
||||
# second html body could show up through multiple alternatives, or html body + alternative
|
||||
self.unsupported_feature("multiple html parts")
|
||||
else:
|
||||
self.set_html_body(content)
|
||||
self.data["message"]["html"] = body
|
||||
|
||||
def add_attachment(self, attachment):
|
||||
key = "images" if attachment.inline else "attachments"
|
||||
|
||||
Reference in New Issue
Block a user