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

fix whitelist filtering in email dao

This commit is contained in:
Tankred Hase 2013-12-03 20:24:12 +01:00
parent 58ed8928e6
commit a32e7ad8c9
2 changed files with 58 additions and 4 deletions

View File

@ -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

View File

@ -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;