mirror of
https://github.com/moparisthebest/mail
synced 2024-11-25 10:22:18 -05:00
[WO-795] Port to promises
This commit is contained in:
parent
f28c7854c3
commit
3da5a55251
@ -62,13 +62,13 @@
|
|||||||
"grunt-string-replace": "~1.0.0",
|
"grunt-string-replace": "~1.0.0",
|
||||||
"grunt-svgmin": "~1.0.0",
|
"grunt-svgmin": "~1.0.0",
|
||||||
"grunt-svgstore": "~0.3.4",
|
"grunt-svgstore": "~0.3.4",
|
||||||
"imap-client": "~0.10.0",
|
"imap-client": "https://github.com/whiteout-io/imap-client/tarball/dev/WO-794",
|
||||||
"jquery": "~2.1.1",
|
"jquery": "~2.1.1",
|
||||||
"mailreader": "~0.4.0",
|
"mailreader": "~0.4.0",
|
||||||
"mocha": "^1.21.4",
|
"mocha": "^1.21.4",
|
||||||
"ng-infinite-scroll": "~1.1.2",
|
"ng-infinite-scroll": "~1.1.2",
|
||||||
"pgpbuilder": "~0.5.0",
|
"pgpbuilder": "https://github.com/whiteout-io/pgpbuilder/tarball/dev/WO-795",
|
||||||
"pgpmailer": "~0.8.0",
|
"pgpmailer": "https://github.com/whiteout-io/pgpmailer/tarball/dev/WO-795",
|
||||||
"sinon": "~1.7.3",
|
"sinon": "~1.7.3",
|
||||||
"tcp-socket": "~0.5.0",
|
"tcp-socket": "~0.5.0",
|
||||||
"time-grunt": "^1.0.0",
|
"time-grunt": "^1.0.0",
|
||||||
|
@ -188,23 +188,16 @@ Email.prototype.unlock = function(options) {
|
|||||||
*/
|
*/
|
||||||
Email.prototype.openFolder = function(options) {
|
Email.prototype.openFolder = function(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve) {
|
||||||
self.checkOnline();
|
self.checkOnline();
|
||||||
|
resolve();
|
||||||
|
|
||||||
if (options.folder.path === config.outboxMailboxPath) {
|
}).then(function() {
|
||||||
resolve();
|
if (options.folder.path !== config.outboxMailboxPath) {
|
||||||
return;
|
return self._imapClient.selectMailbox({
|
||||||
|
path: options.folder.path
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
self._imapClient.selectMailbox({
|
|
||||||
path: options.folder.path
|
|
||||||
}, function(err, folder) {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve(folder);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@ -960,15 +953,7 @@ Email.prototype._sendGeneric = function(options, mailer) {
|
|||||||
}).then(function() {
|
}).then(function() {
|
||||||
|
|
||||||
// send the email
|
// send the email
|
||||||
return new Promise(function(resolve, reject) {
|
return self._pgpMailer.send(options);
|
||||||
self._pgpMailer.send(options, function(err, rfcText) {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve(rfcText);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}).then(function(rfcText) {
|
}).then(function(rfcText) {
|
||||||
// try to upload to sent, but we don't actually care if the upload failed or not
|
// try to upload to sent, but we don't actually care if the upload failed or not
|
||||||
// this should not negatively impact the process of sending
|
// this should not negatively impact the process of sending
|
||||||
@ -990,20 +975,14 @@ Email.prototype._sendGeneric = function(options, mailer) {
|
|||||||
* Signs and encrypts a message
|
* Signs and encrypts a message
|
||||||
*
|
*
|
||||||
* @param {Object} options.email The message to be encrypted
|
* @param {Object} options.email The message to be encrypted
|
||||||
* @param {Function} callback(error, message) Invoked when the message was encrypted, or an error occurred
|
* @param {Function} callback(message) Invoked when the message was encrypted, or an error occurred
|
||||||
*/
|
*/
|
||||||
Email.prototype.encrypt = function(options) {
|
Email.prototype.encrypt = function(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.busy();
|
self.busy();
|
||||||
return new Promise(function(resolve, reject) {
|
return self._pgpbuilder.encrypt(options).then(function(message) {
|
||||||
self._pgpbuilder.encrypt(options, function(err, message) {
|
self.done();
|
||||||
self.done();
|
return message;
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve(message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1043,15 +1022,7 @@ Email.prototype.onConnect = function(imap) {
|
|||||||
|
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
// imap login
|
// imap login
|
||||||
return new Promise(function(resolve, reject) {
|
return self._imapClient.login();
|
||||||
self._imapClient.login(function(err) {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
self._account.loggingIn = false;
|
self._account.loggingIn = false;
|
||||||
@ -1185,7 +1156,7 @@ Email.prototype._onSyncUpdate = function(options) {
|
|||||||
folder: folder,
|
folder: folder,
|
||||||
firstUid: Math.min.apply(null, options.list),
|
firstUid: Math.min.apply(null, options.list),
|
||||||
lastUid: Math.max.apply(null, options.list)
|
lastUid: Math.max.apply(null, options.list)
|
||||||
}, self._dialog.error);
|
}).then(self._dialog.error).catch(self._dialog.error);
|
||||||
} else if (options.type === SYNC_TYPE_DELETED) {
|
} else if (options.type === SYNC_TYPE_DELETED) {
|
||||||
// messages have been deleted, remove from local storage and memory
|
// messages have been deleted, remove from local storage and memory
|
||||||
options.list.forEach(function(uid) {
|
options.list.forEach(function(uid) {
|
||||||
@ -1201,7 +1172,7 @@ Email.prototype._onSyncUpdate = function(options) {
|
|||||||
folder: folder,
|
folder: folder,
|
||||||
message: message,
|
message: message,
|
||||||
localOnly: true
|
localOnly: true
|
||||||
}, self._dialog.error);
|
}).then(self._dialog.error).catch(self._dialog.error);
|
||||||
});
|
});
|
||||||
} else if (options.type === SYNC_TYPE_MSGS) {
|
} else if (options.type === SYNC_TYPE_MSGS) {
|
||||||
// NB! several possible reasons why this could be called.
|
// NB! several possible reasons why this could be called.
|
||||||
@ -1228,7 +1199,7 @@ Email.prototype._onSyncUpdate = function(options) {
|
|||||||
folder: folder,
|
folder: folder,
|
||||||
message: message,
|
message: message,
|
||||||
localOnly: true
|
localOnly: true
|
||||||
}, self._dialog.error);
|
}).then(self._dialog.error).catch(self._dialog.error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -1276,7 +1247,7 @@ Email.prototype._initFoldersFromImap = function() {
|
|||||||
self.busy(); // start the spinner
|
self.busy(); // start the spinner
|
||||||
|
|
||||||
// fetch list from imap server
|
// fetch list from imap server
|
||||||
return listWellknownFolder().then(function(wellKnownFolders) {
|
return self._imapClient.listWellKnownFolders().then(function(wellKnownFolders) {
|
||||||
var foldersChanged = false, // indicates if we need to persist anything to disk
|
var foldersChanged = false, // indicates if we need to persist anything to disk
|
||||||
imapFolders = []; // aggregate all the imap folders
|
imapFolders = []; // aggregate all the imap folders
|
||||||
|
|
||||||
@ -1409,18 +1380,6 @@ Email.prototype._initFoldersFromImap = function() {
|
|||||||
self.done(); // stop the spinner
|
self.done(); // stop the spinner
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
function listWellknownFolder() {
|
|
||||||
return new Promise(function(resolve, reject) {
|
|
||||||
self._imapClient.listWellKnownFolders(function(err, wellKnownFolders) {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve(wellKnownFolders);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1475,17 +1434,13 @@ Email.prototype.done = function() {
|
|||||||
*/
|
*/
|
||||||
Email.prototype._imapMark = function(options) {
|
Email.prototype._imapMark = function(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise(function(resolve, reject) {
|
|
||||||
self.checkOnline();
|
|
||||||
|
|
||||||
|
return new Promise(function(resolve) {
|
||||||
|
self.checkOnline();
|
||||||
|
resolve();
|
||||||
|
}).then(function() {
|
||||||
options.path = options.folder.path;
|
options.path = options.folder.path;
|
||||||
self._imapClient.updateFlags(options, function(err) {
|
return self._imapClient.updateFlags(options);
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1510,7 +1465,10 @@ Email.prototype._imapDeleteMessage = function(options) {
|
|||||||
|
|
||||||
// there's no known trash folder to move the mail to or we're in the trash folder, so we can purge the message
|
// there's no known trash folder to move the mail to or we're in the trash folder, so we can purge the message
|
||||||
if (!trash || options.folder === trash) {
|
if (!trash || options.folder === trash) {
|
||||||
return imapDelete();
|
return self._imapClient.deleteMessage({
|
||||||
|
path: options.folder.path,
|
||||||
|
uid: options.uid
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return self._imapMoveMessage({
|
return self._imapMoveMessage({
|
||||||
@ -1519,21 +1477,6 @@ Email.prototype._imapDeleteMessage = function(options) {
|
|||||||
uid: options.uid
|
uid: options.uid
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function imapDelete() {
|
|
||||||
return new Promise(function(resolve, reject) {
|
|
||||||
self._imapClient.deleteMessage({
|
|
||||||
path: options.folder.path,
|
|
||||||
uid: options.uid
|
|
||||||
}, function(err) {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1546,19 +1489,14 @@ Email.prototype._imapDeleteMessage = function(options) {
|
|||||||
*/
|
*/
|
||||||
Email.prototype._imapMoveMessage = function(options) {
|
Email.prototype._imapMoveMessage = function(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve) {
|
||||||
self.checkOnline();
|
self.checkOnline();
|
||||||
|
resolve();
|
||||||
self._imapClient.moveMessage({
|
}).then(function() {
|
||||||
|
return self._imapClient.moveMessage({
|
||||||
path: options.folder.path,
|
path: options.folder.path,
|
||||||
destination: options.destination.path,
|
destination: options.destination.path,
|
||||||
uid: options.uid
|
uid: options.uid
|
||||||
}, function(err) {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -1575,17 +1513,12 @@ Email.prototype._imapMoveMessage = function(options) {
|
|||||||
*/
|
*/
|
||||||
Email.prototype._imapListMessages = function(options) {
|
Email.prototype._imapListMessages = function(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve) {
|
||||||
self.checkOnline();
|
self.checkOnline();
|
||||||
|
resolve();
|
||||||
|
}).then(function() {
|
||||||
options.path = options.folder.path;
|
options.path = options.folder.path;
|
||||||
self._imapClient.listMessages(options, function(err, messages) {
|
return self._imapClient.listMessages(options);
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve(messages);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1597,17 +1530,10 @@ Email.prototype._imapListMessages = function(options) {
|
|||||||
*/
|
*/
|
||||||
Email.prototype._imapUploadMessage = function(options) {
|
Email.prototype._imapUploadMessage = function(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise(function(resolve, reject) {
|
|
||||||
self._imapClient.uploadMessage({
|
return self._imapClient.uploadMessage({
|
||||||
path: options.folder.path,
|
path: options.folder.path,
|
||||||
message: options.message
|
message: options.message
|
||||||
}, function(err) {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1619,26 +1545,14 @@ Email.prototype._imapUploadMessage = function(options) {
|
|||||||
*/
|
*/
|
||||||
Email.prototype._getBodyParts = function(options) {
|
Email.prototype._getBodyParts = function(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve) {
|
||||||
self.checkOnline();
|
self.checkOnline();
|
||||||
|
resolve();
|
||||||
|
}).then(function() {
|
||||||
options.path = options.folder.path;
|
options.path = options.folder.path;
|
||||||
self._imapClient.getBodyParts(options, function(err) {
|
return self._imapClient.getBodyParts(options);
|
||||||
if (err) {
|
}).then(function() {
|
||||||
reject(err);
|
return self._parse(options);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// interpret the raw content of the email
|
|
||||||
self._mailreader.parse(options, function(err, message) {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve(message);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -218,25 +218,21 @@ ConnectionDoctor.prototype._checkImap = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self._imap.login(function() {
|
self._imap.login().then(function() {
|
||||||
loggedIn = true;
|
loggedIn = true;
|
||||||
|
return self._imap.listWellKnownFolders();
|
||||||
|
}).then(function(wellKnownFolders) {
|
||||||
|
if (wellKnownFolders.Inbox.length === 0) {
|
||||||
|
// the client needs at least an inbox folder to work properly
|
||||||
|
reject(createError(NO_INBOX, str.connDocNoInbox.replace('{0}', host)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self._imap.listWellKnownFolders(function(error, wellKnownFolders) {
|
return self._imap.logout();
|
||||||
if (error) {
|
}).then(function(){
|
||||||
reject(createError(GENERIC_ERROR, str.connDocGenericError.replace('{0}', host).replace('{1}', error.message), error));
|
resolve();
|
||||||
return;
|
}).catch(function(error) {
|
||||||
}
|
reject(createError(GENERIC_ERROR, str.connDocGenericError.replace('{0}', host).replace('{1}', error.message), error));
|
||||||
|
|
||||||
if (wellKnownFolders.Inbox.length === 0) {
|
|
||||||
// the client needs at least an inbox folder to work properly
|
|
||||||
reject(createError(NO_INBOX, str.connDocNoInbox.replace('{0}', host)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self._imap.logout(function() {
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -305,11 +305,11 @@ describe('Email DAO integration tests', function() {
|
|||||||
openpgp.initWorker.restore();
|
openpgp.initWorker.restore();
|
||||||
mailreader.startWorker.restore();
|
mailreader.startWorker.restore();
|
||||||
|
|
||||||
imapClient.stopListeningForChanges(function() {
|
imapClient.stopListeningForChanges().then(function() {
|
||||||
imapClient.logout(function() {
|
return imapClient.logout();
|
||||||
userStorage.clear().then(done);
|
}).then(function() {
|
||||||
});
|
return userStorage.clear();
|
||||||
});
|
}).then(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('IMAP Integration Tests', function() {
|
describe('IMAP Integration Tests', function() {
|
||||||
|
@ -294,7 +294,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
it('should open an imap mailbox', function(done) {
|
it('should open an imap mailbox', function(done) {
|
||||||
imapClientStub.selectMailbox.withArgs({
|
imapClientStub.selectMailbox.withArgs({
|
||||||
path: inboxFolder.path
|
path: inboxFolder.path
|
||||||
}).yieldsAsync();
|
}).returns(resolves());
|
||||||
|
|
||||||
dao.openFolder({
|
dao.openFolder({
|
||||||
folder: inboxFolder
|
folder: inboxFolder
|
||||||
@ -534,7 +534,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
content: '' + cfg.cloudUrl + cfg.verificationUrl + validUuid
|
content: '' + cfg.cloudUrl + cfg.verificationUrl + validUuid
|
||||||
}]));
|
}]));
|
||||||
|
|
||||||
keychainStub.verifyPublicKey.withArgs(validUuid).yieldsAsync({});
|
keychainStub.verifyPublicKey.withArgs(validUuid).returns(rejects({}));
|
||||||
|
|
||||||
localStoreStub.withArgs({
|
localStoreStub.withArgs({
|
||||||
folder: inboxFolder,
|
folder: inboxFolder,
|
||||||
@ -1641,7 +1641,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
imapClientStub.uploadMessage.withArgs({
|
imapClientStub.uploadMessage.withArgs({
|
||||||
path: sentFolder.path,
|
path: sentFolder.path,
|
||||||
message: msg
|
message: msg
|
||||||
}).yields();
|
}).returns(resolves());
|
||||||
|
|
||||||
authStub.getCredentials.returns(resolves(credentials));
|
authStub.getCredentials.returns(resolves(credentials));
|
||||||
pgpMailerStub.send.withArgs({
|
pgpMailerStub.send.withArgs({
|
||||||
@ -1649,7 +1649,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
mail: dummyMail,
|
mail: dummyMail,
|
||||||
smtpclient: undefined,
|
smtpclient: undefined,
|
||||||
publicKeysArmored: publicKeys
|
publicKeysArmored: publicKeys
|
||||||
}).yieldsAsync(null, msg);
|
}).returns(resolves(msg));
|
||||||
|
|
||||||
dao.sendEncrypted({
|
dao.sendEncrypted({
|
||||||
email: dummyMail
|
email: dummyMail
|
||||||
@ -1672,7 +1672,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
mail: dummyMail,
|
mail: dummyMail,
|
||||||
smtpclient: undefined,
|
smtpclient: undefined,
|
||||||
publicKeysArmored: publicKeys
|
publicKeysArmored: publicKeys
|
||||||
}).yieldsAsync(null, msg);
|
}).returns(resolves(msg));
|
||||||
|
|
||||||
dao.sendEncrypted({
|
dao.sendEncrypted({
|
||||||
email: dummyMail
|
email: dummyMail
|
||||||
@ -1687,8 +1687,8 @@ describe('Email DAO unit tests', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should send encrypted and ignore error on upload', function(done) {
|
it('should send encrypted and ignore error on upload', function(done) {
|
||||||
imapClientStub.uploadMessage.yields(new Error());
|
imapClientStub.uploadMessage.returns(rejects(new Error()));
|
||||||
pgpMailerStub.send.yieldsAsync(null, msg);
|
pgpMailerStub.send.returns(resolves(msg));
|
||||||
authStub.getCredentials.returns(resolves(credentials));
|
authStub.getCredentials.returns(resolves(credentials));
|
||||||
|
|
||||||
dao.sendEncrypted({
|
dao.sendEncrypted({
|
||||||
@ -1703,7 +1703,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not send when pgpmailer fails', function(done) {
|
it('should not send when pgpmailer fails', function(done) {
|
||||||
pgpMailerStub.send.yieldsAsync({});
|
pgpMailerStub.send.returns(rejects({}));
|
||||||
authStub.getCredentials.returns(resolves(credentials));
|
authStub.getCredentials.returns(resolves(credentials));
|
||||||
|
|
||||||
dao.sendEncrypted({
|
dao.sendEncrypted({
|
||||||
@ -1754,13 +1754,13 @@ describe('Email DAO unit tests', function() {
|
|||||||
pgpMailerStub.send.withArgs({
|
pgpMailerStub.send.withArgs({
|
||||||
smtpclient: undefined,
|
smtpclient: undefined,
|
||||||
mail: dummyMail
|
mail: dummyMail
|
||||||
}).yieldsAsync(null, msg);
|
}).returns(resolves(msg));
|
||||||
authStub.getCredentials.returns(resolves(credentials));
|
authStub.getCredentials.returns(resolves(credentials));
|
||||||
|
|
||||||
imapClientStub.uploadMessage.withArgs({
|
imapClientStub.uploadMessage.withArgs({
|
||||||
path: sentFolder.path,
|
path: sentFolder.path,
|
||||||
message: msg
|
message: msg
|
||||||
}).yields();
|
}).returns(resolves());
|
||||||
|
|
||||||
dao.sendPlaintext({
|
dao.sendPlaintext({
|
||||||
email: dummyMail
|
email: dummyMail
|
||||||
@ -1779,7 +1779,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
pgpMailerStub.send.withArgs({
|
pgpMailerStub.send.withArgs({
|
||||||
smtpclient: undefined,
|
smtpclient: undefined,
|
||||||
mail: dummyMail
|
mail: dummyMail
|
||||||
}).yieldsAsync(null, msg);
|
}).returns(resolves(msg));
|
||||||
authStub.getCredentials.returns(resolves(credentials));
|
authStub.getCredentials.returns(resolves(credentials));
|
||||||
|
|
||||||
dao.sendPlaintext({
|
dao.sendPlaintext({
|
||||||
@ -1793,8 +1793,8 @@ describe('Email DAO unit tests', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should send and ignore error on upload', function(done) {
|
it('should send and ignore error on upload', function(done) {
|
||||||
imapClientStub.uploadMessage.yields(new Error());
|
imapClientStub.uploadMessage.returns(rejects(new Error()));
|
||||||
pgpMailerStub.send.yieldsAsync(null, msg);
|
pgpMailerStub.send.returns(resolves(msg));
|
||||||
authStub.getCredentials.returns(resolves(credentials));
|
authStub.getCredentials.returns(resolves(credentials));
|
||||||
|
|
||||||
dao.sendPlaintext({
|
dao.sendPlaintext({
|
||||||
@ -1809,7 +1809,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not send due to error', function(done) {
|
it('should not send due to error', function(done) {
|
||||||
pgpMailerStub.send.yieldsAsync({});
|
pgpMailerStub.send.returns(rejects({}));
|
||||||
authStub.getCredentials.returns(resolves(credentials));
|
authStub.getCredentials.returns(resolves(credentials));
|
||||||
|
|
||||||
dao.sendPlaintext({
|
dao.sendPlaintext({
|
||||||
@ -1840,7 +1840,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
|
|
||||||
describe('#encrypt', function() {
|
describe('#encrypt', function() {
|
||||||
it('should encrypt', function(done) {
|
it('should encrypt', function(done) {
|
||||||
pgpBuilderStub.encrypt.yieldsAsync();
|
pgpBuilderStub.encrypt.returns(resolves());
|
||||||
|
|
||||||
dao.encrypt({}).then(function() {
|
dao.encrypt({}).then(function() {
|
||||||
expect(pgpBuilderStub.encrypt.calledOnce).to.be.true;
|
expect(pgpBuilderStub.encrypt.calledOnce).to.be.true;
|
||||||
@ -1869,9 +1869,9 @@ describe('Email DAO unit tests', function() {
|
|||||||
modseq: '123'
|
modseq: '123'
|
||||||
}];
|
}];
|
||||||
authStub.getCredentials.returns(resolves(credentials));
|
authStub.getCredentials.returns(resolves(credentials));
|
||||||
imapClientStub.login.yieldsAsync();
|
imapClientStub.login.returns(resolves());
|
||||||
imapClientStub.selectMailbox.yields();
|
imapClientStub.selectMailbox.returns(resolves());
|
||||||
imapClientStub.listenForChanges.yields();
|
imapClientStub.listenForChanges.returns(resolves());
|
||||||
initFoldersStub.returns(resolves());
|
initFoldersStub.returns(resolves());
|
||||||
|
|
||||||
dao.onConnect(imapClientStub).then(function() {
|
dao.onConnect(imapClientStub).then(function() {
|
||||||
@ -1894,8 +1894,8 @@ describe('Email DAO unit tests', function() {
|
|||||||
|
|
||||||
describe('#onDisconnect', function() {
|
describe('#onDisconnect', function() {
|
||||||
it('should discard imapClient and pgpMailer', function(done) {
|
it('should discard imapClient and pgpMailer', function(done) {
|
||||||
imapClientStub.stopListeningForChanges.yields();
|
imapClientStub.stopListeningForChanges.returns(resolves());
|
||||||
imapClientStub.logout.yields();
|
imapClientStub.logout.returns(resolves());
|
||||||
|
|
||||||
dao.onDisconnect().then(function() {
|
dao.onDisconnect().then(function() {
|
||||||
expect(imapClientStub.stopListeningForChanges.calledOnce).to.be.true;
|
expect(imapClientStub.stopListeningForChanges.calledOnce).to.be.true;
|
||||||
@ -1923,12 +1923,12 @@ describe('Email DAO unit tests', function() {
|
|||||||
setFlagsStub = sinon.stub(dao, 'setFlags');
|
setFlagsStub = sinon.stub(dao, 'setFlags');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get new message', function() {
|
it('should get new message', function(done) {
|
||||||
fetchMessagesStub.withArgs({
|
fetchMessagesStub.withArgs({
|
||||||
folder: inboxFolder,
|
folder: inboxFolder,
|
||||||
firstUid: 1,
|
firstUid: 1,
|
||||||
lastUid: 3
|
lastUid: 3
|
||||||
}).yields();
|
}).returns(resolves());
|
||||||
|
|
||||||
dao._onSyncUpdate({
|
dao._onSyncUpdate({
|
||||||
type: 'new',
|
type: 'new',
|
||||||
@ -1936,16 +1936,19 @@ describe('Email DAO unit tests', function() {
|
|||||||
list: [1, 3]
|
list: [1, 3]
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(dialogStub.error.calledOnce).to.be.true;
|
setTimeout(function() {
|
||||||
expect(fetchMessagesStub.calledOnce).to.be.true;
|
expect(dialogStub.error.calledOnce).to.be.true;
|
||||||
|
expect(fetchMessagesStub.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should delete message', function() {
|
it('should delete message', function(done) {
|
||||||
deleteMessagesStub.withArgs({
|
deleteMessagesStub.withArgs({
|
||||||
folder: inboxFolder,
|
folder: inboxFolder,
|
||||||
message: msgs[0],
|
message: msgs[0],
|
||||||
localOnly: true
|
localOnly: true
|
||||||
}).yields();
|
}).returns(resolves());
|
||||||
|
|
||||||
dao._onSyncUpdate({
|
dao._onSyncUpdate({
|
||||||
type: 'deleted',
|
type: 'deleted',
|
||||||
@ -1953,16 +1956,19 @@ describe('Email DAO unit tests', function() {
|
|||||||
list: [5]
|
list: [5]
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(dialogStub.error.calledOnce).to.be.true;
|
setTimeout(function() {
|
||||||
expect(deleteMessagesStub.calledOnce).to.be.true;
|
expect(dialogStub.error.calledOnce).to.be.true;
|
||||||
|
expect(deleteMessagesStub.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch flags', function() {
|
it('should fetch flags', function(done) {
|
||||||
setFlagsStub.withArgs({
|
setFlagsStub.withArgs({
|
||||||
folder: inboxFolder,
|
folder: inboxFolder,
|
||||||
message: msgs[0],
|
message: msgs[0],
|
||||||
localOnly: true
|
localOnly: true
|
||||||
}).yields();
|
}).returns(resolves());
|
||||||
|
|
||||||
dao._onSyncUpdate({
|
dao._onSyncUpdate({
|
||||||
type: 'messages',
|
type: 'messages',
|
||||||
@ -1970,8 +1976,11 @@ describe('Email DAO unit tests', function() {
|
|||||||
list: msgs
|
list: msgs
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(dialogStub.error.calledOnce).to.be.true;
|
setTimeout(function() {
|
||||||
expect(setFlagsStub.calledOnce).to.be.true;
|
expect(dialogStub.error.calledOnce).to.be.true;
|
||||||
|
expect(setFlagsStub.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -2102,14 +2111,14 @@ describe('Email DAO unit tests', function() {
|
|||||||
|
|
||||||
it('should initialize from imap if online', function(done) {
|
it('should initialize from imap if online', function(done) {
|
||||||
account.folders = [];
|
account.folders = [];
|
||||||
imapClientStub.listWellKnownFolders.yieldsAsync(null, {
|
imapClientStub.listWellKnownFolders.returns(resolves({
|
||||||
Inbox: [inboxFolder],
|
Inbox: [inboxFolder],
|
||||||
Sent: [sentFolder],
|
Sent: [sentFolder],
|
||||||
Drafts: [draftsFolder],
|
Drafts: [draftsFolder],
|
||||||
Trash: [trashFolder],
|
Trash: [trashFolder],
|
||||||
Flagged: [flaggedFolder],
|
Flagged: [flaggedFolder],
|
||||||
Other: [otherFolder]
|
Other: [otherFolder]
|
||||||
});
|
}));
|
||||||
devicestorageStub.storeList.withArgs(sinon.match(function(arg) {
|
devicestorageStub.storeList.withArgs(sinon.match(function(arg) {
|
||||||
expect(arg[0][0].name).to.deep.equal(inboxFolder.name);
|
expect(arg[0][0].name).to.deep.equal(inboxFolder.name);
|
||||||
expect(arg[0][0].path).to.deep.equal(inboxFolder.path);
|
expect(arg[0][0].path).to.deep.equal(inboxFolder.path);
|
||||||
@ -2151,14 +2160,14 @@ describe('Email DAO unit tests', function() {
|
|||||||
path: 'bar',
|
path: 'bar',
|
||||||
}];
|
}];
|
||||||
|
|
||||||
imapClientStub.listWellKnownFolders.yieldsAsync(null, {
|
imapClientStub.listWellKnownFolders.returns(resolves({
|
||||||
Inbox: [inboxFolder],
|
Inbox: [inboxFolder],
|
||||||
Sent: [sentFolder],
|
Sent: [sentFolder],
|
||||||
Drafts: [draftsFolder],
|
Drafts: [draftsFolder],
|
||||||
Trash: [trashFolder],
|
Trash: [trashFolder],
|
||||||
Flagged: [flaggedFolder],
|
Flagged: [flaggedFolder],
|
||||||
Other: [otherFolder]
|
Other: [otherFolder]
|
||||||
});
|
}));
|
||||||
devicestorageStub.storeList.withArgs(sinon.match(function(arg) {
|
devicestorageStub.storeList.withArgs(sinon.match(function(arg) {
|
||||||
expect(arg[0]).to.deep.equal([{
|
expect(arg[0]).to.deep.equal([{
|
||||||
name: inboxFolder.name,
|
name: inboxFolder.name,
|
||||||
@ -2218,7 +2227,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
uid: 1,
|
uid: 1,
|
||||||
unread: false,
|
unread: false,
|
||||||
answered: false
|
answered: false
|
||||||
}).yieldsAsync();
|
}).returns(resolves());
|
||||||
|
|
||||||
dao._imapMark({
|
dao._imapMark({
|
||||||
folder: inboxFolder,
|
folder: inboxFolder,
|
||||||
@ -2238,7 +2247,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
path: inboxFolder.path,
|
path: inboxFolder.path,
|
||||||
destination: sentFolder.path,
|
destination: sentFolder.path,
|
||||||
uid: 123
|
uid: 123
|
||||||
}).yieldsAsync();
|
}).returns(resolves());
|
||||||
|
|
||||||
dao._imapMoveMessage({
|
dao._imapMoveMessage({
|
||||||
folder: inboxFolder,
|
folder: inboxFolder,
|
||||||
@ -2265,7 +2274,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
path: inboxFolder.path,
|
path: inboxFolder.path,
|
||||||
uid: uid,
|
uid: uid,
|
||||||
destination: trashFolder.path
|
destination: trashFolder.path
|
||||||
}).yieldsAsync();
|
}).returns(resolves());
|
||||||
|
|
||||||
dao._imapDeleteMessage({
|
dao._imapDeleteMessage({
|
||||||
folder: inboxFolder,
|
folder: inboxFolder,
|
||||||
@ -2277,7 +2286,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
imapClientStub.deleteMessage.withArgs({
|
imapClientStub.deleteMessage.withArgs({
|
||||||
path: trashFolder.path,
|
path: trashFolder.path,
|
||||||
uid: uid
|
uid: uid
|
||||||
}).yieldsAsync();
|
}).returns(resolves());
|
||||||
|
|
||||||
dao._imapDeleteMessage({
|
dao._imapDeleteMessage({
|
||||||
folder: trashFolder,
|
folder: trashFolder,
|
||||||
@ -2296,7 +2305,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
path: inboxFolder.path,
|
path: inboxFolder.path,
|
||||||
firstUid: firstUid,
|
firstUid: firstUid,
|
||||||
lastUid: lastUid
|
lastUid: lastUid
|
||||||
}).yieldsAsync(null, []);
|
}).returns(resolves([]));
|
||||||
|
|
||||||
dao._imapListMessages({
|
dao._imapListMessages({
|
||||||
folder: inboxFolder,
|
folder: inboxFolder,
|
||||||
@ -2312,7 +2321,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fail when listMessages fails', function(done) {
|
it('should fail when listMessages fails', function(done) {
|
||||||
imapClientStub.listMessages.yieldsAsync({});
|
imapClientStub.listMessages.returns(rejects({}));
|
||||||
|
|
||||||
dao._imapListMessages({
|
dao._imapListMessages({
|
||||||
folder: inboxFolder,
|
folder: inboxFolder,
|
||||||
@ -2343,7 +2352,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
imapClientStub.uploadMessage.withArgs({
|
imapClientStub.uploadMessage.withArgs({
|
||||||
path: draftsFolder.path,
|
path: draftsFolder.path,
|
||||||
message: msg
|
message: msg
|
||||||
}).yields();
|
}).returns(resolves());
|
||||||
|
|
||||||
dao._imapUploadMessage({
|
dao._imapUploadMessage({
|
||||||
folder: draftsFolder,
|
folder: draftsFolder,
|
||||||
@ -2363,7 +2372,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
path: inboxFolder.path,
|
path: inboxFolder.path,
|
||||||
uid: 123,
|
uid: 123,
|
||||||
bodyParts: []
|
bodyParts: []
|
||||||
}).yieldsAsync(null, {});
|
}).returns(resolves({}));
|
||||||
parseStub.yieldsAsync(null, []);
|
parseStub.yieldsAsync(null, []);
|
||||||
|
|
||||||
dao._getBodyParts({
|
dao._getBodyParts({
|
||||||
@ -2381,7 +2390,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fail when getBody fails', function(done) {
|
it('should fail when getBody fails', function(done) {
|
||||||
imapClientStub.getBodyParts.yieldsAsync({});
|
imapClientStub.getBodyParts.returns(rejects({}));
|
||||||
|
|
||||||
dao._getBodyParts({
|
dao._getBodyParts({
|
||||||
folder: inboxFolder,
|
folder: inboxFolder,
|
||||||
@ -2476,7 +2485,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
imapClientStub.uploadMessage.withArgs({
|
imapClientStub.uploadMessage.withArgs({
|
||||||
path: sentFolder.path,
|
path: sentFolder.path,
|
||||||
message: msg
|
message: msg
|
||||||
}).yields();
|
}).returns(resolves());
|
||||||
|
|
||||||
dao._uploadToSent({
|
dao._uploadToSent({
|
||||||
message: msg
|
message: msg
|
||||||
|
@ -167,11 +167,11 @@ describe('Connection Doctor', function() {
|
|||||||
|
|
||||||
describe('#_checkImap', function() {
|
describe('#_checkImap', function() {
|
||||||
it('should perform IMAP login, list folders, logout', function(done) {
|
it('should perform IMAP login, list folders, logout', function(done) {
|
||||||
imapStub.login.yieldsAsync();
|
imapStub.login.returns(resolves());
|
||||||
imapStub.listWellKnownFolders.yieldsAsync(null, {
|
imapStub.listWellKnownFolders.returns(resolves({
|
||||||
Inbox: [{}]
|
Inbox: [{}]
|
||||||
});
|
}));
|
||||||
imapStub.logout.yieldsAsync();
|
imapStub.logout.returns(resolves());
|
||||||
|
|
||||||
doctor._checkImap().then(function() {
|
doctor._checkImap().then(function() {
|
||||||
expect(imapStub.login.calledOnce).to.be.true;
|
expect(imapStub.login.calledOnce).to.be.true;
|
||||||
@ -183,10 +183,11 @@ describe('Connection Doctor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fail w/ generic error on logout', function(done) {
|
it('should fail w/ generic error on logout', function(done) {
|
||||||
imapStub.login.yieldsAsync();
|
imapStub.login.returns(resolves());
|
||||||
imapStub.listWellKnownFolders.yieldsAsync(null, {
|
imapStub.listWellKnownFolders.returns(resolves({
|
||||||
Inbox: [{}]
|
Inbox: [{}]
|
||||||
});
|
}));
|
||||||
|
imapStub.logout.returns(rejects(new Error()));
|
||||||
|
|
||||||
doctor._checkImap().catch(function(error) {
|
doctor._checkImap().catch(function(error) {
|
||||||
expect(error.code).to.equal(ConnectionDoctor.GENERIC_ERROR);
|
expect(error.code).to.equal(ConnectionDoctor.GENERIC_ERROR);
|
||||||
@ -197,18 +198,13 @@ describe('Connection Doctor', function() {
|
|||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
// this error is thrown while we're waiting for the logout
|
|
||||||
imapStub.onError(new Error());
|
|
||||||
}, 50);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail w/ generic error on inbox missing', function(done) {
|
it('should fail w/ generic error on inbox missing', function(done) {
|
||||||
imapStub.login.yieldsAsync();
|
imapStub.login.returns(resolves());
|
||||||
imapStub.listWellKnownFolders.yieldsAsync(null, {
|
imapStub.listWellKnownFolders.returns(resolves({
|
||||||
Inbox: []
|
Inbox: []
|
||||||
});
|
}));
|
||||||
|
|
||||||
doctor._checkImap().catch(function(error) {
|
doctor._checkImap().catch(function(error) {
|
||||||
expect(error.code).to.equal(ConnectionDoctor.NO_INBOX);
|
expect(error.code).to.equal(ConnectionDoctor.NO_INBOX);
|
||||||
@ -221,8 +217,8 @@ describe('Connection Doctor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fail w/ generic error on listing folders fails', function(done) {
|
it('should fail w/ generic error on listing folders fails', function(done) {
|
||||||
imapStub.login.yieldsAsync();
|
imapStub.login.returns(resolves());
|
||||||
imapStub.listWellKnownFolders.yieldsAsync(new Error());
|
imapStub.listWellKnownFolders.returns(rejects(new Error()));
|
||||||
|
|
||||||
doctor._checkImap().catch(function(error) {
|
doctor._checkImap().catch(function(error) {
|
||||||
expect(error.code).to.equal(ConnectionDoctor.GENERIC_ERROR);
|
expect(error.code).to.equal(ConnectionDoctor.GENERIC_ERROR);
|
||||||
@ -236,6 +232,12 @@ describe('Connection Doctor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fail w/ auth rejected', function(done) {
|
it('should fail w/ auth rejected', function(done) {
|
||||||
|
imapStub.login.returns(new Promise(function() {
|
||||||
|
setTimeout(function() {
|
||||||
|
imapStub.onError(new Error());
|
||||||
|
}, 0);
|
||||||
|
}));
|
||||||
|
|
||||||
doctor._checkImap().catch(function(error) {
|
doctor._checkImap().catch(function(error) {
|
||||||
expect(error.code).to.equal(ConnectionDoctor.AUTH_REJECTED);
|
expect(error.code).to.equal(ConnectionDoctor.AUTH_REJECTED);
|
||||||
expect(error.underlyingError).to.exist;
|
expect(error.underlyingError).to.exist;
|
||||||
@ -245,11 +247,6 @@ describe('Connection Doctor', function() {
|
|||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
// this error is thrown while we're waiting for the login
|
|
||||||
imapStub.onError(new Error());
|
|
||||||
}, 50);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user