You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
email: get_payload(decode=True) doesn't handle Content-Transfer-Encoding with trailing white space #98188
If the Content-Transfer-Encoding header field of a message part has trailing whitespace, for example "base64 ", get_payload(decode=True) does not return the properly decoded payload.
Here is a minimal code example. Sample message file attached.
import email
from email import policy
with open('msg.txt', 'rb') as f:
msg = email.message_from_binary_file(f, policy=policy.default)
parts = list(msg.walk())
parts[1].get_payload(decode=True)
> b'SGVsbG8uIFRlc3Rpbmc=\n'
The parsed content-transfer-encoding header "cte" value is truncated, but it's string value is not.
If the Content-Transfer-Encoding header field of a message part has trailing whitespace, for example "base64 ", get_payload(decode=True) does not return the properly decoded payload.
Here is a minimal code example. Sample message file attached.
import email
from email import policy
with open('msg.txt', 'rb') as f:
msg = email.message_from_binary_file(f, policy=policy.default)
parts = list(msg.walk())
parts[1].get_payload(decode=True)
> b'SGVsbG8uIFRlc3Rpbmc=\n'
The parsed content-transfer-encoding header "cte" value is truncated, but it's string value is not.
Activity
rruuaanng commentedon Sep 10, 2024
This issuer, I have commit a PR
pythongh-98188: Fix EmailMessage.get_payload to decode data
gh-98188: Fix EmailMessage.get_payload to decode data when CTE value …
pythongh-98188: Fix EmailMessage.get_payload to decode data when CTE …
pythongh-98188: Fix EmailMessage.get_payload to decode data when CTE …
pythongh-98188: Fix EmailMessage.get_payload to decode data when CTE …
[3.13] gh-98188: Fix EmailMessage.get_payload to decode data when CTE…
[3.12] gh-98188: Fix EmailMessage.get_payload to decode data when CTE…
bitdancer commentedon Jan 7, 2025
Fix committed to all three branches. Thanks all.
pythongh-98188: Fix EmailMessage.get_payload to decode data when CTE …