Title: behaviour change with EmailMessage.set_content
Type: Stage: resolved
Components: email Versions: Python 3.8
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: barry, bremner, doko, ivyl, lukasz.langa, maxking, r.david.murray, xtreak
Priority: release blocker Keywords: 3.8regression, 3.9regression, patch

Created on 2020-07-03 23:14 by bremner, last changed 2020-07-09 00:13 by maxking. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 21349 closed xtreak, 2020-07-06 12:56
Messages (10)
msg372971 - (view) Author: David Bremner (bremner) Date: 2020-07-03 23:14
Works in 3.8.3, but not in 3.8.4rc1

from email.message import EmailMessage
msg = EmailMessage()

Apparently now at least one newline is required.
msg372979 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-07-04 04:47
This is caused due to c1f1ddf30a595c2bfa3c06e54fb03fa212cd28b5 introduced as part of bpo-40597 which is reported back in the issue with
msg373080 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2020-07-06 09:12
that's a regression for the 3.8 branch, marking as a release blocker for 3.8.4.  This should be a documented change for 3.9, and probably reverted/fixed for 3.8.
msg373099 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2020-07-06 11:54
Good catch!

No need to revert anything. The raised ValueError is a relatively simple thing to fix. xtreak, mind making a follow-up PR to restore behavior with no \n characters?
msg373101 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-07-06 11:59
Sure, I guess the fix would be to check for lines to be non-empty before doing a call to max and also convert the report as a test case?
msg373110 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-07-06 12:32
There is a behavior change with my fix. 7bit is returned for Content-Transfer-Encoding before commit and skipping the heuristic if line is empty to avoid ValueError will return quoted-printable for Content-Transfer-Encoding. This is a behavior change even if the ValueError is fixed. I would like to confirm which is the correct behavior and to be documented appropriately.

Test Case in : 

    def test_set_text_plain_empty_content_heuristics(self):
        m = self._make_message()
        content = ""
        raw_data_manager.set_content(m, content)
        self.assertEqual(str(m), textwrap.dedent("""\                             
            Content-Type: text/plain; charset="utf-8"                             
            Content-Transfer-Encoding: quoted-printable                           
        self.assertEqual(m.get_payload(decode=True).decode('utf-8'), "\n")
        self.assertEqual(m.get_content(), "\n")
msg373113 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2020-07-06 12:41
msg373115 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-07-06 13:05
Łukasz, There is already a PR open for this from May linking to original issue at . I missed it during triaging this issue. I guess someone needs to approve that PR and merge it to master to backport to 3.9 and 3.8 to fix the error.
msg373248 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2020-07-07 21:11
I'm short of time, if someone could approve Mark's PR and merge it it would be great. There wasn't supposed to be any behavior change other than the one documented in #40597.
msg373361 - (view) Author: Abhilash Raj (maxking) * (Python committer) Date: 2020-07-09 00:13
I have merged and backported to 3.8 and 3.9 branches ( &

Closing this issue.
Date User Action Args
2020-07-09 00:13:38maxkingsetstatus: open -> closed
resolution: fixed
messages: + msg373361

stage: patch review -> resolved
2020-07-07 21:11:53r.david.murraysetmessages: + msg373248
2020-07-06 13:05:58xtreaksetmessages: + msg373115
2020-07-06 12:56:46xtreaksetkeywords: + patch
stage: patch review
pull_requests: + pull_request20495
2020-07-06 12:41:31lukasz.langasetmessages: + msg373113
2020-07-06 12:32:21xtreaksetnosy: + maxking
messages: + msg373110
2020-07-06 11:59:09xtreaksetmessages: + msg373101
2020-07-06 11:54:13lukasz.langasetmessages: + msg373099
2020-07-06 09:12:33dokosetpriority: normal -> release blocker

nosy: + lukasz.langa, doko
messages: + msg373080

keywords: + 3.8regression, 3.9regression
2020-07-06 09:10:59dokosetnosy: + ivyl
2020-07-04 04:47:24xtreaksetnosy: + xtreak
messages: + msg372979
2020-07-03 23:14:58bremnercreate