feat(mail): handle multiple mail identities

Fixes #768, fixes #4602
This commit is contained in:
Francis Lachapelle
2020-06-18 16:53:42 -04:00
parent 2651b5aa9d
commit f8aa338e64
24 changed files with 605 additions and 426 deletions
@@ -7,23 +7,23 @@
/**
* @ngInject
*/
AccountDialogController.$inject = ['$timeout', '$mdDialog', 'FileUploader', 'Dialog', 'sgSettings', 'Account', 'defaults', 'account', 'accountId', 'mailCustomFromEnabled'];
function AccountDialogController($timeout, $mdDialog, FileUploader, Dialog, Settings, Account, defaults, account, accountId, mailCustomFromEnabled) {
var vm = this,
accountObject = new Account({ id: accountId, security: account.security });
AccountDialogController.$inject = ['$timeout', '$window', '$mdConstant', '$mdDialog', 'FileUploader', 'Dialog', 'sgSettings', 'defaults', 'account', 'accountId', 'mailCustomFromEnabled'];
function AccountDialogController($timeout, $window, $mdConstant, $mdDialog, FileUploader, Dialog, Settings, defaults, account, accountId, mailCustomFromEnabled) {
var vm = this;
vm.defaultPort = 143;
vm.defaults = defaults;
vm.account = account;
vm.accountId = accountId;
vm.customFromIsReadonly = customFromIsReadonly;
vm.onBeforeUploadCertificate = onBeforeUploadCertificate;
vm.removeCertificate = removeCertificate;
vm.importCertificate = importCertificate;
vm.cancel = cancel;
vm.save = save;
vm.hostnameRE = accountId > 0 ? /^(?!(127\.0\.0\.1|localhost(?:\.localdomain)?)$)/ : /./;
vm.ckConfig = {
this.defaultPort = 143;
this.defaults = defaults;
this.account = account;
this.accountId = accountId;
this.hostnameRE = accountId > 0 ? /^(?!(127\.0\.0\.1|localhost(?:\.localdomain)?)$)/ : /./;
this.addressesSearchText = '';
this.emailSeparatorKeys = [
$mdConstant.KEY_CODE.ENTER,
$mdConstant.KEY_CODE.TAB,
$mdConstant.KEY_CODE.COMMA,
$mdConstant.KEY_CODE.SEMICOLON
];
this.ckConfig = {
'autoGrow_minHeight': 70,
'toolbar': [['Bold', 'Italic', '-', 'Link',
'Font','FontSize','-','TextColor',
@@ -31,14 +31,14 @@
language: defaults.LocaleCode
};
if (!vm.account.encryption)
vm.account.encryption = "none";
else if (vm.account.encryption == "ssl")
vm.defaultPort = 993;
if (!this.account.encryption)
this.account.encryption = "none";
else if (this.account.encryption == "ssl")
this.defaultPort = 993;
_loadCertificate();
vm.uploader = new FileUploader({
this.uploader = new FileUploader({
url: [Settings.activeUser('folderURL') + 'Mail', accountId, 'importCertificate'].join('/'),
autoUpload: false,
queueLimit: 1,
@@ -58,9 +58,65 @@
}
});
this.hasIdentities = function () {
return _.filter(this.account.identities, vm.isEditableIdentity).length > 0;
};
this.isEditableIdentity = function (identity) {
return !identity.isReadOnly;
};
this.selectIdentity = function (index) {
if (this.selectedIdentity == index) {
this.selectedIdentity = null;
} else {
this.selectedIdentity = index;
}
};
this.setDefaultIdentity = function ($event, $index) {
_.forEach(this.account.identities, function(identity, i) {
if (i == $index)
identity.isDefault = !identity.isDefault;
else
delete identity.isDefault;
});
$event.stopPropagation();
return false;
};
this.canRemoveIdentity = function (index) {
return (index == this.selectedIdentity) && (this.account.identities.length > 1);
};
this.removeIdentity = function (index) {
this.account.identities.splice(index, 1);
this.selectedIdentity = null;
};
this.addIdentity = function () {
var firstReadonlyIndex = _.findIndex(this.account.identities, { isReadOnly: 1 });
var identity = {};
if (this.customFromIsReadonly())
identity.fullName = this.account.identities[0].fullName;
this.account.identities.splice(Math.max(firstReadonlyIndex, 0), 0, identity);
this.selectedIdentity = firstReadonlyIndex;
};
this.showCkEditor = function ($index) {
return this.selectedIdentity == $index && this.defaults.SOGoMailComposeMessageType == 'html';
};
this.filterEmailAddresses = function ($query) {
return _.filter($window.defaultEmailAddresses, function (address) {
return address.toLowerCase().indexOf($query.toLowerCase()) >= 0;
});
};
function _loadCertificate() {
if (vm.account.security && vm.account.security.hasCertificate)
accountObject.$certificate().then(function(crt) {
vm.account.$certificate().then(function(crt) {
vm.certificate = crt;
}, function() {
delete vm.account.security.hasCertificate;
@@ -73,35 +129,33 @@
return isP12File;
}
function customFromIsReadonly() {
this.customFromIsReadonly = function () {
if (accountId > 0)
return false;
return !mailCustomFromEnabled;
}
};
function importCertificate() {
vm.uploader.queue[0].formData = [{ password: vm.certificatePassword }];
vm.uploader.uploadItem(0);
}
this.importCertificate = function () {
this.uploader.queue[0].formData = [{ password: this.certificatePassword }];
this.uploader.uploadItem(0);
};
function onBeforeUploadCertificate(form) {
vm.form = form;
vm.uploader.clearQueue();
}
this.onBeforeUploadCertificate = function (form) {
this.form = form;
this.uploader.clearQueue();
};
function removeCertificate() {
accountObject.$removeCertificate().then(function() {
delete vm.account.security.hasCertificate;
});
}
this.removeCertificate = function () {
this.account.$removeCertificate();
};
function cancel() {
this.cancel = function () {
$mdDialog.cancel();
}
};
function save() {
this.save = function () {
$mdDialog.hide();
}
};
}
angular