2014-03-11 13:57:03 -04:00
|
|
|
define(function(require) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var EmailSync = require('js/dao/email-sync'),
|
|
|
|
KeychainDAO = require('js/dao/keychain-dao'),
|
2014-05-06 11:23:08 -04:00
|
|
|
mailreader = require('mailreader'),
|
2014-03-11 13:57:03 -04:00
|
|
|
ImapClient = require('imap-client'),
|
|
|
|
DeviceStorageDAO = require('js/dao/devicestorage-dao'),
|
|
|
|
expect = chai.expect;
|
|
|
|
|
|
|
|
chai.Assertion.includeStack = true;
|
|
|
|
|
|
|
|
describe('Email Sync unit tests', function() {
|
|
|
|
var emailSync, keychainStub, imapClientStub, devicestorageStub;
|
|
|
|
|
2014-05-12 06:23:43 -04:00
|
|
|
var emailAddress, mockkeyId, dummyEncryptedMail, trashMailbox,
|
2014-05-06 11:23:08 -04:00
|
|
|
dummyDecryptedMail, mockKeyPair, account, verificationMail, verificationUuid, corruptedVerificationUuid,
|
2014-03-11 13:57:03 -04:00
|
|
|
nonWhitelistedMail;
|
|
|
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
emailAddress = 'asdf@asdf.com';
|
|
|
|
mockkeyId = 1234;
|
|
|
|
dummyEncryptedMail = {
|
|
|
|
uid: 1234,
|
|
|
|
from: [{
|
|
|
|
address: 'asd@asd.de'
|
|
|
|
}],
|
|
|
|
to: [{
|
|
|
|
address: 'qwe@qwe.de'
|
|
|
|
}],
|
|
|
|
subject: 'qweasd',
|
2014-05-06 11:23:08 -04:00
|
|
|
bodyParts: [{
|
|
|
|
type: 'encrypted'
|
|
|
|
}],
|
2014-03-11 13:57:03 -04:00
|
|
|
unread: false,
|
|
|
|
answered: false
|
|
|
|
};
|
|
|
|
verificationUuid = '9A858952-17EE-4273-9E74-D309EAFDFAFB';
|
|
|
|
verificationMail = {
|
|
|
|
from: [{
|
|
|
|
name: 'Whiteout Test',
|
|
|
|
address: 'whiteout.test@t-online.de'
|
|
|
|
}], // sender address
|
|
|
|
to: [{
|
|
|
|
address: 'safewithme.testuser@gmail.com'
|
|
|
|
}], // list of receivers
|
|
|
|
subject: "[whiteout] New public key uploaded", // Subject line
|
2014-05-06 11:23:08 -04:00
|
|
|
bodyParts: [{
|
|
|
|
type: 'text'
|
|
|
|
}],
|
2014-03-11 13:57:03 -04:00
|
|
|
unread: false,
|
|
|
|
answered: false
|
|
|
|
};
|
|
|
|
corruptedVerificationUuid = 'OMFG_FUCKING_BASTARD_UUID_FROM_HELL!';
|
|
|
|
dummyDecryptedMail = {
|
|
|
|
uid: 1234,
|
|
|
|
from: [{
|
|
|
|
address: 'asd@asd.de'
|
|
|
|
}],
|
|
|
|
to: [{
|
|
|
|
address: 'qwe@qwe.de'
|
|
|
|
}],
|
|
|
|
subject: 'qweasd',
|
2014-05-06 11:23:08 -04:00
|
|
|
bodyParts: [{
|
|
|
|
type: 'text'
|
|
|
|
}],
|
2014-03-11 13:57:03 -04:00
|
|
|
unread: false,
|
|
|
|
answered: false,
|
|
|
|
};
|
|
|
|
nonWhitelistedMail = {
|
|
|
|
uid: 1234,
|
|
|
|
from: [{
|
|
|
|
address: 'asd@asd.de'
|
|
|
|
}],
|
|
|
|
to: [{
|
|
|
|
address: 'qwe@qwe.de'
|
|
|
|
}],
|
|
|
|
subject: 'qweasd',
|
2014-05-06 11:23:08 -04:00
|
|
|
bodyParts: [{
|
|
|
|
type: 'text'
|
|
|
|
}],
|
2014-03-11 13:57:03 -04:00
|
|
|
};
|
|
|
|
mockKeyPair = {
|
|
|
|
publicKey: {
|
|
|
|
_id: mockkeyId,
|
|
|
|
userId: emailAddress,
|
|
|
|
publicKey: 'publicpublicpublicpublic'
|
|
|
|
},
|
|
|
|
privateKey: {
|
|
|
|
_id: mockkeyId,
|
|
|
|
userId: emailAddress,
|
|
|
|
encryptedKey: 'privateprivateprivateprivate'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
account = {
|
|
|
|
emailAddress: emailAddress,
|
|
|
|
busy: false
|
|
|
|
};
|
|
|
|
|
|
|
|
keychainStub = sinon.createStubInstance(KeychainDAO);
|
|
|
|
imapClientStub = sinon.createStubInstance(ImapClient);
|
|
|
|
devicestorageStub = sinon.createStubInstance(DeviceStorageDAO);
|
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
emailSync = new EmailSync(keychainStub, devicestorageStub, mailreader);
|
2014-03-11 13:57:03 -04:00
|
|
|
|
|
|
|
expect(emailSync._keychain).to.equal(keychainStub);
|
|
|
|
expect(emailSync._devicestorage).to.equal(devicestorageStub);
|
2014-05-06 11:23:08 -04:00
|
|
|
expect(emailSync._mailreader).to.equal(mailreader);
|
2014-05-12 06:23:43 -04:00
|
|
|
trashMailbox = {
|
|
|
|
type: 'Trash',
|
|
|
|
path: 'trash'
|
|
|
|
};
|
2014-03-11 13:57:03 -04:00
|
|
|
|
|
|
|
// init
|
|
|
|
emailSync.init({
|
|
|
|
account: account
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(emailSync._account).to.equal(account);
|
|
|
|
|
|
|
|
// connect
|
|
|
|
expect(emailSync._imapClient).to.not.exist;
|
|
|
|
expect(emailSync._smtpClient).to.not.exist;
|
|
|
|
expect(emailSync._account.online).to.be.undefined;
|
2014-05-12 06:23:43 -04:00
|
|
|
emailSync._account.folders = [trashMailbox];
|
2014-03-11 13:57:03 -04:00
|
|
|
imapClientStub.login.yields();
|
|
|
|
|
|
|
|
// this is set in the emailDao.onConnect
|
|
|
|
emailSync._account.online = true;
|
|
|
|
|
|
|
|
emailSync.onConnect({
|
|
|
|
imapClient: imapClientStub
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(emailSync._account.online).to.be.true;
|
|
|
|
expect(emailSync._imapClient).to.equal(emailSync._imapClient);
|
|
|
|
expect(emailSync._smtpClient).to.equal(emailSync._smtpClient);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function(done) {
|
|
|
|
// this is set in the emailDao.onDisconnect
|
|
|
|
emailSync._account.online = false;
|
|
|
|
|
|
|
|
emailSync.onDisconnect(null, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(emailSync._account.online).to.be.false;
|
|
|
|
expect(emailSync._imapClient).to.not.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('_imapSearch', function() {
|
2014-05-06 11:23:08 -04:00
|
|
|
var path = 'FOLDAAAA';
|
|
|
|
|
2014-03-11 13:57:03 -04:00
|
|
|
it('should fail when disconnected', function(done) {
|
|
|
|
// this is set in the emailDao.onDisconnect
|
|
|
|
emailSync._account.online = false;
|
|
|
|
|
|
|
|
emailSync._imapSearch({}, function(err) {
|
|
|
|
expect(err.code).to.equal(42);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
it('should list all uids', function(done) {
|
2014-03-11 13:57:03 -04:00
|
|
|
imapClientStub.search.withArgs({
|
2014-05-06 11:23:08 -04:00
|
|
|
folder: path,
|
2014-03-11 13:57:03 -04:00
|
|
|
path: path
|
|
|
|
}).yields();
|
|
|
|
|
|
|
|
emailSync._imapSearch({
|
|
|
|
folder: path
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
it('should list answered uids', function(done) {
|
2014-03-11 13:57:03 -04:00
|
|
|
imapClientStub.search.withArgs({
|
2014-05-06 11:23:08 -04:00
|
|
|
folder: path,
|
2014-03-11 13:57:03 -04:00
|
|
|
path: path,
|
|
|
|
answered: true
|
|
|
|
}).yields();
|
|
|
|
|
|
|
|
emailSync._imapSearch({
|
|
|
|
folder: path,
|
|
|
|
answered: true
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
it('should list unread uids', function(done) {
|
2014-03-11 13:57:03 -04:00
|
|
|
imapClientStub.search.withArgs({
|
2014-05-06 11:23:08 -04:00
|
|
|
folder: path,
|
2014-03-11 13:57:03 -04:00
|
|
|
path: path,
|
|
|
|
unread: true
|
|
|
|
}).yields();
|
|
|
|
|
|
|
|
emailSync._imapSearch({
|
|
|
|
folder: path,
|
|
|
|
unread: true
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('_imapDeleteMessage', function() {
|
2014-05-06 11:23:08 -04:00
|
|
|
var path = 'FOLDAAAA',
|
|
|
|
uid = 1337;
|
|
|
|
|
2014-03-11 13:57:03 -04:00
|
|
|
it('should fail when disconnected', function(done) {
|
|
|
|
// this is set in the emailDao.onDisconnect
|
|
|
|
emailSync._account.online = false;
|
|
|
|
|
|
|
|
emailSync._imapDeleteMessage({}, function(err) {
|
|
|
|
expect(err.code).to.equal(42);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-05-12 06:23:43 -04:00
|
|
|
it('should move to trash', function(done) {
|
|
|
|
imapClientStub.moveMessage.withArgs({
|
2014-03-11 13:57:03 -04:00
|
|
|
path: path,
|
2014-05-12 06:23:43 -04:00
|
|
|
uid: uid,
|
|
|
|
destination: trashMailbox.path
|
|
|
|
}).yields();
|
|
|
|
|
|
|
|
emailSync._imapDeleteMessage({
|
2014-05-06 11:23:08 -04:00
|
|
|
folder: path,
|
2014-03-11 13:57:03 -04:00
|
|
|
uid: uid
|
2014-05-12 06:23:43 -04:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should purge message', function(done) {
|
|
|
|
imapClientStub.deleteMessage.withArgs({
|
|
|
|
path: trashMailbox.path,
|
|
|
|
uid: uid
|
2014-03-11 13:57:03 -04:00
|
|
|
}).yields();
|
|
|
|
|
|
|
|
emailSync._imapDeleteMessage({
|
2014-05-12 06:23:43 -04:00
|
|
|
folder: trashMailbox.path,
|
2014-03-11 13:57:03 -04:00
|
|
|
uid: uid
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('_imapListMessages', function() {
|
2014-05-06 11:23:08 -04:00
|
|
|
var path = 'FOLDAAAA',
|
|
|
|
firstUid = 1337,
|
|
|
|
lastUid = 1339;
|
2014-03-11 13:57:03 -04:00
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
|
|
|
|
it('should work', function(done) {
|
|
|
|
imapClientStub.listMessages.withArgs({
|
2014-03-11 13:57:03 -04:00
|
|
|
path: path,
|
2014-05-06 11:23:08 -04:00
|
|
|
folder: path,
|
2014-03-11 13:57:03 -04:00
|
|
|
firstUid: firstUid,
|
|
|
|
lastUid: lastUid
|
|
|
|
}).yields(null, []);
|
|
|
|
|
|
|
|
emailSync._imapListMessages({
|
|
|
|
folder: path,
|
|
|
|
firstUid: firstUid,
|
|
|
|
lastUid: lastUid
|
|
|
|
}, function(err, msgs) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(msgs).to.exist;
|
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
expect(imapClientStub.listMessages.calledOnce).to.be.true;
|
2014-03-11 13:57:03 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
it('should not work when listMessages fails', function(done) {
|
|
|
|
imapClientStub.listMessages.yields({});
|
2014-03-11 13:57:03 -04:00
|
|
|
|
|
|
|
emailSync._imapListMessages({
|
|
|
|
folder: path,
|
|
|
|
firstUid: firstUid,
|
|
|
|
lastUid: lastUid
|
|
|
|
}, function(err, msgs) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(msgs).to.not.exist;
|
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
expect(imapClientStub.listMessages.calledOnce).to.be.true;
|
2014-03-11 13:57:03 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail when disconnected', function(done) {
|
|
|
|
// this is set in the emailDao.onDisconnect
|
|
|
|
emailSync._account.online = false;
|
|
|
|
|
|
|
|
emailSync._imapListMessages({}, function(err) {
|
|
|
|
expect(err.code).to.equal(42);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
describe('_getBodyParts', function() {
|
|
|
|
var path = 'FOLDAAAA',
|
|
|
|
parseStub;
|
|
|
|
|
2014-03-11 13:57:03 -04:00
|
|
|
it('should work', function(done) {
|
2014-05-06 11:23:08 -04:00
|
|
|
var o = {
|
|
|
|
folder: path,
|
|
|
|
uid: 123,
|
|
|
|
bodyParts: []
|
|
|
|
};
|
2014-03-11 13:57:03 -04:00
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
imapClientStub.getBodyParts.withArgs(o).yields(null, {});
|
|
|
|
parseStub = sinon.stub(mailreader, 'parse').withArgs(o).yields(null, []);
|
2014-03-11 13:57:03 -04:00
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
emailSync._getBodyParts(o, function(err, parts) {
|
2014-03-11 13:57:03 -04:00
|
|
|
expect(err).to.not.exist;
|
2014-05-06 11:23:08 -04:00
|
|
|
expect(parts).to.exist;
|
2014-03-11 13:57:03 -04:00
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
expect(imapClientStub.getBodyParts.calledOnce).to.be.true;
|
|
|
|
expect(parseStub.calledOnce).to.be.true;
|
2014-03-11 13:57:03 -04:00
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
mailreader.parse.restore();
|
2014-03-11 13:57:03 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not work when getBody fails', function(done) {
|
2014-05-06 11:23:08 -04:00
|
|
|
var o = {
|
|
|
|
folder: path,
|
|
|
|
uid: 123,
|
|
|
|
bodyParts: []
|
|
|
|
};
|
2014-03-11 13:57:03 -04:00
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
imapClientStub.getBodyParts.yields({});
|
|
|
|
parseStub = sinon.spy(mailreader, 'parse');
|
2014-03-11 13:57:03 -04:00
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
emailSync._getBodyParts(o, function(err, msg) {
|
2014-03-11 13:57:03 -04:00
|
|
|
expect(err).to.exist;
|
|
|
|
expect(msg).to.not.exist;
|
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
expect(imapClientStub.getBodyParts.calledOnce).to.be.true;
|
|
|
|
expect(parseStub.called).to.be.false;
|
2014-03-11 13:57:03 -04:00
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
mailreader.parse.restore();
|
2014-03-11 13:57:03 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail when disconnected', function(done) {
|
|
|
|
// this is set in the emailDao.onDisconnect
|
|
|
|
emailSync._account.online = false;
|
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
emailSync._getBodyParts({}, function(err) {
|
2014-03-11 13:57:03 -04:00
|
|
|
expect(err.code).to.equal(42);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('_localListMessages', function() {
|
|
|
|
it('should work without uid', function(done) {
|
|
|
|
var folder = 'FOLDAAAA';
|
|
|
|
devicestorageStub.listItems.withArgs('email_' + folder, 0, null).yields();
|
|
|
|
|
|
|
|
emailSync._localListMessages({
|
|
|
|
folder: folder
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work with uid', function(done) {
|
|
|
|
var folder = 'FOLDAAAA',
|
|
|
|
uid = 123;
|
|
|
|
devicestorageStub.listItems.withArgs('email_' + folder + '_' + uid, 0, null).yields();
|
|
|
|
|
|
|
|
emailSync._localListMessages({
|
|
|
|
folder: folder,
|
|
|
|
uid: uid
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('_localStoreMessages', function() {
|
|
|
|
it('should work', function(done) {
|
|
|
|
var folder = 'FOLDAAAA',
|
|
|
|
emails = [{}];
|
|
|
|
devicestorageStub.storeList.withArgs(emails, 'email_' + folder).yields();
|
|
|
|
|
|
|
|
emailSync._localStoreMessages({
|
|
|
|
folder: folder,
|
|
|
|
emails: emails
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('_localDeleteMessage', function() {
|
|
|
|
it('should work', function(done) {
|
|
|
|
var folder = 'FOLDAAAA',
|
|
|
|
uid = 1337;
|
|
|
|
devicestorageStub.removeList.withArgs('email_' + folder + '_' + uid).yields();
|
|
|
|
|
|
|
|
emailSync._localDeleteMessage({
|
|
|
|
folder: folder,
|
|
|
|
uid: uid
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail when uid is missing', function(done) {
|
|
|
|
var folder = 'FOLDAAAA';
|
|
|
|
|
|
|
|
emailSync._localDeleteMessage({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('sync', function() {
|
|
|
|
it('should initially fill from local', function(done) {
|
|
|
|
var folder, localListStub, invocations, imapSearchStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0].messages.length).to.equal(1);
|
|
|
|
expect(emailSync._account.folders[0].messages[0].uid).to.equal(dummyEncryptedMail.uid);
|
|
|
|
expect(emailSync._account.folders[0].messages[0].body).to.not.exist;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not work when busy', function(done) {
|
|
|
|
emailSync._account.busy = true;
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: 'OOGA'
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not work without providing a folder', function(done) {
|
|
|
|
emailSync.sync({}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not work when initial setup errors', function(done) {
|
|
|
|
var folder, localListStub;
|
|
|
|
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields({});
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be up to date', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail.uid - 10, dummyEncryptedMail.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while searching on imap', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, [dummyEncryptedMail]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields({});
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while listing local messages', function(done) {
|
|
|
|
var folder, localListStub;
|
|
|
|
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields({});
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove messages from the remote', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, localDeleteStub, imapDeleteStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, [dummyEncryptedMail]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
|
|
|
|
imapDeleteStub = sinon.stub(emailSync, '_imapDeleteMessage').yields();
|
|
|
|
localDeleteStub = sinon.stub(emailSync, '_localDeleteMessage').yields();
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0].messages).to.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
expect(localDeleteStub.calledOnce).to.be.true;
|
|
|
|
expect(imapDeleteStub.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while removing messages from local', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, localDeleteStub, imapDeleteStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, [dummyEncryptedMail]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapDeleteStub = sinon.stub(emailSync, '_imapDeleteMessage').yields();
|
|
|
|
localDeleteStub = sinon.stub(emailSync, '_localDeleteMessage').yields({});
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0].messages).to.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(localDeleteStub.calledOnce).to.be.true;
|
|
|
|
expect(imapDeleteStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.called).to.be.false;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while removing messages from the remote', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, localDeleteStub, imapDeleteStub;
|
|
|
|
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, [dummyEncryptedMail]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapDeleteStub = sinon.stub(emailSync, '_imapDeleteMessage').yields({});
|
|
|
|
localDeleteStub = sinon.stub(emailSync, '_localDeleteMessage');
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0].messages).to.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(imapDeleteStub.calledOnce).to.be.true;
|
|
|
|
expect(localDeleteStub.called).to.be.false;
|
|
|
|
expect(imapSearchStub.called).to.be.false;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should delete messages locally if not present on remote', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, localDeleteStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
localDeleteStub = sinon.stub(emailSync, '_localDeleteMessage').withArgs({
|
|
|
|
folder: folder,
|
|
|
|
uid: dummyEncryptedMail.uid
|
|
|
|
}).yields();
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0].messages).to.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
expect(localDeleteStub.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while deleting locally if not present on remote', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, localDeleteStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, [dummyEncryptedMail]);
|
|
|
|
localDeleteStub = sinon.stub(emailSync, '_localDeleteMessage').yields({});
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch').withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, []);
|
|
|
|
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0].messages).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.calledOnce).to.be.true;
|
|
|
|
expect(localDeleteStub.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fetch messages downstream from the remote', function(done) {
|
2014-04-28 12:09:51 -04:00
|
|
|
var invocations, folder, localListStub, imapSearchStub, localStoreStub, imapListMessagesStub, incomingMessagesCalled;
|
2014-03-11 13:57:03 -04:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
|
|
|
delete dummyEncryptedMail.body;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, []);
|
|
|
|
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
|
|
|
|
imapListMessagesStub = sinon.stub(emailSync, '_imapListMessages');
|
|
|
|
imapListMessagesStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
firstUid: dummyEncryptedMail.uid,
|
|
|
|
lastUid: dummyEncryptedMail.uid
|
|
|
|
}).yields(null, [dummyEncryptedMail]);
|
|
|
|
|
|
|
|
localStoreStub = sinon.stub(emailSync, '_localStoreMessages');
|
|
|
|
localStoreStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
emails: [dummyEncryptedMail]
|
|
|
|
}).yields();
|
|
|
|
|
2014-04-28 12:09:51 -04:00
|
|
|
incomingMessagesCalled = false;
|
|
|
|
emailSync.onIncomingMessage = function(msgs) {
|
|
|
|
incomingMessagesCalled = true;
|
|
|
|
expect(msgs).to.not.be.empty;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-03-11 13:57:03 -04:00
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0].messages.length).to.equal(1);
|
|
|
|
expect(emailSync._account.folders[0].messages[0].uid).to.equal(dummyEncryptedMail.uid);
|
|
|
|
expect(emailSync._account.folders[0].messages[0].body).to.not.exist;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
2014-04-28 12:09:51 -04:00
|
|
|
expect(incomingMessagesCalled).to.be.true;
|
|
|
|
|
2014-03-11 13:57:03 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while storing messages from the remote locally', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, localStoreStub, imapListMessagesStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
|
|
|
delete dummyEncryptedMail.body;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, []);
|
|
|
|
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.yields(null, [dummyEncryptedMail.uid]);
|
|
|
|
|
|
|
|
imapListMessagesStub = sinon.stub(emailSync, '_imapListMessages');
|
|
|
|
imapListMessagesStub.yields(null, [dummyEncryptedMail]);
|
|
|
|
|
|
|
|
localStoreStub = sinon.stub(emailSync, '_localStoreMessages');
|
|
|
|
localStoreStub.yields({});
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0].messages.length).to.equal(0);
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should verify an authentication mail', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, imapGetStub, imapListMessagesStub, imapDeleteStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, []);
|
|
|
|
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [verificationMail.uid]);
|
|
|
|
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
|
|
|
|
imapListMessagesStub = sinon.stub(emailSync, '_imapListMessages').yields(null, [verificationMail]);
|
2014-05-06 11:23:08 -04:00
|
|
|
imapGetStub = sinon.stub(emailSync, '_getBodyParts').yields(null, [{
|
|
|
|
type: 'text',
|
|
|
|
content: 'yadda yadda bla blabla foo bar https://keys.whiteout.io/verify/' + verificationUuid,
|
|
|
|
}]);
|
2014-03-11 13:57:03 -04:00
|
|
|
keychainStub.verifyPublicKey.withArgs(verificationUuid).yields();
|
|
|
|
localStoreStub = sinon.stub(emailSync, '_localStoreMessages');
|
|
|
|
imapDeleteStub = sinon.stub(emailSync, '_imapDeleteMessage').withArgs({
|
|
|
|
folder: folder,
|
|
|
|
uid: verificationMail.uid
|
|
|
|
}).yields();
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0].messages).to.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
expect(imapGetStub.calledOnce).to.be.true;
|
|
|
|
expect(keychainStub.verifyPublicKey.calledOnce).to.be.true;
|
|
|
|
expect(imapDeleteStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.false;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not care abouta failed deletion of an authentication mail', function(done) {
|
|
|
|
var invocations, folder, localListStub, localStoreStub, imapSearchStub, imapGetStub, imapListMessagesStub, imapDeleteStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, []);
|
|
|
|
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [verificationMail.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapListMessagesStub = sinon.stub(emailSync, '_imapListMessages').yields(null, [verificationMail]);
|
2014-05-06 11:23:08 -04:00
|
|
|
imapGetStub = sinon.stub(emailSync, '_getBodyParts').yields(null, [{
|
|
|
|
type: 'text',
|
|
|
|
content: 'yadda yadda bla blabla foo bar https://keys.whiteout.io/verify/' + verificationUuid,
|
|
|
|
}]);
|
2014-03-11 13:57:03 -04:00
|
|
|
keychainStub.verifyPublicKey.withArgs(verificationUuid).yields();
|
|
|
|
imapDeleteStub = sinon.stub(emailSync, '_imapDeleteMessage').yields({});
|
|
|
|
|
|
|
|
localStoreStub = sinon.stub(emailSync, '_localStoreMessages');
|
|
|
|
localStoreStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
emails: [verificationMail]
|
|
|
|
}).yields();
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0].messages).to.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.called).to.be.false;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
expect(imapGetStub.calledOnce).to.be.true;
|
|
|
|
expect(keychainStub.verifyPublicKey.calledOnce).to.be.true;
|
|
|
|
expect(imapDeleteStub.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail during verifying authentication', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, localStoreStub, imapGetStub, imapListMessagesStub, imapDeleteStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, []);
|
|
|
|
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [verificationMail.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapListMessagesStub = sinon.stub(emailSync, '_imapListMessages').yields(null, [verificationMail]);
|
2014-05-06 11:23:08 -04:00
|
|
|
imapGetStub = sinon.stub(emailSync, '_getBodyParts').yields(null, [{
|
|
|
|
type: 'text',
|
|
|
|
content: 'yadda yadda bla blabla foo bar https://keys.whiteout.io/verify/' + verificationUuid,
|
|
|
|
}]);
|
2014-03-11 13:57:03 -04:00
|
|
|
keychainStub.verifyPublicKey.withArgs(verificationUuid).yields({
|
|
|
|
errMsg: 'fubar'
|
|
|
|
});
|
|
|
|
imapDeleteStub = sinon.stub(emailSync, '_imapDeleteMessage').yields({});
|
|
|
|
|
|
|
|
localStoreStub = sinon.stub(emailSync, '_localStoreMessages');
|
|
|
|
localStoreStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
emails: [verificationMail]
|
|
|
|
}).yields();
|
|
|
|
|
2014-04-28 12:09:51 -04:00
|
|
|
emailSync.onIncomingMessage = function() {};
|
|
|
|
|
2014-03-11 13:57:03 -04:00
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (invocations === 1) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0].messages).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
expect(imapGetStub.calledOnce).to.be.true;
|
|
|
|
expect(keychainStub.verifyPublicKey.calledOnce).to.be.true;
|
|
|
|
expect(imapDeleteStub.called).to.be.false;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not bother about corrupted authentication mails', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, imapGetStub, imapListMessagesStub, imapDeleteStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, []);
|
|
|
|
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
2014-05-06 11:23:08 -04:00
|
|
|
}).yields(null, [verificationMail.uid]);
|
2014-03-11 13:57:03 -04:00
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
|
|
|
|
localStoreStub = sinon.stub(emailSync, '_localStoreMessages').withArgs({
|
|
|
|
folder: folder,
|
2014-05-06 11:23:08 -04:00
|
|
|
emails: [verificationMail]
|
2014-03-11 13:57:03 -04:00
|
|
|
}).yields();
|
|
|
|
|
|
|
|
|
2014-05-06 11:23:08 -04:00
|
|
|
imapListMessagesStub = sinon.stub(emailSync, '_imapListMessages').yields(null, [verificationMail]);
|
|
|
|
imapGetStub = sinon.stub(emailSync, '_getBodyParts').yields(null, [{
|
|
|
|
type: 'text',
|
|
|
|
content: 'yadda yadda bla blabla foo bar https://keys.whiteout.io/verify/' + corruptedVerificationUuid,
|
|
|
|
}]);
|
2014-03-11 13:57:03 -04:00
|
|
|
keychainStub.verifyPublicKey.withArgs(corruptedVerificationUuid).yields({
|
|
|
|
errMsg: 'fubar'
|
|
|
|
});
|
|
|
|
imapDeleteStub = sinon.stub(emailSync, '_imapDeleteMessage').yields({});
|
|
|
|
|
2014-04-28 12:09:51 -04:00
|
|
|
emailSync.onIncomingMessage = function() {};
|
|
|
|
|
2014-03-11 13:57:03 -04:00
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0].messages).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
expect(imapGetStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
|
|
|
expect(keychainStub.verifyPublicKey.called).to.be.false;
|
|
|
|
expect(imapDeleteStub.called).to.be.false;
|
|
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should sync tags from memory to imap and storage', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations,
|
|
|
|
markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
var inImap = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inImap.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, [inStorage]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [inImap.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, [inImap.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
markStub = sinon.stub(emailSync, '_imapMark').withArgs({
|
|
|
|
folder: folder,
|
|
|
|
uid: dummyDecryptedMail.uid,
|
|
|
|
unread: dummyDecryptedMail.unread,
|
|
|
|
answered: dummyDecryptedMail.answered
|
|
|
|
}).yields();
|
|
|
|
localStoreStub = sinon.stub(emailSync, '_localStoreMessages').withArgs({
|
|
|
|
folder: folder,
|
|
|
|
emails: [inStorage]
|
|
|
|
}).yields();
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
expect(markStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
expect(inStorage.unread).to.equal(dummyDecryptedMail.unread);
|
|
|
|
expect(inStorage.answered).to.equal(dummyDecryptedMail.answered);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while syncing unread tags from memory to storage', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations, markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
var inImap = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inImap.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, [inStorage]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
markStub = sinon.stub(emailSync, '_imapMark').yields();
|
|
|
|
localStoreStub = sinon.stub(emailSync, '_localStoreMessages').yields({});
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(markStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.called).to.be.false;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while syncing answered tags from memory to storage', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations, markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
var inImap = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inImap.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, [inStorage]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
markStub = sinon.stub(emailSync, '_imapMark').yields();
|
|
|
|
localStoreStub = sinon.stub(emailSync, '_localStoreMessages').yields({});
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(markStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.called).to.be.false;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while syncing tags from memory to imap', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations,
|
|
|
|
markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
var inImap = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inImap.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, [inStorage]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
markStub = sinon.stub(emailSync, '_imapMark').yields({});
|
|
|
|
localStoreStub = sinon.stub(emailSync, '_localStoreMessages');
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(markStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.called).to.be.false;
|
|
|
|
expect(imapSearchStub.called).to.be.false;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should sync tags from imap to memory and storage', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations,
|
|
|
|
markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inStorage.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, [inStorage]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
markStub = sinon.stub(emailSync, '_imapMark');
|
|
|
|
localStoreStub = sinon.stub(emailSync, '_localStoreMessages').yields();
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledTwice).to.be.true;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
expect(markStub.called).to.be.false;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
expect(dummyDecryptedMail.unread).to.equal(false);
|
|
|
|
expect(inStorage.unread).to.equal(false);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while searching for unread tags on imap', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations, markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inStorage.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, [inStorage]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields({});
|
|
|
|
markStub = sinon.stub(emailSync, '_imapMark');
|
|
|
|
localStoreStub = sinon.stub(emailSync, '_localStoreMessages');
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(markStub.called).to.be.false;
|
|
|
|
expect(imapSearchStub.calledTwice).to.be.true;
|
|
|
|
expect(localStoreStub.called).to.be.false;
|
|
|
|
|
|
|
|
expect(inStorage.unread).to.equal(true);
|
|
|
|
expect(dummyDecryptedMail.unread).to.equal(true); // the live object has not been touched!
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while searching for answered tags on imap', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations, markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inStorage.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, [inStorage]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields({});
|
|
|
|
markStub = sinon.stub(emailSync, '_imapMark');
|
|
|
|
localStoreStub = sinon.stub(emailSync, '_localStoreMessages');
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(markStub.called).to.be.false;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
expect(localStoreStub.called).to.be.false;
|
|
|
|
|
|
|
|
expect(inStorage.unread).to.equal(true);
|
|
|
|
expect(dummyDecryptedMail.unread).to.equal(true); // the live object has not been touched!
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while syncing tags from imap to storage', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations,
|
|
|
|
markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inStorage.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(emailSync, '_localListMessages').yields(null, [inStorage]);
|
|
|
|
imapSearchStub = sinon.stub(emailSync, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
markStub = sinon.stub(emailSync, '_imapMark');
|
|
|
|
localStoreStub = sinon.stub(emailSync, '_localStoreMessages').yields({});
|
|
|
|
|
|
|
|
emailSync.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(emailSync._account.busy).to.be.false;
|
|
|
|
expect(emailSync._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledTwice).to.be.true;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
expect(markStub.called).to.be.false;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('syncOutbox', function() {
|
|
|
|
it('should sync the outbox', function(done) {
|
|
|
|
var folder = 'FOLDAAAA';
|
|
|
|
emailSync._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder
|
|
|
|
}];
|
|
|
|
|
|
|
|
var localListStub = sinon.stub(emailSync, '_localListMessages').withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail]);
|
|
|
|
|
|
|
|
emailSync.syncOutbox({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(emailSync._account.folders[0].messages.length).to.equal(1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('mark', function() {
|
|
|
|
it('should work', function(done) {
|
2014-05-06 11:23:08 -04:00
|
|
|
var o = {
|
2014-03-11 13:57:03 -04:00
|
|
|
folder: 'asdf',
|
|
|
|
uid: 1,
|
|
|
|
unread: false,
|
|
|
|
answered: false
|
2014-05-06 11:23:08 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
imapClientStub.updateFlags.withArgs(o).yields();
|
|
|
|
|
|
|
|
emailSync._imapMark(o, function(err) {
|
2014-03-11 13:57:03 -04:00
|
|
|
expect(imapClientStub.updateFlags.calledOnce).to.be.true;
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|