From a32e7ad8c9198b106239a5faa50d847ebf52d9e2 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Tue, 3 Dec 2013 20:24:12 +0100 Subject: [PATCH] fix whitelist filtering in email dao --- src/js/dao/email-dao.js | 9 ++++-- test/new-unit/email-dao-test.js | 53 ++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/js/dao/email-dao.js b/src/js/dao/email-dao.js index 1018ba0..396139f 100644 --- a/src/js/dao/email-dao.js +++ b/src/js/dao/email-dao.js @@ -295,10 +295,13 @@ define(function(require) { return; } - // ignore non-whiteout mails - headers = _.without(headers, _.filter(headers, function(header) { + // ignore non-whitelisted mails + var nonWhitelisted = _.filter(headers, function(header) { return header.subject.indexOf(str.subjectPrefix) === -1; - })); + }); + nonWhitelisted.forEach(function(i) { + headers.splice(headers.indexOf(i), 1); + }); /* * delta3: memory > imap => we deleted messages directly from the remote, remove from memory and storage diff --git a/test/new-unit/email-dao-test.js b/test/new-unit/email-dao-test.js index f4f7108..8290c37 100644 --- a/test/new-unit/email-dao-test.js +++ b/test/new-unit/email-dao-test.js @@ -14,7 +14,8 @@ define(function(require) { var dao, keychainStub, imapClientStub, smtpClientStub, pgpStub, devicestorageStub; var emailAddress, passphrase, asymKeySize, mockkeyId, dummyEncryptedMail, - dummyDecryptedMail, mockKeyPair, account, publicKey, verificationMail, verificationUuid; + dummyDecryptedMail, mockKeyPair, account, publicKey, verificationMail, verificationUuid, + nonWhitelistedMail; beforeEach(function() { emailAddress = 'asdf@asdf.com'; @@ -56,6 +57,17 @@ define(function(require) { subject: '[whiteout] qweasd', body: 'asd' }; + nonWhitelistedMail = { + uid: 1234, + from: [{ + address: 'asd@asd.de' + }], + to: [{ + address: 'qwe@qwe.de' + }], + subject: 'qweasd', + body: 'asd' + }; mockKeyPair = { publicKey: { _id: mockkeyId, @@ -1030,6 +1042,45 @@ define(function(require) { }); }); + it('should not fetch non-whitelisted mails', function(done) { + var invocations, folder, localListStub, imapListStub, imapGetStub, localStoreStub; + + invocations = 0; + folder = 'FOLDAAAA'; + dao._account.folders = [{ + type: 'Folder', + path: folder, + messages: [] + }]; + + localListStub = sinon.stub(dao, '_localListMessages').yields(null, []); + imapListStub = sinon.stub(dao, '_imapListMessages').yields(null, [nonWhitelistedMail]); + imapGetStub = sinon.stub(dao, '_imapGetMessage').yields(null, nonWhitelistedMail); + localStoreStub = sinon.stub(dao, '_localStoreMessages').yields(); + + dao.sync({ + folder: folder + }, function(err) { + expect(err).to.not.exist; + + if (invocations === 0) { + expect(dao._account.busy).to.be.true; + invocations++; + return; + } + + expect(dao._account.busy).to.be.false; + expect(dao._account.folders[0].messages).to.be.empty; + expect(localListStub.calledOnce).to.be.true; + expect(imapListStub.calledOnce).to.be.true; + expect(imapGetStub.called).to.be.false; + expect(localStoreStub.called).to.be.false; + expect(keychainStub.getReceiverPublicKey.called).to.be.false; + expect(pgpStub.decrypt.called).to.be.false; + done(); + }); + }); + it('should error while decrypting fetch messages from the remote', function(done) { var invocations, folder, localListStub, imapListStub, imapGetStub, localStoreStub;