mirror of
https://github.com/moparisthebest/mail
synced 2024-11-28 20:02:16 -05:00
refactor imap login out of email dao.init
This commit is contained in:
parent
c4b4999814
commit
ee7d179298
@ -10,7 +10,7 @@ define(function(require) {
|
|||||||
// start the main app controller
|
// start the main app controller
|
||||||
appController.fetchOAuthToken('passphrase', function(err) {
|
appController.fetchOAuthToken('passphrase', function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,29 +39,45 @@ define(function(require) {
|
|||||||
offset: offset,
|
offset: offset,
|
||||||
num: num
|
num: num
|
||||||
}, function() {
|
}, function() {
|
||||||
// sync from imap to local db
|
// login to imap
|
||||||
syncImapFolder({
|
loginImap(function() {
|
||||||
folder: $scope.folder,
|
// sync from imap to local db
|
||||||
offset: offset,
|
syncImapFolder({
|
||||||
num: num
|
|
||||||
}, function() {
|
|
||||||
// list again from local db after syncing
|
|
||||||
listLocalMessages({
|
|
||||||
folder: $scope.folder,
|
folder: $scope.folder,
|
||||||
offset: offset,
|
offset: offset,
|
||||||
num: num
|
num: num
|
||||||
}, function() {
|
}, function() {
|
||||||
console.log('syncing ' + $scope.folder + ' complete');
|
// list again from local db after syncing
|
||||||
|
listLocalMessages({
|
||||||
|
folder: $scope.folder,
|
||||||
|
offset: offset,
|
||||||
|
num: num
|
||||||
|
}, function() {
|
||||||
|
console.log('Syncing ' + $scope.folder + ' complete.');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loginImap(callback) {
|
||||||
|
emailDao.imapLogin(function(err) {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Logged in to IMAP.');
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function syncImapFolder(options, callback) {
|
function syncImapFolder(options, callback) {
|
||||||
|
console.log('Syncing IMAP...');
|
||||||
// sync if emails are empty
|
// sync if emails are empty
|
||||||
emailDao.imapSync(options, function(err) {
|
emailDao.imapSync(options, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +88,7 @@ define(function(require) {
|
|||||||
function listLocalMessages(options, callback) {
|
function listLocalMessages(options, callback) {
|
||||||
emailDao.listMessages(options, function(err, emails) {
|
emailDao.listMessages(options, function(err, emails) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// add display dates
|
// add display dates
|
||||||
|
@ -36,18 +36,8 @@ define(function(require) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// login IMAP client if existent
|
// init keychain and then crypto module
|
||||||
if (self._imapClient) {
|
initKeychain();
|
||||||
self._imapClient.login(function(err) {
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
initKeychain();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
initKeychain();
|
|
||||||
}
|
|
||||||
|
|
||||||
function initKeychain() {
|
function initKeychain() {
|
||||||
// init user's local database
|
// init user's local database
|
||||||
@ -91,6 +81,16 @@ define(function(require) {
|
|||||||
// IMAP/SMTP Apis
|
// IMAP/SMTP Apis
|
||||||
//
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Login the imap client
|
||||||
|
*/
|
||||||
|
EmailDAO.prototype.imapLogin = function(callback) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
// login IMAP client if existent
|
||||||
|
self._imapClient.login(callback);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleanup by logging the user off.
|
* Cleanup by logging the user off.
|
||||||
*/
|
*/
|
||||||
|
@ -58,37 +58,24 @@ define(function(require) {
|
|||||||
afterEach(function() {});
|
afterEach(function() {});
|
||||||
|
|
||||||
describe('init', function() {
|
describe('init', function() {
|
||||||
it('should fail due to error in imap login', function(done) {
|
|
||||||
imapClientStub.login.yields(42);
|
|
||||||
|
|
||||||
emailDao.init(account, emaildaoTest.passphrase, function(err) {
|
|
||||||
expect(err).to.equal(42);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail due to error in getUserKeyPair', function(done) {
|
it('should fail due to error in getUserKeyPair', function(done) {
|
||||||
imapClientStub.login.yields();
|
|
||||||
devicestorageStub.init.yields();
|
devicestorageStub.init.yields();
|
||||||
keychainStub.getUserKeyPair.yields(42);
|
keychainStub.getUserKeyPair.yields(42);
|
||||||
|
|
||||||
emailDao.init(account, emaildaoTest.passphrase, function(err) {
|
emailDao.init(account, emaildaoTest.passphrase, function(err) {
|
||||||
expect(devicestorageStub.init.calledOnce).to.be.true;
|
expect(devicestorageStub.init.calledOnce).to.be.true;
|
||||||
expect(imapClientStub.login.calledOnce).to.be.true;
|
|
||||||
expect(err).to.equal(42);
|
expect(err).to.equal(42);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should init with new keygen', function(done) {
|
it('should init with new keygen', function(done) {
|
||||||
imapClientStub.login.yields();
|
|
||||||
devicestorageStub.init.yields();
|
devicestorageStub.init.yields();
|
||||||
keychainStub.getUserKeyPair.yields();
|
keychainStub.getUserKeyPair.yields();
|
||||||
cryptoStub.init.yields(null, {});
|
cryptoStub.init.yields(null, {});
|
||||||
keychainStub.putUserKeyPair.yields();
|
keychainStub.putUserKeyPair.yields();
|
||||||
|
|
||||||
emailDao.init(account, emaildaoTest.passphrase, function(err) {
|
emailDao.init(account, emaildaoTest.passphrase, function(err) {
|
||||||
expect(imapClientStub.login.calledOnce).to.be.true;
|
|
||||||
expect(devicestorageStub.init.calledOnce).to.be.true;
|
expect(devicestorageStub.init.calledOnce).to.be.true;
|
||||||
expect(keychainStub.getUserKeyPair.calledOnce).to.be.true;
|
expect(keychainStub.getUserKeyPair.calledOnce).to.be.true;
|
||||||
expect(cryptoStub.init.calledOnce).to.be.true;
|
expect(cryptoStub.init.calledOnce).to.be.true;
|
||||||
@ -99,16 +86,34 @@ define(function(require) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('login', function() {
|
||||||
|
it('should fail due to error in imap login', function(done) {
|
||||||
|
imapClientStub.login.yields(42);
|
||||||
|
|
||||||
|
emailDao.imapLogin(function(err) {
|
||||||
|
expect(err).to.equal(42);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work', function(done) {
|
||||||
|
imapClientStub.login.yields();
|
||||||
|
|
||||||
|
emailDao.imapLogin(function(err) {
|
||||||
|
expect(err).to.not.exist;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('IMAP/SMTP tests', function() {
|
describe('IMAP/SMTP tests', function() {
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
imapClientStub.login.yields();
|
|
||||||
devicestorageStub.init.yields();
|
devicestorageStub.init.yields();
|
||||||
keychainStub.getUserKeyPair.yields();
|
keychainStub.getUserKeyPair.yields();
|
||||||
cryptoStub.init.yields(null, {});
|
cryptoStub.init.yields(null, {});
|
||||||
keychainStub.putUserKeyPair.yields();
|
keychainStub.putUserKeyPair.yields();
|
||||||
|
|
||||||
emailDao.init(account, emaildaoTest.passphrase, function(err) {
|
emailDao.init(account, emaildaoTest.passphrase, function(err) {
|
||||||
expect(imapClientStub.login.calledOnce).to.be.true;
|
|
||||||
expect(devicestorageStub.init.calledOnce).to.be.true;
|
expect(devicestorageStub.init.calledOnce).to.be.true;
|
||||||
expect(keychainStub.getUserKeyPair.calledOnce).to.be.true;
|
expect(keychainStub.getUserKeyPair.calledOnce).to.be.true;
|
||||||
expect(cryptoStub.init.calledOnce).to.be.true;
|
expect(cryptoStub.init.calledOnce).to.be.true;
|
||||||
|
Loading…
Reference in New Issue
Block a user