From 8ffa4808f4c4b14263bfd592900e43b4ba14f366 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Mon, 9 Oct 2017 08:17:04 +0300 Subject: [PATCH] Send confirmation notifications while IDELing --- imap-core/lib/imap-connection.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/imap-core/lib/imap-connection.js b/imap-core/lib/imap-connection.js index 51371d4b..57de2239 100644 --- a/imap-core/lib/imap-connection.js +++ b/imap-core/lib/imap-connection.js @@ -12,7 +12,7 @@ const EventEmitter = require('events').EventEmitter; const packageInfo = require('../../package'); const errors = require('../../lib/errors.js'); -const SOCKET_TIMEOUT = 30 * 60 * 1000; +const SOCKET_TIMEOUT = 10 * 60 * 1000; /** * Creates a handler for new socket @@ -161,14 +161,17 @@ class IMAPConnection extends EventEmitter { /** * Close socket */ - close() { + close(force) { if (!this._socket.destroyed && this._socket.writable) { - this._socket.end(); + this._socket[!force ? 'end' : 'destroy'](); } this._server.connections.delete(this); this._closing = true; + if (force) { + setImmediate(() => this._onClose()); + } } // PRIVATE METHODS @@ -308,11 +311,15 @@ class IMAPConnection extends EventEmitter { '[%s] Connection TIMEOUT', this.id ); + if (this.idling) { - return; // ignore timeouts when IDLEing + // see if the connection still works + this.send('* OK Still here'); + return; } + this.send('* BYE Idle timeout, closing connection'); - this.close(); + this.close(true); // force connection to close } /**