Repository navigation
Preserve multiline and Unicode IMAP search terms - #209
Open
stevebauman wants to merge 5 commits into
Open
stevebauman wants to merge 5 commits into
stevebauman wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
🟢 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
SEARCHandSORT, 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
| { | ||
| $first = reset($params); | ||
|
|
||
| if (is_string($first) && preg_match('/^\s*CHARSET(?:\s|$)/i', $first)) { |
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.

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.
SEARCHandSORTnow 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.SEARCHdeclares UTF-8 when it sends non-ASCII text.Command syntax, flags, and UID sets still go through validation. If the server rejects a
LOGINliteral, the resulting exception redacts the credentials.