Title: email: invalid RFC 2047 address header after refolding with email.policy.default · Issue #121284 · python/cpython · GitHub
Open Graph Title: email: invalid RFC 2047 address header after refolding with email.policy.default · Issue #121284 · python/cpython
X Title: email: invalid RFC 2047 address header after refolding with email.policy.default · Issue #121284 · python/cpython
Description: Bug report Bug description: If an email message (modern or legacy) is assigned an address header that is pre-encoded with RFC 2047, calling as_bytes(policy=default) can generate an invalid address header. The resulting header may include...
Open Graph Description: Bug report Bug description: If an email message (modern or legacy) is assigned an address header that is pre-encoded with RFC 2047, calling as_bytes(policy=default) can generate an invalid address ...
X Description: Bug report Bug description: If an email message (modern or legacy) is assigned an address header that is pre-encoded with RFC 2047, calling as_bytes(policy=default) can generate an invalid address ...
Opengraph URL: https://github.com/python/cpython/issues/121284
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"email: invalid RFC 2047 address header after refolding with email.policy.default ","articleBody":"# Bug report\n\n### Bug description:\n\nIf an email message (modern or legacy) is assigned an address header that is pre-encoded with RFC 2047, calling as_bytes(policy=default) can generate an invalid address header. The resulting header may include unquoted RFC 5322 special characters in a way that can alter its meaning.\n\nHere is a minimal example to demonstrate the problem, isolated from much larger code (including Django's django.core.mail.message). Although this example starts with a legacy Message, an example using only the modern email API [is in a later comment](#issuecomment-2207348299):\n\n```python\nimport email.message\nimport email.policy\n\nmessage = email.message.Message()\nmessage[\"To\"] = '=?utf-8?b?TmfGsOG7nWkgbmjhuq1uIGEgdmVyeSB2ZXJ5IGxvbmcs?= name \u003cto@example.com>'\n\nmessage.as_bytes(policy=email.policy.default)\n# b'To: =?utf-8?b?TmfGsOG7nWkgbmjhuq1u?= a very very long, name \u003cto@example.com>\\n\\n'\n```\n\n(The unquoted comma in the resulting display-name is not valid.)\n\nFor a real-world case where this can occur, see [Django ticket 35378](https://code.djangoproject.com/ticket/35378) and anymail/django-anymail#369. (Thanks to @andresmrm for noticing the problem and isolating a test case.)\n\nOddly, as_string(policy=default) doesn't exhibit the problem:\n```python\nmessage.as_string(policy=email.policy.default)\n# 'To: =?utf-8?b?TmfGsOG7nWkgbmjhuq1uIGEgdmVyeSB2ZXJ5IGxvbmcs?= name \u003cto@example.com>\\n\\n'\n```\n\nAlso, the problem does not occur when assigning the non-encoded equivalent to the header:\n```python\nmessage2 = email.message.Message()\nmessage2[\"To\"] = '\"Người nhận a very very long, name\" \u003cto@example.com>'\nmessage2.as_bytes(policy=email.policy.default)\n# b'To:\\n =?utf-8?b?TmfGsOG7nWkgbmjhuq1uIGEgdmVyeSB2ZXJ5IGxvbmcs?= name \u003cto@example.com>\\n\\n'\n```\n\n(Possibly related to #80222)\n\n\n### CPython versions tested on:\n\n3.9, 3.12\n\n### Operating systems tested on:\n\nmacOS\n\n[edits: removed ambiguous use of \"default\" in example comment; clarified this is not a real-world example, but a minimal test case]\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-122754\n* gh-131403\n* gh-131404\n* gh-131405\n* gh-131411\n* gh-131412\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/medmunds","@type":"Person","name":"medmunds"},"datePublished":"2024-07-02T18:05:12Z","url":"https://github.com/python/cpython/issues/121284"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6e0d75b3-ad1f-c9b6-78d9-1f4183f7d272 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A202:18B602:876F5:BE845:6B0051A7 |
| html-safe-nonce | 46cf530b7ca47e18db5026724ff6c23299b5d4805fceadce7eec4f60cf9f90e1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjAyOjE4QjYwMjo4NzZGNTpCRTg0NTo2QjAwNTFBNyIsInZpc2l0b3JfaWQiOiI4NzY2NDc3OTQ0NTk3MDA4ODA3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 067d12e37aaeaa1b7c2a471a8e90e57b39a50f874a93b11101095047bf98b1bd |
| hovercard-subject-tag | issue:2386852702 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/121284/issue_layout |
| twitter:image | https://opengraph.githubassets.com/80b6a4101f9a3c4ba3b1f9e94f31e9906731dd00fa179d16619915103c7981ed/python/cpython/issues/121284 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/80b6a4101f9a3c4ba3b1f9e94f31e9906731dd00fa179d16619915103c7981ed/python/cpython/issues/121284 |
| og:image:alt | Bug report Bug description: If an email message (modern or legacy) is assigned an address header that is pre-encoded with RFC 2047, calling as_bytes(policy=default) can generate an invalid address ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | medmunds |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width