From 7281ce98683946f825b5bfec197beecad7867a70 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Fri, 1 Nov 2024 10:03:32 +0200 Subject: [PATCH] fix(imap): Support invalid servers that return a full partial instead of starting byte for a FETCH property --- lib/tools.js | 2 +- test/imap-parser-test.js | 59 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/lib/tools.js b/lib/tools.js index ba1136c..626e639 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -250,7 +250,7 @@ module.exports = { ) .toString() .toLowerCase() - .replace(/<\d+>$/, ''); + .replace(/<\d+(\.\d+)?>$/, ''); continue; } if (typeof key !== 'string') { diff --git a/test/imap-parser-test.js b/test/imap-parser-test.js index e9ea908..5e40e0a 100644 --- a/test/imap-parser-test.js +++ b/test/imap-parser-test.js @@ -1002,3 +1002,62 @@ module.exports['IMAP Parser, subfolder square bracket'] = test => { type: 'ATOM', value: 'INBOX.[Airmail].Snooze' } ]); }); + +module.exports['IMAP Parser, FETCH with full range'] = test => + asyncWrapper(test, async test => { + let parsed = await parser('* 32 FETCH (UID 32 RFC822.SIZE 3991 BODY[2.MIME] "(* 61B literal *)" BODY[2]<0.65536> "(* 6B literal *)")'); + console.log(JSON.stringify(parsed.attributes)); + test.deepEqual(parsed.attributes, [ + { + type: 'ATOM', + value: 'FETCH' + }, + [ + { + type: 'ATOM', + value: 'UID' + }, + { + type: 'ATOM', + value: '32' + }, + { + type: 'ATOM', + value: 'RFC822.SIZE' + }, + { + type: 'ATOM', + value: '3991' + }, + { + type: 'ATOM', + value: 'BODY', + section: [ + { + type: 'ATOM', + value: '2.MIME' + } + ] + }, + { + type: 'STRING', + value: '(* 61B literal *)' + }, + { + type: 'ATOM', + value: 'BODY', + section: [ + { + type: 'ATOM', + value: '2' + } + ], + partial: [0, 65536] + }, + { + type: 'STRING', + value: '(* 6B literal *)' + } + ] + ]); + });