@@ -58,7 +58,7 @@ def render(self, context):
5858 self ._transform_markdown ()
5959 self ._transform_attachments ()
6060 self ._transform_attachment_references ()
61- self ._message .__setitem__ ('Date' , email .utils .formatdate ())
61+ self ._message .add_header ('Date' , email .utils .formatdate ())
6262 assert self ._sender
6363 assert self ._recipients
6464 assert self ._message
@@ -74,7 +74,9 @@ def _transform_encoding(self, raw_message):
7474
7575 def _transform_recipients (self ):
7676 """Extract sender and recipients from FROM, TO, CC and BCC fields."""
77- # Extract recipients
77+ # The docs recommend using __delitem__()
78+ # https://docs.python.org/3/library/email.message.html#email.message.EmailMessage.__delitem__
79+ # pylint: disable=unnecessary-dunder-call
7880 addrs = email .utils .getaddresses (self ._message .get_all ("TO" , [])) + \
7981 email .utils .getaddresses (self ._message .get_all ("CC" , [])) + \
8082 email .utils .getaddresses (self ._message .get_all ("BCC" , []))
@@ -87,15 +89,15 @@ def _make_message_multipart(self):
8789 Convert self._message into a multipart message.
8890
8991 Specifically, if the message's content-type is not multipart, this
90- method will create a new `multipart/mixed ` message, copy message
92+ method will create a new `multipart/related ` message, copy message
9193 headers and re-attach the original payload.
9294 """
9395 # Do nothing if message already multipart
9496 if self ._message .is_multipart ():
9597 return
9698
9799 # Create empty multipart message
98- multipart_message = email .mime .multipart .MIMEMultipart ('mixed ' )
100+ multipart_message = email .mime .multipart .MIMEMultipart ('related ' )
99101
100102 # Copy headers. Avoid duplicate Content-Type and MIME-Version headers,
101103 # which we set explicitely. MIME-Version was set when we created an
@@ -128,13 +130,13 @@ def _transform_markdown(self):
128130 Specifically, if the message's content-type is `text/markdown`, we
129131 transform `self._message` to have the following structure:
130132
131- multipart/mixed
133+ multipart/related
132134 └── multipart/alternative
133135 ├── text/plain (original markdown plaintext)
134136 └── text/html (converted markdown)
135137
136138 Attachments should be added as subsequent payload items of the
137- top-level `multipart/mixed ` message.
139+ top-level `multipart/related ` message.
138140 """
139141 # Do nothing if Content-Type is not text/markdown
140142 if not self ._message ['Content-Type' ].startswith ("text/markdown" ):
@@ -186,11 +188,11 @@ def _transform_attachments(self):
186188 """
187189 Parse attachment headers and generate content-id headers for each.
188190
189- Attachments are added to the payload of a `multipart/mixed ` message.
191+ Attachments are added to the payload of a `multipart/related ` message.
190192 For instance, a plaintext message with attachments would have the
191193 following structure:
192194
193- multipart/mixed
195+ multipart/related
194196 ├── text/plain
195197 ├── attachment1
196198 └── attachment2
@@ -199,7 +201,7 @@ def _transform_attachments(self):
199201 then the message would have the following structure after transforming
200202 markdown and attachments:
201203
202- multipart/mixed
204+ multipart/related
203205 ├── multipart/alternative
204206 │ ├── text/plain
205207 │ └── text/html
0 commit comments