Title: email.utils.encode_rfc2231() writes 'None' as the charset when only language is given · Issue #161222 · python/cpython · GitHub
Open Graph Title: email.utils.encode_rfc2231() writes 'None' as the charset when only language is given · Issue #161222 · python/cpython
X Title: email.utils.encode_rfc2231() writes 'None' as the charset when only language is given · Issue #161222 · python/cpython
Description: Bug report Bug description: email.utils.encode_rfc2231() substitutes an empty string when language is omitted, but not when charset is omitted. When only language is given, None is interpolated into the result as the literal charset name...
Open Graph Description: Bug report Bug description: email.utils.encode_rfc2231() substitutes an empty string when language is omitted, but not when charset is omitted. When only language is given, None is interpolated int...
X Description: Bug report Bug description: email.utils.encode_rfc2231() substitutes an empty string when language is omitted, but not when charset is omitted. When only language is given, None is interpolated int...
Opengraph URL: https://github.com/python/cpython/issues/161222
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"email.utils.encode_rfc2231() writes 'None' as the charset when only language is given","articleBody":"# Bug report\n\n### Bug description:\n\n`email.utils.encode_rfc2231()` substitutes an empty string when *language* is omitted, but not when *charset* is omitted. When only *language* is given, `None` is interpolated into the result as the literal charset name:\n\n```python\n>>> import email.utils\n>>> email.utils.encode_rfc2231('abc', language='en')\n\"None'en'abc\"\n```\n\nThe same happens when a `(None, language, value)` tuple is passed as a parameter value to `Message.add_header()`:\n\n```python\n>>> from email.message import Message\n>>> m = Message()\n>>> m.add_header('Content-Disposition', 'attachment', filename=(None, 'en', 'report.txt'))\n>>> m['Content-Disposition']\n\"attachment; filename*=None'en'report.txt\"\n```\n\nRFC 2231 section 4 says \"it is perfectly permissible to leave either the character set or language field blank\", so the expected result is `\"'en'abc\"`. The email package's own parser reads the value back correctly only because `None` is not a known codec, so it falls back to the undecoded text. Other consumers see a bogus charset name.\n\nThis is separate from gh-85014, which covers the case where both *charset* and *language* are `None`.\n\n### CPython versions tested on:\n\n3.15, CPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-161225\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/andresdelfino","@type":"Person","name":"andresdelfino"},"datePublished":"2026-11-02T23:06:01Z","url":"https://github.com/python/cpython/issues/161222"}
| 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:e4e5150a-24d4-b17b-dee0-79b0befd01b1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B1A2:291B58:30E448A:3E09185:6B020291 |
| html-safe-nonce | d6d596de8c42a3419570420cf0b60358a82dc4f9cdfc976d27c49e461c52c61d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMUEyOjI5MUI1ODozMEU0NDhBOjNFMDkxODU6NkIwMjAyOTEiLCJ2aXNpdG9yX2lkIjoiNjg0MzE0Njk5NDgwMjg4NTI2NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 371f60b9a18c86ceb4623cbde807c8a2eb5ba17faebc430e055c33228ae325c1 |
| hovercard-subject-tag | issue:6172684502 |
| 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/161222/issue_layout |
| twitter:image | https://opengraph.githubassets.com/80d23c18a12ce8afbae12a5f6460d00757bf6318490a57e6d06e9608bd63f3db/python/cpython/issues/161222 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/80d23c18a12ce8afbae12a5f6460d00757bf6318490a57e6d06e9608bd63f3db/python/cpython/issues/161222 |
| og:image:alt | Bug report Bug description: email.utils.encode_rfc2231() substitutes an empty string when language is omitted, but not when charset is omitted. When only language is given, None is interpolated int... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | andresdelfino |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width