Dont try to connect to imap when navigator is offline

This commit is contained in:
Tankred Hase 2015-03-04 14:16:44 +01:00
parent 1806f78ef3
commit 6ceb877472
3 changed files with 20 additions and 0 deletions

View File

@ -1017,6 +1017,13 @@ Email.prototype.encrypt = function(options) {
Email.prototype.onConnect = function(imap) {
var self = this;
if (!self.isOnline()) {
// don't try to connect when navigator is offline
return new Promise(function(resolve) {
resolve();
});
}
self._account.loggingIn = true;
// init imap/smtp clients

View File

@ -293,6 +293,7 @@ describe('Email DAO integration tests', function() {
passphrase: testAccount.pass,
keypair: mockKeyPair
}).then(function() {
sinon.stub(accountService._emailDao, 'isOnline').returns(true);
accountService._emailDao.onConnect(imapClient);
});
});

View File

@ -1956,6 +1956,7 @@ describe('Email DAO unit tests', function() {
beforeEach(function() {
initFoldersStub = sinon.stub(dao, '_initFoldersFromImap');
sinon.stub(dao, 'isOnline');
delete dao._imapClient;
credentials = {
@ -1968,6 +1969,7 @@ describe('Email DAO unit tests', function() {
uid: 123,
modseq: '123'
}];
dao.isOnline.returns(true);
authStub.getCredentials.returns(resolves(credentials));
imapClientStub.login.returns(resolves());
imapClientStub.selectMailbox.returns(resolves());
@ -1990,6 +1992,16 @@ describe('Email DAO unit tests', function() {
done();
});
});
it('should not connect when user agent is offline', function(done) {
dao.isOnline.returns(false);
dao.onConnect(imapClientStub).then(function() {
expect(authStub.getCredentials.called).to.be.false;
done();
});
});
});
describe('#onDisconnect', function() {