Skip to content

Folder list fails on Proton Bridge and Exchange Online (LIST-STATUS requested without checking the capability) #1426

@Robin-Everaars

Description

@Robin-Everaars

I have three accounts set up: Gmail, Proton (via Proton Mail Bridge, configured as a custom IMAP server), and an Exchange Online / Office 365 account. Inbox and sending work on all of them, but folder listing fails on the two non-Gmail accounts:

Folder fetch failed for 2 account(s):
  <exchange>: imap: BAD Command Argument Error. 12
  <proton>: in response: cannot read tag: imapwire: expected '*' or atom, got ' '

I turned on DEBUG_IMAP to see what was actually going over the wire, and the common factor is the LIST-STATUS extension. FetchFolders (in fetcher/fetcher.go) always asks for the unseen count inline:

listCmd := c.List("", "*", &imap.ListOptions{
    ReturnStatus: &imap.StatusOptions{
        NumUnseen: true,
    },
})

go-imap turns that into LIST "" "*" RETURN (STATUS (UNSEEN)), which requires LIST-STATUS (RFC 5819). Nothing checks that the server advertises it first, and the two accounts that break are the two that don't:

Proton Mail Bridge 3.24.2:

* CAPABILITY AUTH=PLAIN ID IDLE IMAP4rev1 MOVE STARTTLS UIDPLUS UNSELECT

Exchange Online:

* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+

Gmail (works):

* CAPABILITY IMAP4rev1 ... LIST-EXTENDED LIST-STATUS ... SPECIAL-USE ...

Exchange rejects the RETURN argument outright (BAD), and Proton Bridge sends back a reply go-imap can't parse. A plain LIST "" "*" works fine on both, it's only the inline STATUS that trips them up.

Gating it on the capability should be enough:

opts := &imap.ListOptions{}
if c.Caps().Has(imap.CapListStatus) {
    opts.ReturnStatus = &imap.StatusOptions{NumUnseen: true}
}
listCmd := c.List("", "*", opts)

and if the unseen counts matter on those servers, fall back to a STATUS per mailbox.

To reproduce: add an account on any server that doesn't advertise LIST-STATUS (Proton Bridge, or Exchange / Office 365) and open the folder list.

Version: matcha 0.40.1, go-imap v2, Linux.

Metadata

Metadata

Assignees

Labels

area/cliCLI flags / commandsarea/fetcherIMAP fetch / IDLE / searcharea/oauthOAuth / XOAUTH2 / auth flowsos/linuxLinux-specific

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions