matcha icon indicating copy to clipboard operation
matcha copied to clipboard

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

Open Robin-Everaars opened this issue 6 months ago • 5 comments

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.

Robin-Everaars avatar Jun 03 '26 13:06 Robin-Everaars

Hey, @Robin-Everaars,

Thank you for leaving the issue (a very well written issue).

The fix was simple. PR is #1427

And here are the binaries for you to test: https://github.com/floatpane/matcha/pull/1427#issuecomment-4613014565

andrinoff avatar Jun 03 '26 13:06 andrinoff

Hey, @Robin-Everaars,

Thank you for leaving the issue (a very well written issue).

The fix was simple. PR is #1427

And here are the binaries for you to test: https://github.com/floatpane/matcha/pull/1427#issuecomment-4613014565

You're welcome and thanks @andrinoff for the quick fix! I'll check on Monday when I'm back from my mini-vacation.

P.S. love Matcha! Been hunting for a good and easy solution for mail in the terminal and Matcha checks all the boxes for me!

Robin-Everaars avatar Jun 03 '26 14:06 Robin-Everaars

Was seeing this on my machine as well. The test binaries work without an error for me.

subtervisor avatar Jun 03 '26 21:06 subtervisor

Following up (sorry for the late confirmation after the mini-vacation): 0.41.1 fixes this for me. Folder listing now works correctly on all three accounts — Gmail, Proton Mail Bridge, and Exchange Online / M365. The two that were failing (Proton + Exchange) now populate their folder lists fine, no more BAD Command Argument Error or imapwire parse error. Capability-gating the LIST-STATUS RETURN (STATUS (UNSEEN)) did the trick. Thanks again @andrinoff for the quick fix! 🍵

Robin-Everaars avatar Jun 15 '26 14:06 Robin-Everaars

Cheers, @Robin-Everaars, sounds like a good vacation!

andrinoff avatar Jun 15 '26 14:06 andrinoff