pmclanahan / django-celery-email

A Django email backend that uses a celery task for sending the email.
BSD 3-Clause "New" or "Revised" License
477 stars 108 forks source link

Fix attachments with a "text/*" mimetype failing to be decoded. #50

Closed canassa closed 6 years ago

canassa commented 6 years ago

For emails attachments contains a mimetype starting with text/, Django expects the content to be a string. This behavior is documented in here:

https://docs.djangoproject.com/en/2.0/topics/email/#emailmessage-objects

This causes both the email_to_dict and dict_to_email function to fail. email_to_dict fails because the attachment returned by Django is a string and not bytes, and dict_to_email fails because Django itself complains if you try to send an email with a text/* mimetype and a binary content.

This causes the a bytes-like object is required, not 'str' error to be raised at this line

I added workarounds to both functions and a regression test.

pmclanahan commented 6 years ago

Looks good to me. Thoughts @poxip ?

bertonha commented 6 years ago

Any news on this issue?

pmclanahan commented 6 years ago

I see no reason to block it. I'll merge.