From ee8d00be7ccecff18e11d523cac8d2258f235f97 Mon Sep 17 00:00:00 2001 From: Petr Malimanek Date: Fri, 30 Dec 2016 00:47:25 +0100 Subject: [PATCH 1/4] Add utf7 decoding of labels --- lib/Connection.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Connection.js b/lib/Connection.js index 619862ff4..46ce06af1 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -1448,7 +1448,7 @@ Connection.prototype._resUntagged = function(info) { if (toget[i] === 'X-GM-LABELS') { var labels = info.text[keys[j]]; for (var k = 0, lenk = labels.length; k < lenk; ++k) - labels[k] = (''+labels[k]).replace(RE_ESCAPE, '\\'); + labels[k] = utf7.decode((''+labels[k]).replace(RE_ESCAPE, '\\')); } key = FETCH_ATTR_MAP[toget[i]]; if (!key) diff --git a/package.json b/package.json index 3f1445855..e2c528a90 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name": "imap", - "version": "0.8.19", + "version": "0.8.20", "author": "Brian White ", "description": "An IMAP module for node.js that makes communicating with IMAP servers easy", "main": "./lib/Connection", From 852283c9aa0490ec0c091335ba3c7bfabd7814b9 Mon Sep 17 00:00:00 2001 From: Petr Malimanek Date: Sun, 15 Mar 2020 10:23:59 +0100 Subject: [PATCH 2/4] Make @integromat/imap npm package --- .idea/$CACHE_FILE$ | 17 +++++++++++++++++ .idea/.gitignore | 2 ++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/node-imap.iml | 8 ++++++++ .idea/scopes | 6 ++++++ .idea/vagrant.xml | 7 +++++++ .idea/vcs.xml | 28 ++++++++++++++++++++++++++++ package.json | 6 +++--- 9 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 .idea/$CACHE_FILE$ create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/node-imap.iml create mode 100644 .idea/scopes create mode 100644 .idea/vagrant.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/$CACHE_FILE$ b/.idea/$CACHE_FILE$ new file mode 100644 index 000000000..3a1e22c78 --- /dev/null +++ b/.idea/$CACHE_FILE$ @@ -0,0 +1,17 @@ + + + + + + + + + + + Angular + + + + + + \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..5c98b4288 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..28a804d89 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..5c0e0f485 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/node-imap.iml b/.idea/node-imap.iml new file mode 100644 index 000000000..c956989b2 --- /dev/null +++ b/.idea/node-imap.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/scopes b/.idea/scopes new file mode 100644 index 000000000..a2df5f7cb --- /dev/null +++ b/.idea/scopes @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vagrant.xml b/.idea/vagrant.xml new file mode 100644 index 000000000..a5aa78680 --- /dev/null +++ b/.idea/vagrant.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..f95c87a02 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,28 @@ + + + + + + + + + \ No newline at end of file diff --git a/package.json b/package.json index e2c528a90..e2fb1f75c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ -{ "name": "imap", - "version": "0.8.20", +{ "name": "@integromat/imap", + "version": "0.8.21", "author": "Brian White ", "description": "An IMAP module for node.js that makes communicating with IMAP servers easy", "main": "./lib/Connection", @@ -13,5 +13,5 @@ "engines": { "node": ">=0.8.0" }, "keywords": [ "imap", "mail", "email", "reader", "client" ], "licenses": [ { "type": "MIT", "url": "https://github.com/mscdex/node-imap/raw/master/LICENSE" } ], - "repository": { "type": "git", "url": "https://github.com/mscdex/node-imap.git" } + "repository": { "type": "git", "url": "https://github.com/integromat/node-imap.git" } } From f20a2bc4e7a62d8bc30a9b22ecf2db2f4513e480 Mon Sep 17 00:00:00 2001 From: Petr Malimanek Date: Sun, 15 Mar 2020 10:31:20 +0100 Subject: [PATCH 3/4] Add .gitignore --- .gitignore | 3 +++ .idea/$CACHE_FILE$ | 17 ----------------- .idea/.gitignore | 2 -- .idea/misc.xml | 6 ------ .idea/modules.xml | 8 -------- .idea/node-imap.iml | 8 -------- .idea/scopes | 6 ------ .idea/vagrant.xml | 7 ------- .idea/vcs.xml | 28 ---------------------------- 9 files changed, 3 insertions(+), 82 deletions(-) create mode 100644 .gitignore delete mode 100644 .idea/$CACHE_FILE$ delete mode 100644 .idea/.gitignore delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/node-imap.iml delete mode 100644 .idea/scopes delete mode 100644 .idea/vagrant.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..84fae5498 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +.vscode +node_modules diff --git a/.idea/$CACHE_FILE$ b/.idea/$CACHE_FILE$ deleted file mode 100644 index 3a1e22c78..000000000 --- a/.idea/$CACHE_FILE$ +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - Angular - - - - - - \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 5c98b4288..000000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Default ignored files -/workspace.xml \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 28a804d89..000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 5c0e0f485..000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/node-imap.iml b/.idea/node-imap.iml deleted file mode 100644 index c956989b2..000000000 --- a/.idea/node-imap.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/scopes b/.idea/scopes deleted file mode 100644 index a2df5f7cb..000000000 --- a/.idea/scopes +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vagrant.xml b/.idea/vagrant.xml deleted file mode 100644 index a5aa78680..000000000 --- a/.idea/vagrant.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index f95c87a02..000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - \ No newline at end of file From 55f99c4422a7843beafafd9b2232381bd12b7e85 Mon Sep 17 00:00:00 2001 From: o-hushcha Date: Wed, 27 May 2026 00:44:55 +0300 Subject: [PATCH 4/4] Fix TypeError in parseFetch for integer-shaped key tokens Some IMAP servers emit FETCH responses where an even-indexed atom (key position) is an integer-shaped token (e.g. "* 1 FETCH (12345 NIL)" or as observed in the wild on the @integromat/imap consumer side via extension/quirk responses). convStr returns a JS number for such atoms, and parseFetch then calls .toLowerCase() on it, throwing: TypeError: list[i].toLowerCase is not a function at Parser.parseFetch (lib/Parser.js:431) Coerce the key token to a string at the extraction site. Value-position numeric atoms (RFC822.SIZE, MODSEQ, UIDNEXT, etc.) are untouched, so existing consumers that read those as numbers see no behavior change. Bump to 0.8.22. Co-Authored-By: Claude Opus 4.7 (1M context) --- lib/Parser.js | 7 ++++++- package.json | 2 +- test/test-parser.js | 9 +++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/Parser.js b/lib/Parser.js index 16297d366..44740ea76 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -428,7 +428,12 @@ function parseFetch(text, literals, seqno) { var list = parseExpr(text, literals)[0], attrs = {}, m, body; // list is [KEY1, VAL1, KEY2, VAL2, .... KEYn, VALn] for (var i = 0, len = list.length, key, val; i < len; i += 2) { - key = list[i].toLowerCase(); + // Coerce the key token to a string before lowercasing. Some servers send + // integer-shaped atoms at key positions in malformed FETCH responses; + // convStr returns a JS number for those, and Number has no .toLowerCase. + // Coercing here keeps value-position numeric atoms (RFC822.SIZE, MODSEQ, + // etc.) untouched. + key = String(list[i]).toLowerCase(); val = list[i + 1]; if (key === 'envelope') val = parseFetchEnvelope(val); diff --git a/package.json b/package.json index e2fb1f75c..98368648c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name": "@integromat/imap", - "version": "0.8.21", + "version": "0.8.22", "author": "Brian White ", "description": "An IMAP module for node.js that makes communicating with IMAP servers easy", "main": "./lib/Connection", diff --git a/test/test-parser.js b/test/test-parser.js index 39d1723d1..01236a749 100644 --- a/test/test-parser.js +++ b/test/test-parser.js @@ -310,6 +310,15 @@ var CR = '\r', LF = '\n', CRLF = CR + LF; ], what: 'Untagged FETCH with non-body literal' }, + { source: ['* 1 FETCH (12345 NIL)', CRLF], + expected: [ { type: 'fetch', + num: 1, + textCode: undefined, + text: { '12345': null } + } + ], + what: 'Untagged FETCH with integer-shaped key token (regression: no TypeError on .toLowerCase)' + }, { source: ['* 12 FETCH (INTERNALDATE {2', '6}' + CRLF + '17-Jul-1996 02:44:25 -0700)' + CRLF], expected: [ { type: 'fetch',