Skip to content

ImapHook: Handle mixed plaintext and RFC 2047 encoded attachment filenames#66672

Merged
potiuk merged 1 commit into
apache:mainfrom
SameerMesiah97:65871-ImapHook-Mixed-Plaintext-Encoded-Fix
May 10, 2026
Merged

ImapHook: Handle mixed plaintext and RFC 2047 encoded attachment filenames#66672
potiuk merged 1 commit into
apache:mainfrom
SameerMesiah97:65871-ImapHook-Mixed-Plaintext-Encoded-Fix

Conversation

@SameerMesiah97
Copy link
Copy Markdown
Contributor

Description

This PR is a follow-up to PR #65875 and fixes an additional edge case in ImapHook.retrieve_mail_attachments involving 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 with None encodings for plaintext segments, potentially resulting in a TypeError during 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_header may legitimately return a mixture of decoded byte segments and plain string segments with None encodings 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:

  • Attachment filenames containing a mix of plaintext and RFC 2047 encoded segments are correctly decoded and matched during attachment retrieval.

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

…mapHook. Add unit test covering mixed plaintext and encoded filename decoding.
@potiuk potiuk merged commit 3e81987 into apache:main May 10, 2026
90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants