Improve display of S/MIME certificates

This commit is contained in:
Francis Lachapelle
2018-01-23 13:30:56 -05:00
parent 511aa63a34
commit 7ebdac5525
17 changed files with 291 additions and 60 deletions
@@ -38,10 +38,11 @@
* @desc The factory we'll use to register with Angular.
* @returns the Card constructor
*/
Card.$factory = ['$timeout', 'sgSettings', 'sgCard_STATUS', 'Resource', 'Preferences', function($timeout, Settings, Card_STATUS, Resource, Preferences) {
Card.$factory = ['$q', '$timeout', 'sgSettings', 'sgCard_STATUS', 'Resource', 'Preferences', function($q, $timeout, Settings, Card_STATUS, Resource, Preferences) {
angular.extend(Card, {
STATUS: Card_STATUS,
$$resource: new Resource(Settings.activeUser('folderURL') + 'Contacts', Settings.activeUser()),
$q: $q,
$timeout: $timeout,
$Preferences: Preferences
});
@@ -485,6 +486,44 @@
return this.refs.length - 1;
};
/**
* @function $certificate
* @memberof Account.prototype
* @desc View the S/MIME certificate details associated to the account.
* @returns a promise of the HTTP operation
*/
Card.prototype.$certificate = function() {
var _this = this;
if (this.hasCertificate) {
if (this.$$certificate)
return Card.$q.when(this.$$certificate);
else {
return Card.$$resource.fetch([this.pid, this.id].join('/'), 'certificate').then(function(data) {
_this.$$certificate = data;
return data;
});
}
}
else {
return Card.$q.reject();
}
};
/**
* @function $removeCertificate
* @memberof Account.prototype
* @desc Remove any S/MIME certificate associated with the account.
* @returns a promise of the HTTP operation
*/
Card.prototype.$removeCertificate = function() {
var _this = this;
return Card.$$resource.fetch([this.pid, this.id].join('/'), 'removeCertificate').then(function() {
_this.hasCertificate = false;
});
};
/**
* @function explode
* @memberof Card.prototype
@@ -43,6 +43,7 @@
_registerHotkeys(hotkeys);
_loadCertificate();
$scope.$on('$destroy', function() {
// Deregister hotkeys
@@ -71,6 +72,15 @@
});
}
function _loadCertificate() {
if (vm.card.hasCertificate)
vm.card.$certificate().then(function(crt) {
vm.certificate = crt;
}, function() {
delete vm.card.hasCertificate;
});
}
function transformCategory(input) {
if (angular.isString(input))
return { value: input };
@@ -298,7 +298,7 @@
var formattedMessage = "<p>" + part.error.replace(/\n/, "</p><p class=\"md-caption\">");
formattedMessage = formattedMessage.replace(/\n/g, "</p><p class=\"md-caption\">") + "</p>";
_this.$smime = {
validSignature: part.valid,
valid: part.valid,
certificate: part.certificates[part.certificates.length - 1],
message: formattedMessage
};
@@ -306,8 +306,12 @@
else if (part.type == 'UIxMailPartEncryptedViewer') {
_this.$smime = {
isEncrypted: true,
message: l("This message is encrypted")
valid: part.valid
};
if (part.valid)
_this.$smime.message = l("This message is encrypted");
else
_this.$smime.message = l("This message can't be decrypted. Please make sure you have uploaded your S/MIME certificate from the mail preferences module.");
}
_.forEach(part.content, function(mixedPart) {
_visit(mixedPart);