Send confirmation notifications while IDELing

This commit is contained in:
Andris Reinman 2017-10-09 08:17:04 +03:00
parent 69477d3a6d
commit 8ffa4808f4

View file

@ -12,7 +12,7 @@ const EventEmitter = require('events').EventEmitter;
const packageInfo = require('../../package'); const packageInfo = require('../../package');
const errors = require('../../lib/errors.js'); const errors = require('../../lib/errors.js');
const SOCKET_TIMEOUT = 30 * 60 * 1000; const SOCKET_TIMEOUT = 10 * 60 * 1000;
/** /**
* Creates a handler for new socket * Creates a handler for new socket
@ -161,14 +161,17 @@ class IMAPConnection extends EventEmitter {
/** /**
* Close socket * Close socket
*/ */
close() { close(force) {
if (!this._socket.destroyed && this._socket.writable) { if (!this._socket.destroyed && this._socket.writable) {
this._socket.end(); this._socket[!force ? 'end' : 'destroy']();
} }
this._server.connections.delete(this); this._server.connections.delete(this);
this._closing = true; this._closing = true;
if (force) {
setImmediate(() => this._onClose());
}
} }
// PRIVATE METHODS // PRIVATE METHODS
@ -308,11 +311,15 @@ class IMAPConnection extends EventEmitter {
'[%s] Connection TIMEOUT', '[%s] Connection TIMEOUT',
this.id this.id
); );
if (this.idling) { 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.send('* BYE Idle timeout, closing connection');
this.close(); this.close(true); // force connection to close
} }
/** /**