This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: EmailMessage may lack Mime-Version
Type: behavior Stage:
Components: email Versions: Python 3.10, Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Vlastimil.Zíma, barry, r.david.murray
Priority: normal Keywords:

Created on 2022-03-28 12:26 by Vlastimil.Zíma, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg416163 - (view) Author: Vlastimil Zíma (Vlastimil.Zíma) Date: 2022-03-28 12:26
When an `EmailMessage` is created without setting its content, it may lack the `MIME-Version` header. I encountered this behavior when creating a S/MIME signed message, but I believe it applies to any `EmailMessage` in general.


from email.message import EmailMessage

nested_message = EmailMessage()

env = EmailMessage()
env.add_header("Content-Type", "multipart/signed", protocol="application/pkcs7-signature", micalg='sha-256')
env.preamble = "This is an S/MIME signed message"

This results in a message with no `MIME-Version` header

Content-Type: multipart/signed; protocol="application/pkcs7-signature";
 micalg="sha-256"; boundary="===============4414940364499332856=="

This is an S/MIME signed message
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0



which violates section 4 of RFC 2045, see

> Messages composed in accordance with this document MUST include such
   a header field, with the following verbatim text:

     MIME-Version: 1.0

and the section doesn't seem to be obsoleted by newer MIME related RFCs.

It's not clear why the `EmailMessage` shouldn't have the `MIME-Version` header defined in all cases, since it should represent the email message. I suggest to set the `MIME-version` header on `__init__` the same way `MIMEBase` does.
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91297
2022-03-28 12:26:22Vlastimil.Zímacreate