Comparing version 1.0.132 to 1.0.133
@@ -17,3 +17,3 @@ 'use strict'; | ||
connection.mailbox = false; | ||
connection.mailboxOptions = false; | ||
connection.currentSelectCommand = false; | ||
connection.state = connection.states.AUTHENTICATED; | ||
@@ -20,0 +20,0 @@ |
@@ -141,4 +141,7 @@ 'use strict'; | ||
let idleTimer; | ||
return new Promise(resolve => { | ||
if (!connection.currentSelectCommand) { | ||
return resolve(); | ||
} | ||
return new Promise(resolve => { | ||
// no IDLE support, fallback to NOOP'ing | ||
@@ -153,2 +156,4 @@ connection.preCheck = async () => { | ||
let selectCommand = connection.currentSelectCommand; | ||
let idleCheck = async () => { | ||
@@ -159,4 +164,16 @@ let response; | ||
connection.log.debug({ src: 'c', msg: `Running SELECT to detect changes in folder` }); | ||
response = await connection.exec('SELECT', connection.mailbox.path, connection.mailboxOptions); | ||
response = await connection.exec(selectCommand.command, selectCommand.arguments); | ||
break; | ||
case 'STATUS': | ||
{ | ||
let statusArgs = [selectCommand.arguments[0], []]; // path | ||
for (let key of ['MESSAGES', 'UIDNEXT', 'UIDVALIDITY', 'UNSEEN']) { | ||
statusArgs[1].push({ type: 'ATOM', value: key.toUpperCase() }); | ||
} | ||
connection.log.debug({ src: 'c', msg: `Running STATUS to detect changes in folder` }); | ||
response = await connection.exec('STATUS', statusArgs); | ||
} | ||
break; | ||
case 'NOOP': | ||
@@ -163,0 +180,0 @@ default: |
@@ -52,101 +52,102 @@ 'use strict'; | ||
response = await connection.exec( | ||
!options.readOnly ? 'SELECT' : 'EXAMINE', | ||
[{ type: encodedPath.indexOf('&') >= 0 ? 'STRING' : 'ATOM', value: encodedPath }].concat(extraArgs || []), | ||
{ | ||
untagged: { | ||
OK: async untagged => { | ||
if (!untagged.attributes || !untagged.attributes.length) { | ||
return; | ||
} | ||
let section = !untagged.attributes[0].value && untagged.attributes[0].section; | ||
if (section && section.length > 1 && section[0].type === 'ATOM' && typeof section[0].value === 'string') { | ||
let key = section[0].value.toLowerCase(); | ||
let value; | ||
let selectCommand = { | ||
command: !options.readOnly ? 'SELECT' : 'EXAMINE', | ||
arguments: [{ type: encodedPath.indexOf('&') >= 0 ? 'STRING' : 'ATOM', value: encodedPath }].concat(extraArgs || []) | ||
}; | ||
if (typeof section[1].value === 'string') { | ||
value = section[1].value; | ||
} else if (Array.isArray(section[1])) { | ||
value = section[1].map(entry => (typeof entry.value === 'string' ? entry.value : false)).filter(entry => entry); | ||
} | ||
response = await connection.exec(selectCommand.command, selectCommand.arguments, { | ||
untagged: { | ||
OK: async untagged => { | ||
if (!untagged.attributes || !untagged.attributes.length) { | ||
return; | ||
} | ||
let section = !untagged.attributes[0].value && untagged.attributes[0].section; | ||
if (section && section.length > 1 && section[0].type === 'ATOM' && typeof section[0].value === 'string') { | ||
let key = section[0].value.toLowerCase(); | ||
let value; | ||
switch (key) { | ||
case 'highestmodseq': | ||
key = 'highestModseq'; | ||
if (/^[0-9]+$/.test(value)) { | ||
value = BigInt(value); | ||
} | ||
break; | ||
if (typeof section[1].value === 'string') { | ||
value = section[1].value; | ||
} else if (Array.isArray(section[1])) { | ||
value = section[1].map(entry => (typeof entry.value === 'string' ? entry.value : false)).filter(entry => entry); | ||
} | ||
case 'mailboxid': | ||
key = 'mailboxId'; | ||
if (Array.isArray(value) && value.length) { | ||
value = value[0]; | ||
} | ||
break; | ||
switch (key) { | ||
case 'highestmodseq': | ||
key = 'highestModseq'; | ||
if (/^[0-9]+$/.test(value)) { | ||
value = BigInt(value); | ||
} | ||
break; | ||
case 'permanentflags': | ||
key = 'permanentFlags'; | ||
value = new Set(value); | ||
break; | ||
case 'mailboxid': | ||
key = 'mailboxId'; | ||
if (Array.isArray(value) && value.length) { | ||
value = value[0]; | ||
} | ||
break; | ||
case 'uidnext': | ||
key = 'uidNext'; | ||
value = Number(value); | ||
break; | ||
case 'permanentflags': | ||
key = 'permanentFlags'; | ||
value = new Set(value); | ||
break; | ||
case 'uidvalidity': | ||
key = 'uidValidity'; | ||
if (/^[0-9]+$/.test(value)) { | ||
value = BigInt(value); | ||
} | ||
break; | ||
} | ||
case 'uidnext': | ||
key = 'uidNext'; | ||
value = Number(value); | ||
break; | ||
map[key] = value; | ||
case 'uidvalidity': | ||
key = 'uidValidity'; | ||
if (/^[0-9]+$/.test(value)) { | ||
value = BigInt(value); | ||
} | ||
break; | ||
} | ||
if (section && section.length === 1 && section[0].type === 'ATOM' && typeof section[0].value === 'string') { | ||
let key = section[0].value.toLowerCase(); | ||
switch (key) { | ||
case 'nomodseq': | ||
key = 'noModseq'; | ||
map[key] = true; | ||
break; | ||
} | ||
map[key] = value; | ||
} | ||
if (section && section.length === 1 && section[0].type === 'ATOM' && typeof section[0].value === 'string') { | ||
let key = section[0].value.toLowerCase(); | ||
switch (key) { | ||
case 'nomodseq': | ||
key = 'noModseq'; | ||
map[key] = true; | ||
break; | ||
} | ||
}, | ||
FLAGS: async untagged => { | ||
if (!untagged.attributes || (!untagged.attributes.length && Array.isArray(untagged.attributes[0]))) { | ||
return; | ||
} | ||
let flags = untagged.attributes[0].map(flag => (typeof flag.value === 'string' ? flag.value : false)).filter(flag => flag); | ||
map.flags = new Set(flags); | ||
}, | ||
EXISTS: async untagged => { | ||
let num = Number(untagged.command); | ||
if (isNaN(num)) { | ||
return false; | ||
} | ||
} | ||
}, | ||
FLAGS: async untagged => { | ||
if (!untagged.attributes || (!untagged.attributes.length && Array.isArray(untagged.attributes[0]))) { | ||
return; | ||
} | ||
let flags = untagged.attributes[0].map(flag => (typeof flag.value === 'string' ? flag.value : false)).filter(flag => flag); | ||
map.flags = new Set(flags); | ||
}, | ||
EXISTS: async untagged => { | ||
let num = Number(untagged.command); | ||
if (isNaN(num)) { | ||
return false; | ||
} | ||
map.exists = num; | ||
}, | ||
VANISHED: async untagged => { | ||
await connection.untaggedVanished( | ||
untagged, | ||
// mailbox is not yet open, so use a dummy mailbox object | ||
{ path, uidNext: false, uidValidity: false } | ||
); | ||
}, | ||
// we should only get an untagged FETCH for a SELECT/EXAMINE if QRESYNC was asked for | ||
FETCH: async untagged => { | ||
await connection.untaggedFetch( | ||
untagged, | ||
// mailbox is not yet open, so use a dummy mailbox object | ||
{ path, uidNext: false, uidValidity: false } | ||
); | ||
} | ||
map.exists = num; | ||
}, | ||
VANISHED: async untagged => { | ||
await connection.untaggedVanished( | ||
untagged, | ||
// mailbox is not yet open, so use a dummy mailbox object | ||
{ path, uidNext: false, uidValidity: false } | ||
); | ||
}, | ||
// we should only get an untagged FETCH for a SELECT/EXAMINE if QRESYNC was asked for | ||
FETCH: async untagged => { | ||
await connection.untaggedFetch( | ||
untagged, | ||
// mailbox is not yet open, so use a dummy mailbox object | ||
{ path, uidNext: false, uidValidity: false } | ||
); | ||
} | ||
} | ||
); | ||
}); | ||
@@ -187,3 +188,3 @@ let section = !response.response.attributes[0].value && response.response.attributes[0].section; | ||
connection.mailbox = map; | ||
connection.mailboxOptions = options; | ||
connection.currentSelectCommand = selectCommand; | ||
connection.state = connection.states.SELECTED; | ||
@@ -210,3 +211,3 @@ | ||
connection.mailbox = false; | ||
connection.mailboxOptions = false; | ||
connection.currentSelectCommand = false; | ||
connection.state = connection.states.AUTHENTICATED; | ||
@@ -213,0 +214,0 @@ |
{ | ||
"name": "imapflow", | ||
"version": "1.0.132", | ||
"version": "1.0.133", | ||
"description": "IMAP Client for Node", | ||
@@ -5,0 +5,0 @@ "main": "./lib/imap-flow.js", |
Sorry, the diff of this file is too big to display
555863
12363