diff --git a/src/js/controller/read.js b/src/js/controller/read.js index 2bf42bb..5f6f88e 100644 --- a/src/js/controller/read.js +++ b/src/js/controller/read.js @@ -70,10 +70,13 @@ define(function(require) { $scope.node = undefined; }); $scope.$watch('state.mailList.selected.body', function(body) { - var selected = $scope.state.mailList.selected; - $scope.node = undefined; // reset model - if (!body || (body && selected.encrypted && !selected.decrypted)) { + if (!body) { + return; + } + + var selected = $scope.state.mailList.selected; + if (selected.encrypted && !selected.decrypted) { return; } diff --git a/src/js/dao/email-dao.js b/src/js/dao/email-dao.js index 4cf73ed..2ee8152 100644 --- a/src/js/dao/email-dao.js +++ b/src/js/dao/email-dao.js @@ -398,15 +398,13 @@ define(function(require) { // get the sender's public key for signature checking self._keychain.getReceiverPublicKey(message.from[0].address, function(err, senderPublicKey) { if (err) { - message.decryptingBody = false; - callback(err); + done(err); return; } if (!senderPublicKey) { // this should only happen if a mail from another channel is in the inbox - message.body = 'Public key for sender not found!'; - done(); + showError('Public key for sender not found!'); return; } @@ -414,8 +412,7 @@ define(function(require) { var encryptedNode = self._emailSync.filterBodyParts(message.bodyParts, 'encrypted')[0]; self._crypto.decrypt(encryptedNode.content, senderPublicKey.publicKey, function(err, decrypted) { if (err || !decrypted) { - message.body = err.errMsg || err.message; - done(); + showError(err.errMsg || err.message); return; } @@ -425,9 +422,9 @@ define(function(require) { // parse the decrpyted raw content in the mailparser self._mailreader.parse({ bodyParts: [encryptedNode] - }, function(error, parsedBodyParts) { - if (error) { - done(error); + }, function(err, parsedBodyParts) { + if (err) { + showError(err.errMsg || err.message); return; } @@ -450,6 +447,12 @@ define(function(require) { }); }); + function showError(msg) { + message.body = msg; + message.decrypted = true; // display error msh in body + done(); + } + function done(err) { message.decryptingBody = false; callback(err, err ? undefined : message); diff --git a/test/new-unit/email-dao-test.js b/test/new-unit/email-dao-test.js index 7ac9d4d..6439815 100644 --- a/test/new-unit/email-dao-test.js +++ b/test/new-unit/email-dao-test.js @@ -994,8 +994,9 @@ define(function(require) { dao.decryptBody({ message: message }, function(error, msg) { - expect(error).to.exist; - expect(msg).to.not.exist; + expect(error).to.not.exist; + expect(msg.body).to.equal('asd'); + expect(msg).to.exist; expect(message.decryptingBody).to.be.false; expect(keychainStub.getReceiverPublicKey.calledOnce).to.be.true;