Title: Email MIME `base64` parser stops at the end of the first padding · Issue #137687 · python/cpython · GitHub
Open Graph Title: Email MIME `base64` parser stops at the end of the first padding · Issue #137687 · python/cpython
X Title: Email MIME `base64` parser stops at the end of the first padding · Issue #137687 · python/cpython
Description: Bug report Bug description: Hi Cpython Developers, I was testing and comparing different email parsers, and found a parsing discrepancy that seems to be a problem. MIME-Version: 1.0 Content-Type: application/zip Content-Disposition: atta...
Open Graph Description: Bug report Bug description: Hi Cpython Developers, I was testing and comparing different email parsers, and found a parsing discrepancy that seems to be a problem. MIME-Version: 1.0 Content-Type: a...
X Description: Bug report Bug description: Hi Cpython Developers, I was testing and comparing different email parsers, and found a parsing discrepancy that seems to be a problem. MIME-Version: 1.0 Content-Type: a...
Opengraph URL: https://github.com/python/cpython/issues/137687
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Email MIME `base64` parser stops at the end of the first padding","articleBody":"# Bug report\n\n### Bug description:\n\nHi Cpython Developers,\n\nI was testing and comparing different email parsers, and found a parsing discrepancy that seems to be a problem.\n```\nMIME-Version: 1.0\nContent-Type: application/zip\nContent-Disposition: attachment; filename=archive.zip\nContent-Transfer-Encoding: base64\n\nUEsDBBQAAAAIAA==\nemVkIGZpbGUgY29udGVudA==\n```\nWith the [python's email get_payload method](https://github.com/python/cpython/blob/5d64571b43bc75b2971af6aa046dfba64fb43ef8/Lib/email/message.py#L243), the return content would stopped at the first \"==\" as it seems to be the default behavior of `base64.b64decode`.\nMeanwhile, peer implementations (e.g. **apache.commons.mal (java)**, **MimeKit (c#)**, **PhpMimeMailParser (php)**) will return the whole content.\n\nBelow is an running example in python.\n```python\nimport base64\nimport email\n\n\"\"\"\n Parsing the mime format\n\"\"\"\nrequest = \"\"\"MIME-Version: 1.0\nContent-Type: application/zip\nContent-Disposition: attachment; filename=archive.zip\nContent-Transfer-Encoding: base64\n\nUEsDBBQAAAAIAA==\nemVkIGZpbGUgY29udGVudA==\n\"\"\"\nmsg = email.message_from_string(request)\nprint(\"Part content:\", repr(msg.get_payload(decode=True)))\nprint()\n\n\"\"\"\n Examples of base64\n\"\"\"\ncontents = [\n \"UEsDBBQAAAAIAA==\\nemVkIGZpbGUgY29udGVudA==\",\n \"UEsDBBQAAAAIAA==emVkIGZpbGUgY29udGVudA==\",\n \"UEsDBBQAAAAIAA=emVkIGZpbGUgY29udGVudA==\",\n \"UEsDBBQAAAAIAAemVkIGZpbGUgY29udGVudA==\",\n \"UEsDBBQAAAAIAA==\",\n \"emVkIGZpbGUgY29udGVudA==\"\n ]\nfor content in contents:\n decoded_bytes = base64.b64decode(content)\n print(repr(content), \" -\u003e\")\n print(\" \", decoded_bytes)\n```\n\nOutput:\n```\nPart content: b'PK\\x03\\x04\\x14\\x00\\x00\\x00\\x08\\x00'\n\n'UEsDBBQAAAAIAA==\\nemVkIGZpbGUgY29udGVudA==' -\u003e\n b'PK\\x03\\x04\\x14\\x00\\x00\\x00\\x08\\x00'\n'UEsDBBQAAAAIAA==emVkIGZpbGUgY29udGVudA==' -\u003e\n b'PK\\x03\\x04\\x14\\x00\\x00\\x00\\x08\\x00'\n'UEsDBBQAAAAIAA=emVkIGZpbGUgY29udGVudA==' -\u003e\n b'PK\\x03\\x04\\x14\\x00\\x00\\x00\\x08\\x00\\x07\\xa6VB\\x06f\\x96\\xc6R\\x066\\xf6\\xe7FV\\xe7@'\n'UEsDBBQAAAAIAAemVkIGZpbGUgY29udGVudA==' -\u003e\n b'PK\\x03\\x04\\x14\\x00\\x00\\x00\\x08\\x00\\x07\\xa6VB\\x06f\\x96\\xc6R\\x066\\xf6\\xe7FV\\xe7@'\n'UEsDBBQAAAAIAA==' -\u003e\n b'PK\\x03\\x04\\x14\\x00\\x00\\x00\\x08\\x00'\n'emVkIGZpbGUgY29udGVudA==' -\u003e\n b'zed file content'\n```\n\n\nThank you,\nWei-Cheng\n\n\n### CPython versions tested on:\n\n3.15\n\n### Operating systems tested on:\n\nLinux","author":{"url":"https://github.com/spencerwuwu","@type":"Person","name":"spencerwuwu"},"datePublished":"2025-08-12T18:59:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/137687/cpython/issues/137687"}
| 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:ec302193-8493-106f-45cc-03122ec6e456 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BCE2:1661F0:881755:B621DD:6A5275F5 |
| html-safe-nonce | dc8991df991614c69c352a6366ece41fba039e1fa53e25185eae724abc74119d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0UyOjE2NjFGMDo4ODE3NTU6QjYyMUREOjZBNTI3NUY1IiwidmlzaXRvcl9pZCI6Ijc3MzczOTc0NDUzODcyNTMyMzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | deefbcb3e33cf3400354d693486cf62fd3207ad6bc0c1943eec3fa5db688876b |
| hovercard-subject-tag | issue:3315479942 |
| 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/137687/issue_layout |
| twitter:image | https://opengraph.githubassets.com/181a235d004c3ac0590205c31ed579684c582105d19b7cc933a45cf52bfb540c/python/cpython/issues/137687 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/181a235d004c3ac0590205c31ed579684c582105d19b7cc933a45cf52bfb540c/python/cpython/issues/137687 |
| og:image:alt | Bug report Bug description: Hi Cpython Developers, I was testing and comparing different email parsers, and found a parsing discrepancy that seems to be a problem. MIME-Version: 1.0 Content-Type: a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | spencerwuwu |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width