Skip to content

Preserve multiline and Unicode IMAP search terms - #209

Open
stevebauman wants to merge 5 commits into
masterfrom
fix/preserve-imap-search-values
Open

stevebauman wants to merge 5 commits into
masterfrom
fix/preserve-imap-search-values

Conversation

@stevebauman

Copy link
Copy Markdown
Member

Searching for text that contains a line break currently strips the line break before the query reaches the server. Non-ASCII search terms are encoded using modified UTF-7, which IMAP uses for mailbox names.

SEARCH and SORT now quote and escape ordinary text and use length-prefixed IMAP literals when a value needs one. That lets the server read the original bytes, including line breaks. SEARCH declares UTF-8 when it sends non-ASCII text.

Command syntax, flags, and UID sets still go through validation. If the server rejects a LOGIN literal, the resulting exception redacts the credentials.

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.

🟢 Approval recommended

No active review issues remain for the changes preserving multiline and Unicode IMAP search terms.

No open issues 🎉

What changed in this PR

Preserves multiline and Unicode search terms through the IMAP query and command pipeline, using literals instead of stripping line breaks or applying mailbox-name encoding.

Changes:

  • Adds literal-aware compilation for SEARCH and SORT, with automatic UTF-8 declaration for non-ASCII search literals.
  • Maintains syntax validation and compiler override compatibility, and redacts credentials when authentication literals are rejected.
  • Adds regression tests for literal encoding, nested criteria, sorting, keywords, and credential redaction.
File Description
tests/​Unit/​Support/​StrTest.php Tests literal byte lengths, preserved characters, and NUL rejection.
tests/​Unit/​MessageQueryTest.php Tests nested literal searches, UTF-8 sorting, and token passthrough.
tests/​Unit/​Connection/​ImapQueryBuilderTest.php Tests compiler overrides and keyword validation.
tests/​Unit/​Connection/​ImapConnectionTest.php Tests credential redaction on literal rejection.
src/​Support/​Str.php Encodes non-printable or non-ASCII strings as literals and rejects NUL.
src/​Support/​Assert.php Adds keyword validation using shared atom checks.
src/​QueriesMessages.php Exposes toImapTokens through query passthrough.
src/​MessageQuery.php Sends literal-aware tokens for searches and sorting.
src/​Connection/​ImapQueryBuilder.php Compiles literal-aware criteria while retaining legacy subclass hooks.
src/​Connection/​ImapConnection.php Declares search charset and redacts authentication continuation errors.
src/​Connection/​ImapCommandArgument.php Represents syntax fragments and literals and detects non-ASCII payloads.
src/​Connection/​ImapCommand.php Preserves argument spacing and literal boundaries during compilation.
src/​Connection/​ConnectionInterface.php Documents supported argument types and search charset behavior.

Review effort: Balanced

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.

🟡 Changes recommended

An explicit charset in a compound ImapCommandArgument is missed, causing an extra UTF-8 declaration to be prepended and producing invalid IMAP SEARCH syntax.

1 open issue

Review effort: Balanced

{
$first = reset($params);

if (is_string($first) && preg_match('/^\s*CHARSET(?:\s|$)/i', $first)) {
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.

2 participants