ImapHook: Handle mixed plaintext and RFC 2047 encoded attachment filenames#66672
Merged
potiuk merged 1 commit intoMay 10, 2026
Merged
Conversation
…mapHook. Add unit test covering mixed plaintext and encoded filename decoding.
potiuk
approved these changes
May 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR is a follow-up to PR #65875 and fixes an additional edge case in
ImapHook.retrieve_mail_attachmentsinvolving attachment filenames that contain a mix of plain text and RFC 2047 encoded segments.Previously, filenames such as
"bar =?utf-8?B?ZsOzbw==?="could produce decoded header fragments withNoneencodings for plaintext segments, potentially resulting in aTypeErrorduring filename decoding.This change updates the decoding logic to safely handle mixed plaintext and encoded fragments returned by
email.header.decode_header.Rationale
email.header.decode_headermay legitimately return a mixture of decoded byte segments and plain string segments withNoneencodings for valid RFC 2047 headers.The previous implementation did not fully account for this behavior, which could cause attachment retrieval to fail for certain valid email attachment filenames.
Tests
Added a unit test verifying that:
Backwards Compatibility
No breaking changes; existing attachment retrieval and filename decoding behavior remain compatible for previously supported cases.
Acknowledgements
This change builds on the edge-case handling previously explored in PR #66578 by @mgustimz involving mixed plaintext and RFC 2047 encoded filename segments.
Related: Issue #65871