postalsys / imapflow

IMAP Client library for EmailEngine Email API (https://emailengine.app)
https://imapflow.com
Other
350 stars 59 forks source link

ParserError: Mailbox names that contain square brackets trigger parser errors #204

Closed RogWilco closed 2 months ago

RogWilco commented 2 months ago

Describe the bug Mailboxes containing square brackets in their names sometimes cause the parser to throw an error. In my particular case, it was the mailboxes automatically created by the MacOS email client Airmail (i.e. "INBOX.[Airmail].Snooze").

To Reproduce Steps to reproduce the behavior:

  1. Connect and authenticate to an IMAP account that contains at least one mailbox containing square brackets in the name.
  2. Attempt to fetch a list of mailboxes using ImapFlow.list()
  3. Observe that sometimes the affected mailbox is omitted from the parsed results, with one or more errors thrown similar to this:
 {
  src: 's',
  msg: '* LIST (\\UnMarked) "." INBOX.[Airmail].Snooze',
  err: Error: Unexpected section start char [ at position 29 [E14]
      at TokenParser.processString (/Users/foo/project/node_modules/imapflow/lib/handler/token-parser.js:358:41)
      at TokenParser.getAttributes (/Users/foo/project/node_modules/imapflow/lib/handler/token-parser.js:33:20)
      at ParserInstance.getAttributes (/Users/foo/project/node_modules/imapflow/lib/handler/parser-instance.js:156:34)
      at module.exports (/Users/foo/project/node_modules/imapflow/lib/handler/imap-parser.js:44:48)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async ImapFlow.reader (/Users/foo/project/node_modules/imapflow/lib/imap-flow.js:478:26) {
    code: 'ParserError14',
    parserContext: {
      input: '(\\UnMarked) "." INBOX.[Airmail].Snooze',
      pos: 29,
      chr: '['
    },
    node: 'INBOX.'
  },
  cid: '11ofrx5prhwu6azae603'
}

Expected behavior The relevant mailbox(es) should be returned without parser errors.

Desktop (please complete the following information):

andris9 commented 2 months ago

Fixed in v1.0.163