Fix: treat first text/plain alternative as plaintext body

Improve handling of alternative parts and `content_subtype`
to match how Django's SMTP backend handles some unusual cases.

Change Test backend to support (and record) text/* alternative
parts. (But still reject other types of alternatives.)

Fixes #252
This commit is contained in:
medmunds
2022-01-10 15:27:12 -08:00
committed by Mike Edmunds
parent 28247ec042
commit 60fbe1e896
4 changed files with 111 additions and 9 deletions

View File

@@ -107,7 +107,12 @@ class TestPayload(BasePayload):
self.params['html_body'] = body
def add_alternative(self, content, mimetype):
self.unsupported_feature("alternative part with type '%s'" % mimetype)
# For testing purposes, we allow all "text/*" alternatives,
# but not any other mimetypes.
if mimetype.startswith('text'):
self.params.setdefault('alternatives', []).append((content, mimetype))
else:
self.unsupported_feature("alternative part with type '%s'" % mimetype)
def add_attachment(self, attachment):
self.params.setdefault('attachments', []).append(attachment)