1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-29 12:22:22 -05:00

Show decrypting/parsing errors in mail reader

This commit is contained in:
Tankred Hase 2014-05-12 13:44:02 +02:00
parent 2a1a92f907
commit 99edcee93b
3 changed files with 21 additions and 14 deletions

View File

@ -70,10 +70,13 @@ define(function(require) {
$scope.node = undefined; $scope.node = undefined;
}); });
$scope.$watch('state.mailList.selected.body', function(body) { $scope.$watch('state.mailList.selected.body', function(body) {
var selected = $scope.state.mailList.selected;
$scope.node = undefined; // reset model $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; return;
} }

View File

@ -398,15 +398,13 @@ define(function(require) {
// get the sender's public key for signature checking // get the sender's public key for signature checking
self._keychain.getReceiverPublicKey(message.from[0].address, function(err, senderPublicKey) { self._keychain.getReceiverPublicKey(message.from[0].address, function(err, senderPublicKey) {
if (err) { if (err) {
message.decryptingBody = false; done(err);
callback(err);
return; return;
} }
if (!senderPublicKey) { if (!senderPublicKey) {
// this should only happen if a mail from another channel is in the inbox // this should only happen if a mail from another channel is in the inbox
message.body = 'Public key for sender not found!'; showError('Public key for sender not found!');
done();
return; return;
} }
@ -414,8 +412,7 @@ define(function(require) {
var encryptedNode = self._emailSync.filterBodyParts(message.bodyParts, 'encrypted')[0]; var encryptedNode = self._emailSync.filterBodyParts(message.bodyParts, 'encrypted')[0];
self._crypto.decrypt(encryptedNode.content, senderPublicKey.publicKey, function(err, decrypted) { self._crypto.decrypt(encryptedNode.content, senderPublicKey.publicKey, function(err, decrypted) {
if (err || !decrypted) { if (err || !decrypted) {
message.body = err.errMsg || err.message; showError(err.errMsg || err.message);
done();
return; return;
} }
@ -425,9 +422,9 @@ define(function(require) {
// parse the decrpyted raw content in the mailparser // parse the decrpyted raw content in the mailparser
self._mailreader.parse({ self._mailreader.parse({
bodyParts: [encryptedNode] bodyParts: [encryptedNode]
}, function(error, parsedBodyParts) { }, function(err, parsedBodyParts) {
if (error) { if (err) {
done(error); showError(err.errMsg || err.message);
return; 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) { function done(err) {
message.decryptingBody = false; message.decryptingBody = false;
callback(err, err ? undefined : message); callback(err, err ? undefined : message);

View File

@ -994,8 +994,9 @@ define(function(require) {
dao.decryptBody({ dao.decryptBody({
message: message message: message
}, function(error, msg) { }, function(error, msg) {
expect(error).to.exist; expect(error).to.not.exist;
expect(msg).to.not.exist; expect(msg.body).to.equal('asd');
expect(msg).to.exist;
expect(message.decryptingBody).to.be.false; expect(message.decryptingBody).to.be.false;
expect(keychainStub.getReceiverPublicKey.calledOnce).to.be.true; expect(keychainStub.getReceiverPublicKey.calledOnce).to.be.true;