mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-09-06 13:14:34 +08:00
use public properties to check if a socket is open or not
This commit is contained in:
parent
9c04a286e2
commit
425652d4c0
4 changed files with 4 additions and 10 deletions
|
@ -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]) {
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Add table
Reference in a new issue