Closed martinezleoml closed 1 year ago
Thanks for investigating, and for including a full raw email demonstrating the problem.
My initial reaction was, Apple Mail is doing something weird, so yeah, whatever workaround makes sense. But the more I investigated, Apple Mail's use of multipart/mixed to interleave text/plain and inline image parts is a valid approach. The inline images don't need content-ids, because they're not being referenced elsewhere, and multipart/mixed is defined to present its parts in sequential order. (See RFC 2046 section 5.1.3—and W3C's older version that clarifies multipart/mixed children are "intended to be displayed serially." Also RFC 2183 sections 2.1-2.2 which specify content-disposition.)
Arguably, Gmail is doing the wrong thing by presenting the inline images at the end of the message as attachments.
I think the bug here is that Anymail's inline_attachments
doesn't include these inline images that don't have content-ids, even though they are inline content. (And in fact, it can't, because inline_attachments
is actually a dict mapping content-id to MIMEPart.)
The underlying problem is that Anymail's inline_attachments
dict doesn't parallel its attachments
list, leading to understandable confusion. (Something similar came up in #229.) Also "inline attachment" isn't really a thing—a MIMEPart is either inline or an attachment (or neither), never both.
Proposal:
inline_attachments
to content_id_map
(or cid_map
?), reflecting what it actually implements. (Keep inline_attachments
as a deprecated alias for content_id_map
, issuing a warning on use.)is_inline_attachment()
to is_inline()
. (And keep the original as a deprecated alias.)inlines
list property that returns a sequence of parts that are inline (paralleling the behavior of attachments
).is_attachment()
(via MIMEPart), get rid of the AnymailInboundMessage version.Thanks for the follow up @medmunds.
I was not sure what was the intended behaviour between displaying images inline or consider it as raw attachments, so thanks for clarifying this. 🙂
Your proposal works for me! Would you want some help to refactor?
Would you want some help to refactor?
Yes, please! If you want to open a PR with any or all of the above, that would be much appreciated.
@medmunds Here is a start #330 ;)
Resolved by #330.
Hi there!
We've figured out that inbound email processing of emails sent through Apple Mail app (tested on macOS) resulted on inline attachments (like images) not being taken into account at all by django-anymail.
Reproduction
Send a basic email with picture(s) using Apple Mail:
Copy-paste the resulting raw message content (sent by Apple Mail) into a file named
message.raw
:--Apple-Mail=_B8C68BCC-061A-452F-A5CD-474B952DC8B5 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii
Some text before rectangle
--Apple-Mail=_B8C68BCC-061A-452F-A5CD-474B952DC8B5 Content-Disposition: inline; filename=rectangle.png Content-Type: image/png; x-unix-mode=0644; name="rectangle.png" Content-Transfer-Encoding: base64
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA AXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAQSURBVHgBAQUA+v8AAAAA/wEEAQB5fl4xAAAA AElFTkSuQmCC
--Apple-Mail=_B8C68BCC-061A-452F-A5CD-474B952DC8B5 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii
Some text after rectangle --Apple-Mail=_B8C68BCC-061A-452F-A5CD-474B952DC8B5--
The output shows that no attachment or inline attachment has been detected, even if we can read the attachment walking through message parts:
Resolution
I think that "inline attachments" without a
Content-ID
header should be considered as regular attachments, as Gmail do when receiving this kind of email: