1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-22 17:02:17 -05:00

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) { Email.prototype.onConnect = function(imap) {
var self = this; 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; self._account.loggingIn = true;
// init imap/smtp clients // init imap/smtp clients

View File

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

View File

@ -1956,6 +1956,7 @@ describe('Email DAO unit tests', function() {
beforeEach(function() { beforeEach(function() {
initFoldersStub = sinon.stub(dao, '_initFoldersFromImap'); initFoldersStub = sinon.stub(dao, '_initFoldersFromImap');
sinon.stub(dao, 'isOnline');
delete dao._imapClient; delete dao._imapClient;
credentials = { credentials = {
@ -1968,6 +1969,7 @@ describe('Email DAO unit tests', function() {
uid: 123, uid: 123,
modseq: '123' modseq: '123'
}]; }];
dao.isOnline.returns(true);
authStub.getCredentials.returns(resolves(credentials)); authStub.getCredentials.returns(resolves(credentials));
imapClientStub.login.returns(resolves()); imapClientStub.login.returns(resolves());
imapClientStub.selectMailbox.returns(resolves()); imapClientStub.selectMailbox.returns(resolves());
@ -1990,6 +1992,16 @@ describe('Email DAO unit tests', function() {
done(); 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() { describe('#onDisconnect', function() {