Skip to content

bpo-41402: Fix email ContentManager calling .encode() on bytes#21631

Merged
ambv merged 3 commits intopython:mainfrom
joreiff:fix-email-bytes-7bit
Aug 9, 2021
Merged

bpo-41402: Fix email ContentManager calling .encode() on bytes#21631
ambv merged 3 commits intopython:mainfrom
joreiff:fix-email-bytes-7bit

Conversation

@joreiff
Copy link
Copy Markdown
Contributor

@joreiff joreiff commented Jul 26, 2020

If assigning binary content to an EmailMessage via set_content(), the function email.contentmanager.set_bytes_content() is called. This function fails when choosing the 7bit transfer encoding because of a call to data.decode('ascii'). Since bytes does not have a method .decode(), an exception is raised.

By changing data.decode('ascii') to data = data.encode('ascii'), we make sure that the input data really is 7bit and at the same time remove an inefficiency since set_payload() would have decoded the data anyway.

https://bugs.python.org/issue41402

@joreiff joreiff requested a review from a team as a code owner July 26, 2020 18:12
@the-knights-who-say-ni
Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@joreiff

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@joreiff
Copy link
Copy Markdown
Contributor Author

joreiff commented Aug 4, 2020

Is there anything else I need to do before this PR can be merged?

@joreiff
Copy link
Copy Markdown
Contributor Author

joreiff commented Sep 13, 2020

@bitdancer How does merging work? Do I need to do something regarding the Python 3.8 and 3.9 backports?

@ambv ambv added the needs backport to 3.10 only security fixes label Aug 9, 2021
@ambv ambv merged commit b33186b into python:main Aug 9, 2021
@miss-islington
Copy link
Copy Markdown
Contributor

Thanks @joreiff for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 9, 2021
…nGH-21631)

(cherry picked from commit b33186b)

Co-authored-by: Johannes Reiff <mail@jreiff.de>
@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Aug 9, 2021
@bedevere-bot
Copy link
Copy Markdown

GH-27686 is a backport of this pull request to the 3.10 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 9, 2021
…nGH-21631)

(cherry picked from commit b33186b)

Co-authored-by: Johannes Reiff <mail@jreiff.de>
@bedevere-bot
Copy link
Copy Markdown

GH-27687 is a backport of this pull request to the 3.9 branch.

@joreiff joreiff deleted the fix-email-bytes-7bit branch August 9, 2021 17:25
@joreiff
Copy link
Copy Markdown
Contributor Author

joreiff commented Aug 9, 2021

Perfect, thank you!

ambv pushed a commit that referenced this pull request Aug 9, 2021
) (GH-27687)

(cherry picked from commit b33186b)

Co-authored-by: Johannes Reiff <mail@jreiff.de>
miss-islington added a commit that referenced this pull request Aug 9, 2021
)

(cherry picked from commit b33186b)

Co-authored-by: Johannes Reiff <mail@jreiff.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants