diff --git a/README.rst b/README.rst index c60108f..368749f 100644 --- a/README.rst +++ b/README.rst @@ -144,10 +144,7 @@ Djrill supports most of the functionality of Django's `EmailMessage`_ and for logging. To send a single message to multiple recipients without exposing their email addresses to each other, simply include them all in the "to" list and leave ``preserve_recipients`` set to False.) -* **Attachments:** Djrill includes a message's attachments, but only with the - mimetypes "text/\*", "image/\*", or "application/pdf" (since that is all - Mandrill allows). Any other attachment types will raise - ``djrill.NotSupportedByMandrillError`` when you attempt to send the message. +* **Attachments:** Djrill includes a message's attachments. * **Headers:** Djrill accepts additional headers, but only ``Reply-To`` and ``X-*`` (since that is all that Mandrill accepts). Any other extra headers will raise ``djrill.NotSupportedByMandrillError`` when you attempt to send the diff --git a/djrill/mail/backends/djrill.py b/djrill/mail/backends/djrill.py index ddf1937..74e835d 100644 --- a/djrill/mail/backends/djrill.py +++ b/djrill/mail/backends/djrill.py @@ -233,18 +233,6 @@ class DjrillBackend(BaseEmailBackend): if mimetype is None: mimetype = DEFAULT_ATTACHMENT_MIME_TYPE - # Mandrill silently filters attachments with unsupported mimetypes. - # This can be confusing, so we raise an exception instead. - (main, sub) = mimetype.lower().split('/') - attachment_allowed = ( - main == 'text' or main == 'image' - or (main == 'application' and sub == 'pdf')) - if not attachment_allowed: - raise NotSupportedByMandrillError( - "Invalid attachment mimetype '%s'. Mandrill only supports " - "text/*, image/*, and application/pdf attachments." - % mimetype) - try: content_b64 = b64encode(content) except TypeError: diff --git a/djrill/tests/test_mandrill_send.py b/djrill/tests/test_mandrill_send.py index bd875da..43ea351 100644 --- a/djrill/tests/test_mandrill_send.py +++ b/djrill/tests/test_mandrill_send.py @@ -114,6 +114,11 @@ class DjrillBackendTests(DjrillBackendMockAPITestCase): mimeattachment.set_payload(pdf_content) email.attach(mimeattachment) + # Attachment type that wasn't supported in early Mandrill releases: + ppt_content = b"PPT\xb4 pretend this is a valid ppt file" + email.attach(filename="presentation.ppt", content=ppt_content, + mimetype="application/vnd.ms-powerpoint") + email.send() def decode_att(att): @@ -121,7 +126,7 @@ class DjrillBackendTests(DjrillBackendMockAPITestCase): data = self.get_api_call_data() attachments = data['message']['attachments'] - self.assertEqual(len(attachments), 3) + self.assertEqual(len(attachments), 4) self.assertEqual(attachments[0]["type"], "text/plain") self.assertEqual(attachments[0]["name"], "test.txt") self.assertEqual(decode_att(attachments[0]["content"]).decode('ascii'), @@ -132,6 +137,10 @@ class DjrillBackendTests(DjrillBackendMockAPITestCase): self.assertEqual(attachments[2]["type"], "application/pdf") self.assertEqual(attachments[2]["name"], "") # none self.assertEqual(decode_att(attachments[2]["content"]), pdf_content) + self.assertEqual(attachments[3]["type"], + "application/vnd.ms-powerpoint") + self.assertEqual(attachments[3]["name"], "presentation.ppt") + self.assertEqual(decode_att(attachments[3]["content"]), ppt_content) def test_extra_header_errors(self): email = mail.EmailMessage('Subject', 'Body', 'from@example.com', @@ -174,24 +183,6 @@ class DjrillBackendTests(DjrillBackendMockAPITestCase): msg="Mandrill API should not be called when send fails silently") self.assertEqual(sent, 0) - def test_attachment_errors(self): - # Mandrill silently strips attachments that aren't text/*, image/*, - # or application/pdf. We want to alert the Djrill user: - with self.assertRaises(NotSupportedByMandrillError): - msg = mail.EmailMessage('Subject', 'Body', - 'from@example.com', ['to@example.com']) - # This is the default mimetype, but won't work with Mandrill: - msg.attach(content="test", mimetype="application/octet-stream") - msg.send() - - with self.assertRaises(NotSupportedByMandrillError): - msg = mail.EmailMessage('Subject', 'Body', - 'from@example.com', ['to@example.com']) - # Can't send Office docs, either: - msg.attach(filename="presentation.ppt", content="test", - mimetype="application/vnd.ms-powerpoint") - msg.send() - def test_bcc_errors(self): # Mandrill only allows a single bcc address with self.assertRaises(NotSupportedByMandrillError):