Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion anymail/inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ def _get_body_content(self, content_type):

# Hoisted from email.message.MIMEPart
def is_attachment(self):
return self.get_content_disposition() == "attachment"
return self.get_content_disposition() == "attachment" or (
self.get_content_disposition() == "inline" and self["Content-ID"] is None
)

# New for Anymail
def is_inline_attachment(self):
Expand Down
27 changes: 27 additions & 0 deletions tests/test_inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,33 @@ def test_attachment_as_uploaded_file_security(self):
self.assertEqual(attachments[1].get_filename(), "../static/index.html")
self.assertEqual(attachments[1].as_uploaded_file().name, "index.html")

def test_attachment_issued_by_apple_mail(self):
# Attachments issued by Apple Mail client are sometimes included as inline
# attachments without Content-ID. They should then be considered as regular
# attachments.
raw = dedent(
"""\
MIME-Version: 1.0
Subject: Attachment test
Content-Type: multipart/mixed; boundary="this_is_a_boundary"

--this_is_a_boundary
Content-Disposition: inline; filename=pixel.png
Content-Type: image/png; x-unix-mode=0644; name="pixel.png"
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA
AXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAQSURBVHgBAQUA+v8AAAAA/wEEAQB5fl4xAAAA
AElFTkSuQmCC
--this_is_a_boundary
"""
)
msg = AnymailInboundMessage.parse_raw_mime(raw)
attachments = msg.attachments

self.assertEqual(attachments[0].get_filename(), "pixel.png")
self.assertEqual(attachments[0].get_content_type(), "image/png")


class AnymailInboundMessageAttachedMessageTests(SimpleTestCase):
# message/rfc822 attachments should get parsed recursively
Expand Down