From 0d0e8a6ea379adf11594684d49a1ce5031339939 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Sat, 6 Jul 2024 11:15:57 +0300 Subject: [PATCH] fix(parser): parse subfolders with square brackets --- lib/handler/token-parser.js | 14 ++++++++++---- test/imap-parser-test.js | 10 ++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/handler/token-parser.js b/lib/handler/token-parser.js index 36d53bf..6a94488 100644 --- a/lib/handler/token-parser.js +++ b/lib/handler/token-parser.js @@ -355,10 +355,16 @@ class TokenParser { if (chr === '[') { // allowed only for selected elements if (['BODY', 'BODY.PEEK', 'BINARY', 'BINARY.PEEK'].indexOf(this.currentNode.value.toUpperCase()) < 0) { - let error = new Error(`Unexpected section start char [ at position ${this.pos + i} [E14]`); - error.code = 'ParserError14'; - error.parserContext = { input: this.str, pos: this.pos + i, chr }; - throw error; + if (/[./]/.test(this.currentNode.value)) { + // could be a path + this.currentNode.value += chr; + break; + } else { + let error = new Error(`Unexpected section start char [ at position ${this.pos + i} [E14]`); + error.code = 'ParserError14'; + error.parserContext = { input: this.str, pos: this.pos + i, chr }; + throw error; + } } this.currentNode.endPos = this.pos + i; this.currentNode = this.createNode(this.currentNode.parentNode, this.pos + i); diff --git a/test/imap-parser-test.js b/test/imap-parser-test.js index 271fc55..e9ea908 100644 --- a/test/imap-parser-test.js +++ b/test/imap-parser-test.js @@ -992,3 +992,13 @@ module.exports['IMAP Parser, BAD with throttling'] = test => test.equal(parsed.command, 'BAD'); test.deepEqual(parsed.attributes, [{ type: 'TEXT', value: 'Request is throttled. Suggested Backoff Time: 92415 milliseconds' }]); }); + +module.exports['IMAP Parser, subfolder square bracket'] = test => + asyncWrapper(test, async test => { + let parsed = await parser('* LIST (\\UnMarked) "." INBOX.[Airmail].Snooze'); + test.deepEqual(parsed.attributes, [ + [{ type: 'ATOM', value: '\\UnMarked' }], + { type: 'STRING', value: '.' }, + { type: 'ATOM', value: 'INBOX.[Airmail].Snooze' } + ]); + });