From 55add6a6d3d5755fb5d435d74272502ec5749a29 Mon Sep 17 00:00:00 2001 From: Felix Hammerl Date: Mon, 27 Apr 2015 18:15:36 +0200 Subject: [PATCH] [WO-939] Fix TLS cert rejection bug --- src/js/controller/app/navigation.js | 10 ++++------ src/js/email/email.js | 17 +++++++---------- src/js/email/outbox.js | 6 ++---- .../unit/controller/app/navigation-ctrl-test.js | 15 +++++++++------ test/unit/email/outbox-bo-test.js | 7 ++----- 5 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/js/controller/app/navigation.js b/src/js/controller/app/navigation.js index 07d1911..4ae457d 100644 --- a/src/js/controller/app/navigation.js +++ b/src/js/controller/app/navigation.js @@ -11,7 +11,7 @@ var NOTIFICATION_SENT_TIMEOUT = 2000; // Controller // -var NavigationCtrl = function($scope, $location, $q, $timeout, account, email, outbox, notification, appConfig, dialog, dummy, privateKey, axe) { +var NavigationCtrl = function($scope, $location, $q, $timeout, account, email, outbox, notification, status, appConfig, dialog, dummy, privateKey, axe) { if (!$location.search().dev && !account.isLoggedIn()) { $location.path('/'); // init app return; @@ -90,10 +90,10 @@ var NavigationCtrl = function($scope, $location, $q, $timeout, account, email, o // scope functions // - $scope.onOutboxUpdate = function(err, count) { + $scope.onOutboxUpdate = function(err) { if (err) { - dialog.error(err); - return; + axe.error('Sending from outbox failed: ' + err.message); + status.update('Error sending messages...'); } // update the outbox mail count @@ -106,8 +106,6 @@ var NavigationCtrl = function($scope, $location, $q, $timeout, account, email, o return; } - ob.count = count; - return $q(function(resolve) { resolve(); diff --git a/src/js/email/email.js b/src/js/email/email.js index 920d0a5..6d6df4a 100644 --- a/src/js/email/email.js +++ b/src/js/email/email.js @@ -809,7 +809,7 @@ Email.prototype.refreshOutbox = function() { outbox.messages.splice(index, 1); }); - updateUnreadCount(outbox); // update the unread count + updateUnreadCount(outbox, true); // update the unread count, count all messages }); }; @@ -1731,16 +1731,13 @@ Email.prototype.isOnline = function() { /** * Updates a folder's unread count: - * - For the outbox, that's the total number of messages, - * - For every other folder, it's the number of unread messages + * - For the outbox, that's the total number of messages (countAllMessages === true), + * - For every other folder, it's the number of unread messages (countAllMessages === falsy) */ -function updateUnreadCount(folder) { - var allMsgs = folder.messages.length, - unreadMsgs = _.filter(folder.messages, function(msg) { - return msg.unread; - }).length; - - folder.count = folder.path === config.outboxMailboxPath ? allMsgs : unreadMsgs; +function updateUnreadCount(folder, countAllMessages) { + folder.count = countAllMessages ? folder.messages.length : _.filter(folder.messages, function(msg) { + return msg.unread; + }).length; } /** diff --git a/src/js/email/outbox.js b/src/js/email/outbox.js index cfca924..91fb1b1 100644 --- a/src/js/email/outbox.js +++ b/src/js/email/outbox.js @@ -124,8 +124,7 @@ Outbox.prototype.put = function(mail) { * @param {Function} callback(error, pendingMailsCount) Callback that informs you about the count of pending mails. */ Outbox.prototype._processOutbox = function(callback) { - var self = this, - unsentMails = 0; + var self = this; // also, if a _processOutbox call is still in progress, ignore it. if (self._outboxBusy) { @@ -138,7 +137,6 @@ Outbox.prototype._processOutbox = function(callback) { self._devicestorage.listItems(outboxDb).then(function(pendingMails) { // if we're not online, don't even bother sending mails. if (!self._emailDao._account.online || _.isEmpty(pendingMails)) { - unsentMails = pendingMails.length; return; } @@ -154,7 +152,7 @@ Outbox.prototype._processOutbox = function(callback) { }).then(function() { self._outboxBusy = false; - callback(null, unsentMails); + callback(); }).catch(function(err) { self._outboxBusy = false; diff --git a/test/unit/controller/app/navigation-ctrl-test.js b/test/unit/controller/app/navigation-ctrl-test.js index 936b34b..be19b88 100644 --- a/test/unit/controller/app/navigation-ctrl-test.js +++ b/test/unit/controller/app/navigation-ctrl-test.js @@ -75,17 +75,20 @@ describe('Navigation Controller unit test', function() { }); describe('empty outbox', function() { - it('should work', function() { - var callback; + it('should work', function(done) { + var onOutboxUpdate; expect(outboxBoMock.startChecking.callCount).to.equal(1); - outboxBoMock.startChecking.calledWith(sinon.match(function(cb) { - callback = cb; + onOutboxUpdate = cb; })); - callback(null, 5); - expect(outboxFolder.count).to.equal(5); + emailDaoMock.refreshOutbox.returns(resolves()); + + onOutboxUpdate().then(function() { + expect(emailDaoMock.refreshOutbox.calledOnce).to.be.true; + done(); + }); }); }); diff --git a/test/unit/email/outbox-bo-test.js b/test/unit/email/outbox-bo-test.js index 698ddd3..1a68479 100644 --- a/test/unit/email/outbox-bo-test.js +++ b/test/unit/email/outbox-bo-test.js @@ -263,10 +263,8 @@ describe('Outbox unit test', function() { devicestorageStub.removeList.returns(resolves()); - function onOutboxUpdate(err, count) { + function onOutboxUpdate(err) { expect(err).to.not.exist; - expect(count).to.equal(0); - expect(outbox._outboxBusy).to.be.false; expect(emailDaoStub.sendEncrypted.callCount).to.equal(2); expect(emailDaoStub.sendPlaintext.callCount).to.equal(2); @@ -284,9 +282,8 @@ describe('Outbox unit test', function() { emailDaoStub._account.online = false; devicestorageStub.listItems.returns(resolves([{}])); - outbox._processOutbox(function(err, count) { + outbox._processOutbox(function(err) { expect(err).to.not.exist; - expect(count).to.equal(1); expect(devicestorageStub.listItems.callCount).to.equal(1); expect(outbox._outboxBusy).to.be.false; done();