diff --git a/lib/imap-flow.js b/lib/imap-flow.js index 3fd5cd3..e4118c9 100644 --- a/lib/imap-flow.js +++ b/lib/imap-flow.js @@ -387,9 +387,18 @@ class ImapFlow extends EventEmitter { } write(chunk) { - if (this.socket.destroyed || this.state === this.states.LOGOUT) { + if (this.socket.destroyed) { // do not write after connection end or logout - return; + const error = new Error('Socket is already closed'); + error.code = 'NoConnection'; + throw error; + } + + if (this.state === this.states.LOGOUT) { + // should not happen + const error = new Error('Can not send data after logged out'); + error.code = 'StateLogout'; + throw error; } if (this.writeSocket.destroyed) { @@ -471,6 +480,7 @@ class ImapFlow extends EventEmitter { let options = data.options || {}; this.log.debug({ src: 's', msg: logCompiled.toString(), cid: this.id, comment: options.comment }); + this.write(this.commandParts.shift()); if (typeof options.onSend === 'function') {