Skip to content

fix(imap): do not re-encode the path of a target mailbox - #298

Merged
robert-virkus merged 1 commit into
Enough-Software:mainfrom
brlumen:fix/imap-mailbox-path-double-encoding
Oct 2, 2026
Merged

robert-virkus merged 1 commit into
Enough-Software:mainfrom
brlumen:fix/imap-mailbox-path-double-encoding

Conversation

@brlumen

@brlumen brlumen commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #297

_encodeFirstMailboxPath() 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 appendMessage*(), copy(), uidCopy(), move() and uidMove() failed for target mailboxes with non-ASCII names or &, e.g. with NO [TRYCREATE] on Yandex.

Change

_encodeFirstMailboxPath() now quotes the encodedPath of a given Mailbox with _quoteMailboxPath(), as SELECT, STATUS, RENAME, DELETE, SUBSCRIBE and UNSUBSCRIBE already do. A plain targetMailboxPath is encoded as before.

A Mailbox target is therefore always quoted now, e.g. APPEND "INBOX" instead of APPEND INBOX, the same as SELECT "INBOX". Three existing expectations are updated for that.

Tests

  • uidMove() and appendMessageText() to a mailbox from a LIST response no longer encode its name again. Without the fix they send UID MOVE 1:3 &-BCMENAQwBDsEUQQ9BD0ESwQ1- and APPEND &-BB4EQgQ,BEAEMAQyBDsENQQ9BD0ESwQ1- (\Seen) {21}.
  • copy() with a plain non-ASCII targetMailboxPath still encodes it once.

dart format and dart analyze show no new findings, dart test: 594 passed.

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.
@robert-virkus

Copy link
Copy Markdown
Member

nice one, thanks!

@robert-virkus
robert-virkus merged commit a024e52 into Enough-Software:main Oct 2, 2026
1 check 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.

APPEND, COPY and MOVE re-encode Mailbox.encodedPath, so non-ASCII target mailboxes fail

2 participants