I am working on my own email client (powered by Django 1.10 and Python 3).
Currently, I am trying to render inbox messages using python's IMAPClient library. It looks like I succeeded in parsing emails with mixed
and alternative
subtypes, but now I am stuck trying to render parts of the body with subtype relative
. That is, parts containing HTML with embedded inline
attachments.
Currently, I am going to download one-by-one all the inline images to my server using the respective fetch
command, and after than insert links on those images in the HTML of the target letter.
To illustrate, let's say email HTML representation contains an inline image:
...<td><img src="cid:part1.06030702.04060203@studinter.ru"></td>...
...and thebodystruture
part containing the inline image description looks like this:
(b'IMAGE', b'JPEG', (b'NAME', b'ban1.jpg'), b'<part1.06030702.04060203@studinter.ru>', None, b'BASE64', 15400, None, (b'INLINE', (b'FILENAME', b'ban1.jpg')), None)
So, in theory, I could download the image on my server, and replace the src
tag's value(namely, cid:part1.06030702.04060203@studinter.ru
) by the url of the image on my server.
My concern here is that this very process of inserting inline attachments into the target HTML message body is something that libraries like IMAPClient or python's email package have already implemented, and whether I am going to reinvent bicycle. I am completely lost in this topic.
The question is, do I really have to implement it on my own? If yes, is the described method appropriate? And if no, I would really appreciate a hint on how to do this with IMAPClient, or standard library's imaplib.