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.

classification
Title: Email does not apply policy to multipart messages with defects
Type: Stage:
Components: email Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: barry, jishac, mdengler, r.david.murray
Priority: normal Keywords:

Created on 2021-04-12 20:17 by jishac, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
email.multipart.test.py jishac, 2021-04-12 20:17 Test script to reproduce the issue
Messages (2)
msg390897 - (view) Author: Joseph Ishac (jishac) Date: 2021-04-12 20:17
I have noticed an issue (Python 3.8.5) where an email can be read in as bytes, but will not be returned as such with the as_bytes() call if the message is multipart, has a boundary which is not properly quoted, and the message has non-ascii text. It seems to be a result of how multipart messages are treated if the NoBoundaryInMultipartDefect is encountered [See Test #1].

I would argue that attempting to output the test message in the sample script with an 8bit, utf-8 enabled policy should return the original bytes as the 8bit policy should be applied to the "body" portion (any part after the null lines) of the email (as would be the case if it were not multipart) [See Test #4]

Currently it appears that the entire message is treated as headers, applying the strict 7bit, ascii requirement to the entire contents of the message. Furthermore, the msg.preamble is None.

I am also uncertain that attempting to leverage the handle_defect hooks would be helpful as correcting the boundary doesn't seem to work unless you re-parse the message [See Tests #2 and #3]

So the requested change would be to apply the encoding output policy to all portions of a message after the null line ending the headers.
msg416204 - (view) Author: Martin Dengler (mdengler) * Date: 2022-03-28 19:43
Possible related to https://github.com/python/cpython/pull/32137 and https://bugs.python.org/issue43323
History
Date User Action Args
2022-04-11 14:59:44adminsetgithub: 87984
2022-03-28 19:43:44mdenglersetmessages: + msg416204
2022-03-26 21:10:15mdenglersetnosy: + mdengler
2021-04-12 20:17:28jishaccreate