diff --git a/imap-core/lib/imap-connection.js b/imap-core/lib/imap-connection.js index 06fa4c5b..04b712b2 100644 --- a/imap-core/lib/imap-connection.js +++ b/imap-core/lib/imap-connection.js @@ -203,7 +203,7 @@ class IMAPConnection extends EventEmitter { * @param {String|Array} data If data is Array, send a multi-line response */ send(payload, callback) { - if (this._socket && this._socket.writable) { + if (this._socket && !this._socket.destroyed && this._socket.readyState === 'open') { try { this[!this.compression ? '_socket' : '_deflate'].write(payload + '\r\n', 'binary', (...args) => { if (args[0]) { diff --git a/imap-core/lib/imap-tools.js b/imap-core/lib/imap-tools.js index fcf85b3e..5c16f792 100644 --- a/imap-core/lib/imap-tools.js +++ b/imap-core/lib/imap-tools.js @@ -744,7 +744,6 @@ module.exports.sendCapabilityResponse = connection => { capabilities.push('SPECIAL-USE'); capabilities.push('UIDPLUS'); - capabilities.push('UNSELECT'); capabilities.push('ENABLE'); capabilities.push('CONDSTORE'); capabilities.push('UTF8=ACCEPT'); diff --git a/lib/pop3/connection.js b/lib/pop3/connection.js index 7bb1973c..967bc7c0 100644 --- a/lib/pop3/connection.js +++ b/lib/pop3/connection.js @@ -70,14 +70,14 @@ class POP3Connection extends EventEmitter { } write(payload) { - if (!this._socket || !this._socket.writable) { + if (!this._socket || this._socket.destroyed || this._socket.readyState !== 'open') { return; } this._socket.write(payload); } send(payload) { - if (!this._socket || !this._socket.writable) { + if (!this._socket || this._socket.destroyed || this._socket.readyState !== 'open') { return; } diff --git a/lib/tools.js b/lib/tools.js index 914ccf82..5af63f47 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -459,14 +459,9 @@ function validationErrors(validationResult) { } function checkSocket(socket) { - if (!socket || !socket._writableState || !socket._readableState) { + if (!socket || socket.destroyed || socket.readyState !== 'open') { throw new Error('Socket not open'); } - for (let s of [socket._writableState, socket._readableState]) { - if (s.destroyed || s.errored || s.closed) { - throw new Error('Socket not open'); - } - } } module.exports = {