diff --git a/package.json b/package.json index 2303719..f2e48cf 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "grunt-string-replace": "~1.0.0", "grunt-svgmin": "~1.0.0", "grunt-svgstore": "~0.3.4", - "imap-client": "~0.7.0", + "imap-client": "~0.8.0", "jquery": "~2.1.1", "mailreader": "~0.4.0", "mocha": "^1.21.4", @@ -72,4 +72,4 @@ "time-grunt": "^1.0.0", "wo-smtpclient": "~0.5.0" } -} \ No newline at end of file +} diff --git a/src/js/email/email.js b/src/js/email/email.js index 8ac597f..9c3c0c5 100644 --- a/src/js/email/email.js +++ b/src/js/email/email.js @@ -1218,20 +1218,19 @@ Email.prototype.onConnect = function(options, callback) { * It will discard the imap client and pgp mailer */ Email.prototype.onDisconnect = function(callback) { - var self = this; - // logout of imap-client - self._imapClient.logout(function() { - // ignore error, because it's not problem if logout fails - if (callback) { - callback(); - } - }); + // ignore error, because it's not problem if logout fails + this._imapClient.stopListeningForChanges(function() {}); + this._imapClient.logout(function() {}); // discard clients - self._account.online = false; - self._imapClient = undefined; - self._pgpMailer = undefined; + this._account.online = false; + this._imapClient = undefined; + this._pgpMailer = undefined; + + if (callback) { + callback(); + } }; /** diff --git a/test/integration/email-dao-test.js b/test/integration/email-dao-test.js index 91d4603..eb637a6 100644 --- a/test/integration/email-dao-test.js +++ b/test/integration/email-dao-test.js @@ -312,10 +312,11 @@ describe('Email DAO integration tests', function() { mailreader.startWorker.restore(); accountService.onConnect.restore(); - imapClient._client.close(); - imapClient._listeningClient.close(); - - userStorage.clear(done); + imapClient.stopListeningForChanges(function() { + imapClient.logout(function() { + userStorage.clear(done); + }); + }); }); describe('IMAP Integration Tests', function() { diff --git a/test/unit/email/email-dao-test.js b/test/unit/email/email-dao-test.js index 66d3397..08fbee6 100644 --- a/test/unit/email/email-dao-test.js +++ b/test/unit/email/email-dao-test.js @@ -1875,13 +1875,18 @@ describe('Email DAO unit tests', function() { describe('#onDisconnect', function() { it('should discard imapClient and pgpMailer', function(done) { - imapClientStub.logout.yieldsAsync(); + imapClientStub.stopListeningForChanges.yields(); + imapClientStub.logout.yields(); - dao.onDisconnect(done); + dao.onDisconnect(function() { + expect(imapClientStub.stopListeningForChanges.calledOnce).to.be.true; + expect(imapClientStub.logout.calledOnce).to.be.true; + expect(dao._account.online).to.be.false; + expect(dao._imapClient).to.not.exist; + expect(dao._pgpMailer).to.not.exist; + done(); + }); - expect(dao._account.online).to.be.false; - expect(dao._imapClient).to.not.exist; - expect(dao._pgpMailer).to.not.exist; }); });