summaryrefslogtreecommitdiffstats
path: root/Misc
diff options
context:
space:
mode:
authorRanKKI <hliu86.me@gmail.com>2025-01-06 01:32:16 (GMT)
committerGitHub <noreply@github.com>2025-01-06 01:32:16 (GMT)
commita62ba52f1439c1f878a3ff9b8544caf9aeef9b90 (patch)
tree1497bc9199ac370221eff8d042cdf4ff17e5d9a6 /Misc
parent3b231be8f000ae59faa04d5a2f1af11beafee866 (diff)
downloadcpython-a62ba52f1439c1f878a3ff9b8544caf9aeef9b90.zip
cpython-a62ba52f1439c1f878a3ff9b8544caf9aeef9b90.tar.gz
cpython-a62ba52f1439c1f878a3ff9b8544caf9aeef9b90.tar.bz2
gh-98188: Fix EmailMessage.get_payload to decode data when CTE value has extra text (#127547)
Up to this point message handling has been very strict with regards to content encoding values: mixed case was accepted, but trailing blanks or other text would cause decoding failure, even if the first token was a valid encoding. By Postel's Rule we should go ahead and decode as long as we can recognize that first token. We have not thought of any security or backward compatibility concerns with this fix. This fix does introduce a new technique/pattern to the Message code: we look to see if the header has a 'cte' attribute, and if so we use that. This effectively promotes the header API exposed by HeaderRegistry to an API that any header parser "should" support. This seems like a reasonable thing to do. It is not, however, a requirement, as the string value of the header is still used if there is no cte attribute. The full fix (ignore any trailing blanks or blank-separated trailing text) applies only to the non-compat32 API. compat32 is only fixed to the extent that it now ignores trailing spaces. Note that the HeaderRegistry parsing still records a HeaderDefect if there is extra text. Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Diffstat (limited to 'Misc')
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS.d/next/Library/2024-12-03-14-45-16.gh-issue-98188.GX9i2b.rst3
2 files changed, 4 insertions, 0 deletions
diff --git a/Misc/ACKS b/Misc/ACKS
index c6e5331..d7585c1 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1129,6 +1129,7 @@ Gregor Lingl
Everett Lipman
Mirko Liss
Alexander Liu
+Hui Liu
Yuan Liu
Nick Lockwood
Stephanie Lockwood
diff --git a/Misc/NEWS.d/next/Library/2024-12-03-14-45-16.gh-issue-98188.GX9i2b.rst b/Misc/NEWS.d/next/Library/2024-12-03-14-45-16.gh-issue-98188.GX9i2b.rst
new file mode 100644
index 0000000..30ab8cf
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-12-03-14-45-16.gh-issue-98188.GX9i2b.rst
@@ -0,0 +1,3 @@
+Fix an issue in :meth:`email.message.Message.get_payload` where data
+cannot be decoded if the Content Transfer Encoding mechanism contains
+trailing whitespaces or additional junk text. Patch by Hui Liu.