pmclanahan/django-celery-email — pull request #5 by daxtens (2014-02-19 22:37:22+00:00)
Title: Support Celery's JSON serializer

This supports the use of Celery's JSON serializer, which [improves the security of Celery](http://celery.readthedocs.org/en/latest/userguide/security.html#serializers).

Prior to this patch, attempting to use Celery with the JSON serialization (as opposed to pickling) generated error messages complaining that a `django.core.mail.EmailMessage` is not JSON serializable. This patch converts email messages to dictionaries which are JSON serializable.

**For those still using the `pickle` serializer, everything should continue to work the same.**

### Caveat on JSON-serializing attachments

This patch copies the `attachments` property of EmailMessages without further processing. Per [https://docs.djangoproject.com/en/dev/topics/email/#emailmessage-objects](the Django docs on EmailMessage objects), attachments are:
> either `email.MIMEBase.MIMEBase instances`, or `(filename, content, mimetype)` triples.

As I understand it, this means that **attachments as `MIMEBase` instances will still fail**, but the triples may succeed. My application doesn't send attachments at the moment, so I haven't tested this. If in the deep distant future I get the opportunity to test it I will extend the patch.

**Attachments will still work for those using pickling.** In the mean time, this patch still enhances support for those using JSON - instead of everything failing, only a limited subset of things fail.