Fixed crasher when sending rfc822 messages as attachments. (#59)

This commit is contained in:
Luke Plant
2017-04-15 21:45:32 +03:00
committed by Mike Edmunds
parent 7b010ab224
commit 7d7448011b
3 changed files with 33 additions and 2 deletions

View File

@@ -171,6 +171,12 @@ class Attachment(object):
if isinstance(attachment, MIMEBase):
self.name = attachment.get_filename()
self.content = attachment.get_payload(decode=True)
if self.content is None:
if hasattr(attachment, 'as_bytes'):
self.content = attachment.as_bytes()
else:
# Python 2.7 fallback
self.content = attachment.as_string().encode(self.encoding)
self.mimetype = attachment.get_content_type()
if get_content_disposition(attachment) == 'inline':