From 91714b7dda2c9cdedfef68a4dd763cdd46d630de Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Mon, 19 Jul 2021 14:23:08 +0200 Subject: [PATCH] WIP --- lib/Connection.js | 73 ++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/lib/Connection.js b/lib/Connection.js index 5a712e2..93c0e86 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -1379,6 +1379,47 @@ let commandHandlers = createCommandHandlers({ }, "CAPABILITY": function (_request, { payload }) { this._caps = payload.map((v) => v.toUpperCase()); + }, + "NAMESPACE": function (_request, { payload }) { + this.namespaces = payload; + }, + "PREAUTH": function (_request, _) { + this.state = 'authenticated'; + }, + "EXPUNGE": function (_request, { sequenceNumber }) { + if (this._box != null) { + if (this._box.messages.total > 0) { + this._box.messages.total -= 1; + } + + this.emit('expunge', sequenceNumber); + } + }, + } + }, + "STATUS": { + untagged: { + "STATUS": function (request, { payload }) { + // REFACTOR: Improve this? + let attrs = defaultValue(payload.attrs, {}); + + let box = { + name: payload.name, + uidnext: defaultValue(attrs.uidnext, 0), + uidvalidity: defaultValue(attrs.uidvalidity, 0), + messages: { + total: defaultValue(attrs.messages, 0), + new: defaultValue(attrs.recent, 0), + unseen: defaultValue(attrs.unseen, 0) + }, + // CONDSTORE + highestmodseq: (attrs.highestmodseq != null) + ? String(attrs.highestmodseq) + : undefined + }; + + request.legacyArgs.push(box); + Object.assign(request.responseData, box); } } }, @@ -1533,18 +1574,6 @@ Connection.prototype._resUntagged = function({ type, num: sequenceNumber, textCo if (commandHandlers.canHandleUntagged(this._curReq, response)) { // FIXME: Include other fields commandHandlers.handleUntagged.call(this, this._curReq, response); - } else if (type === 'namespace') { - this.namespaces = payload; - } else if (type === 'preauth') { - this.state = 'authenticated'; - } else if (type === 'expunge') { - if (this._box) { - if (this._box.messages.total > 0) { - this._box.messages.total -= 1; - } - - this.emit('expunge', sequenceNumber); - } } else if (type === 'ok') { if (this.state === 'connected' && !this._curReq) { this._login(); @@ -1598,26 +1627,6 @@ Connection.prototype._resUntagged = function({ type, num: sequenceNumber, textCo this.emit('error', err); this._sock.end(); } - } else if (type === 'status') { - let attrs = defaultValue(payload.attrs, {}); - - box = { - name: payload.name, - uidnext: defaultValue(attrs.uidnext, 0), - uidvalidity: defaultValue(attrs.uidvalidity, 0), - messages: { - total: defaultValue(attrs.messages, 0), - new: defaultValue(attrs.recent, 0), - unseen: defaultValue(attrs.unseen, 0) - }, - // CONDSTORE - highestmodseq: (attrs.highestmodseq != null) - ? String(attrs.highestmodseq) - : undefined - }; - - // FIXME - this._curReq.cbargs.push(box); } else if (type === 'fetch') { if (/^(?:UID )?FETCH/.test(this._curReq.fullcmd)) { // FETCH response sent as result of FETCH request