Skip to content

Decode RFC 2231 MIME parameters#170

Merged
stevebauman merged 6 commits into
masterfrom
agent/issue-169-rfc-2231-parameters
Jul 16, 2026
Merged

Decode RFC 2231 MIME parameters#170
stevebauman merged 6 commits into
masterfrom
agent/issue-169-rfc-2231-parameters

Conversation

@stevebauman

@stevebauman stevebauman commented Jul 16, 2026

Copy link
Copy Markdown
Member

Closes #169

This PR fixes attachment filenames that are split across multiple RFC 2231 MIME parameters in IMAP BODYSTRUCTURE responses.

Some IMAP servers return attachment filenames as numbered parameters:

filename*0=attachment_name_part_0
filename*1=attachment_name_part_1.pdf

ImapEngine previously looked only for an exact filename or name parameter. As a result, lazy-loaded attachments could have a null filename even though the complete filename was present in the response.

Extended parameters containing percent-encoded values and charset information were also not being decoded.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes RFC 2231 MIME parameter handling so attachment filenames (and content-type name parameters) are correctly reconstructed from continuation segments and decoded from extended/percent-encoded forms when parsing IMAP BODYSTRUCTURE.

Changes:

  • Added MimeParameterParser to normalize MIME parameters (RFC 2231 continuations + extended decoding).
  • Wired normalized parameter parsing into BodyStructurePart, BodyStructureCollection, and ContentDisposition.
  • Added unit tests covering continuations, extended parameters, charset conversion, and compatibility decoding.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Unit/Support/MimeParameterParserTest.php Adds focused unit tests for RFC 2231 continuations/extended decoding and compatibility cases.
tests/Unit/BodyStructureTest.php Adds integration-style tests ensuring BODYSTRUCTURE parsing yields correct filenames/parameters.
src/Support/MimeParameterParser.php Introduces central MIME parameter normalization via MailMimeParser.
src/ContentDisposition.php Uses MimeParameterParser so disposition parameters (e.g., filename*0, filename*1) are reconstructed.
src/BodyStructurePart.php Uses MimeParameterParser for part parameters and relies on normalized name for filenames when no disposition.
src/BodyStructureCollection.php Uses MimeParameterParser for multipart parameters (e.g., boundary) and normalized names.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Support/MimeParameterParser.php Outdated
@stevebauman
stevebauman merged commit 8d5652b into master Jul 16, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attachment filenames using RFC 2231 continuations are not reconstructed

2 participants