Skip to content

Commit

Permalink
fix(parser): parse subfolders with square brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Jul 6, 2024
1 parent 954a9de commit 0d0e8a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/handler/token-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions test/imap-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
]);
});

0 comments on commit 0d0e8a6

Please sign in to comment.