Repository navigation
fix(imap): encode mailbox names unless UTF8=ACCEPT is enabled - #300
Merged
robert-virkus merged 2 commits intoOct 2, 2026
Merged
Conversation
APPEND, COPY and MOVE passed Mailbox.encodedPath, which is already modified UTF-7, through Mailbox.encode() once more on servers without UTF8=ACCEPT. The '&' that starts every non-ASCII run became '&-', so the server rejected the command, e.g. with NO [TRYCREATE]. The encodedPath of a target Mailbox is now quoted with _quoteMailboxPath(), as SELECT and the other mailbox commands do. A plain targetMailboxPath is still encoded.
selectMailboxByPath() used the decoded path as Mailbox.encodedPath, so SELECT sent it unencoded: a non-ASCII name went out as raw UTF-8 and a name such as "R&D" without the "&-" escape. The path is now encoded in modified UTF-7 as a whole, which leaves the ASCII path separator as it is. Mailbox names given as strings were sent in UTF-8 as soon as the server advertised UTF8=ACCEPT. RFC 6855 requires ENABLE UTF8=ACCEPT first: until then the server lists modified UTF-7 names, and Gmail answers a UTF-8 name with "BAD Could not parse command". UTF-8 is now only used once UTF8=ACCEPT is enabled, as MailClient does when it connects.
Member
|
Thanks, lgtm! |
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.
Fixes #299
Builds on #298 and includes its commit: without it, sending modified UTF-7 on a server that advertises
UTF8=ACCEPTwould bring the double encoding of #297 to a plainImapClienton Gmail, for aMailboxtarget ofappendMessage*(),copy()ormove(). Only the last commit belongs to this PR.Change
selectMailboxByPath()encodes the given path and name instead of using them asencodedPathandencodedNamedirectly. The whole path is encoded at once, since modified UTF-7 leaves the ASCII path separator as it is.UTF8=ACCEPTis enabled, checked withserverInfo.isEnabled()instead ofsupportsUtf8.MailClientenables it when it connects, so it behaves as before._encodeMailboxPath()and_quoteMailboxPath(), now also needed byselectMailboxByPath(), moved to_checkMailboxName().Code that passes an already encoded
Mailbox.encodedPathas a plaintargetMailboxPathworked only with a plainImapClienton a server that advertisesUTF8=ACCEPT. It now gets the same result there as on other servers; passing theMailboxitself works with #298.Tests
In
test/imap/imap_quoting_test.dart:selectMailboxByPath()sendsSELECT "Entw&APw-rfe/M&APw-ll"forEntwürfe/MüllandSELECT "R&-D"forR&D. Without the fix:SELECT "Entwürfe/Müll"in UTF-8 andSELECT "R&D".UTF8=ACCEPTadvertised but not enabled,selectMailboxByPath()andappendMessageText(targetMailboxPath: ...)send modified UTF-7. Without the fix both send UTF-8.ENABLE UTF8=ACCEPTboth send UTF-8, as before.dart formatanddart analyzeshow no new findings,dart test: 598 passed.