fix(preferences(js)): honor SOGoForwardConstraints in Sieve filters
parent
772efb3e99
commit
5bb8161494
|
@ -189,6 +189,10 @@
|
|||
</div>
|
||||
</div>
|
||||
</md-dialog-content>
|
||||
<md-dialog-content class="md-default-theme md-bg md-warn md-padding sg-dialog-message ng-hide"
|
||||
ng-show="filterEditor.invalid">
|
||||
<div>{{filterEditor.invalid}}</div>
|
||||
</md-dialog-content>
|
||||
<md-dialog-actions>
|
||||
<md-button type="button" ng-click="filterEditor.cancel()"><var:string label:value="Cancel"/></md-button>
|
||||
<md-button type="submit"
|
||||
|
|
|
@ -7,25 +7,18 @@
|
|||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
FiltersDialogController.$inject = ['$scope', '$window', '$mdDialog', 'filter', 'mailboxes', 'labels'];
|
||||
function FiltersDialogController($scope, $window, $mdDialog, filter, mailboxes, labels) {
|
||||
FiltersDialogController.$inject = ['$scope', '$window', '$mdDialog', 'Dialog', 'filter', 'mailboxes', 'labels', 'validateForwardAddress', 'Preferences'];
|
||||
function FiltersDialogController($scope, $window, $mdDialog, Dialog, filter, mailboxes, labels, validateForwardAddress, Preferences) {
|
||||
var vm = this,
|
||||
sieveCapabilities = $window.sieveCapabilities,
|
||||
forwardEnabled = $window.forwardEnabled,
|
||||
vacationEnabled = $window.vacationEnabled;
|
||||
|
||||
vm.filter = filter;
|
||||
vm.mailboxes = mailboxes;
|
||||
vm.labels = labels;
|
||||
vm.cancel = cancel;
|
||||
vm.hasRulesAndActions = hasRulesAndActions;
|
||||
vm.save = save;
|
||||
vm.addMailFilterRule = addMailFilterRule;
|
||||
vm.removeMailFilterRule = removeMailFilterRule;
|
||||
vm.addMailFilterAction = addMailFilterAction;
|
||||
vm.removeMailFilterAction = removeMailFilterAction;
|
||||
this.filter = filter;
|
||||
this.mailboxes = mailboxes;
|
||||
this.labels = labels;
|
||||
|
||||
vm.fieldLabels = {
|
||||
this.fieldLabels = {
|
||||
"subject": l("Subject"),
|
||||
"from": l("From"),
|
||||
"to": l("To"),
|
||||
|
@ -36,35 +29,35 @@
|
|||
};
|
||||
|
||||
if (sieveCapabilities.indexOf("body") > -1)
|
||||
vm.fieldLabels.body = l("Body");
|
||||
this.fieldLabels.body = l("Body");
|
||||
|
||||
vm.methodLabels = {
|
||||
this.methodLabels = {
|
||||
"discard": l("Discard the message"),
|
||||
"keep": l("Keep the message"),
|
||||
"stop": l("Stop processing filter rules")
|
||||
};
|
||||
|
||||
if (forwardEnabled)
|
||||
vm.methodLabels.redirect = l("Forward the message to");
|
||||
this.methodLabels.redirect = l("Forward the message to");
|
||||
|
||||
//if (vacationEnabled)
|
||||
// vm.methodLabels.vacation = l("Send a vacation message");
|
||||
// this.methodLabels.vacation = l("Send a vacation message");
|
||||
|
||||
if (sieveCapabilities.indexOf("reject") > -1)
|
||||
vm.methodLabels.reject = l("Send a reject message");
|
||||
this.methodLabels.reject = l("Send a reject message");
|
||||
|
||||
if (sieveCapabilities.indexOf("fileinto") > -1)
|
||||
vm.methodLabels.fileinto = l("File the message in");
|
||||
this.methodLabels.fileinto = l("File the message in");
|
||||
|
||||
if (sieveCapabilities.indexOf("imapflags") > -1 || sieveCapabilities.indexOf("imap4flags") > -1)
|
||||
vm.methodLabels.addflag = l("Flag the message with");
|
||||
this.methodLabels.addflag = l("Flag the message with");
|
||||
|
||||
vm.numberOperatorLabels = {
|
||||
this.numberOperatorLabels = {
|
||||
"under": l("is under"),
|
||||
"over": l("is over")
|
||||
};
|
||||
|
||||
vm.textOperatorLabels = {
|
||||
this.textOperatorLabels = {
|
||||
"is": l("is"),
|
||||
"is_not": l("is not"),
|
||||
"contains": l("contains"),
|
||||
|
@ -74,49 +67,65 @@
|
|||
};
|
||||
|
||||
if (sieveCapabilities.indexOf("regex") > -1) {
|
||||
vm.textOperatorLabels.regex = l("matches regex");
|
||||
vm.textOperatorLabels.regex_not = l("does not match regex");
|
||||
this.textOperatorLabels.regex = l("matches regex");
|
||||
this.textOperatorLabels.regex_not = l("does not match regex");
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
this.cancel = function () {
|
||||
$mdDialog.cancel();
|
||||
}
|
||||
};
|
||||
|
||||
function hasRulesAndActions() {
|
||||
var requirements = [ vm.filter.actions ];
|
||||
if (vm.filter.match != 'allmessages')
|
||||
this.hasRulesAndActions = function () {
|
||||
var requirements = [ this.filter.actions ];
|
||||
if (this.filter.match != 'allmessages')
|
||||
// When matching all messages, no rules are required
|
||||
requirements.push(vm.filter.rules);
|
||||
requirements.push(this.filter.rules);
|
||||
return _.every(requirements, function(a) {
|
||||
return a && a.length > 0;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function save(form) {
|
||||
this.save = function (form) {
|
||||
var i;
|
||||
|
||||
this.invalid = false;
|
||||
|
||||
// We do some sanity checks
|
||||
if (this.filter.actions) {
|
||||
try {
|
||||
_.forEach(_.filter(this.filter.actions, { 'method': 'redirect' }), function (action) {
|
||||
validateForwardAddress(action.argument);
|
||||
});
|
||||
} catch (err) {
|
||||
//Dialog.alert(l('Error'), err);
|
||||
this.invalid = err.message;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$mdDialog.hide();
|
||||
}
|
||||
};
|
||||
|
||||
function addMailFilterRule(event) {
|
||||
if (!vm.filter.rules)
|
||||
vm.filter.rules = [];
|
||||
this.addMailFilterRule = function (event) {
|
||||
if (!this.filter.rules)
|
||||
this.filter.rules = [];
|
||||
|
||||
vm.filter.rules.push({ field: 'subject', operator: 'contains' });
|
||||
}
|
||||
this.filter.rules.push({ field: 'subject', operator: 'contains' });
|
||||
};
|
||||
|
||||
function removeMailFilterRule(index) {
|
||||
vm.filter.rules.splice(index, 1);
|
||||
}
|
||||
this.removeMailFilterRule = function (index) {
|
||||
this.filter.rules.splice(index, 1);
|
||||
};
|
||||
|
||||
function addMailFilterAction(event) {
|
||||
if (!vm.filter.actions)
|
||||
vm.filter.actions = [];
|
||||
this.addMailFilterAction = function (event) {
|
||||
if (!this.filter.actions)
|
||||
this.filter.actions = [];
|
||||
|
||||
vm.filter.actions.push({ method: 'discard' });
|
||||
}
|
||||
this.filter.actions.push({ method: 'discard' });
|
||||
};
|
||||
|
||||
function removeMailFilterAction(index) {
|
||||
vm.filter.actions.splice(index, 1);
|
||||
}
|
||||
this.removeMailFilterAction = function (index) {
|
||||
this.filter.actions.splice(index, 1);
|
||||
};
|
||||
}
|
||||
|
||||
angular
|
||||
|
|
|
@ -223,7 +223,8 @@
|
|||
locals: {
|
||||
filter: filter,
|
||||
mailboxes: mailboxes,
|
||||
labels: this.preferences.defaults.SOGoMailLabelsColors
|
||||
labels: this.preferences.defaults.SOGoMailLabelsColors,
|
||||
validateForwardAddress: validateForwardAddress
|
||||
}
|
||||
}).then(function() {
|
||||
if (!vm.preferences.defaults.SOGoSieveFilters)
|
||||
|
@ -341,23 +342,18 @@
|
|||
}
|
||||
};
|
||||
|
||||
this.save = function(form, options) {
|
||||
var i, sendForm, addresses, defaultAddresses, domains, domain;
|
||||
function validateForwardAddress(address) {
|
||||
var defaultAddresses, domains, domain;
|
||||
|
||||
sendForm = true;
|
||||
domains = [];
|
||||
|
||||
// We do some sanity checks
|
||||
if ($window.forwardConstraints > 0 &&
|
||||
angular.isDefined(this.preferences.defaults.Forward) &&
|
||||
this.preferences.defaults.Forward.enabled &&
|
||||
angular.isDefined(this.preferences.defaults.Forward.forwardAddress)) {
|
||||
|
||||
addresses = this.preferences.defaults.Forward.forwardAddress;
|
||||
angular.isDefined(Preferences.defaults.Forward) &&
|
||||
Preferences.defaults.Forward.enabled &&
|
||||
angular.isDefined(Preferences.defaults.Forward.forwardAddress)) {
|
||||
|
||||
// We first extract the list of 'known domains' to SOGo
|
||||
defaultAddresses = $window.defaultEmailAddresses;
|
||||
|
||||
_.forEach(defaultAddresses, function(adr) {
|
||||
var domain = adr.split("@")[1];
|
||||
if (domain) {
|
||||
|
@ -366,24 +362,40 @@
|
|||
});
|
||||
|
||||
// We check if we're allowed or not to forward based on the domain defaults
|
||||
for (i = 0; i < addresses.length && sendForm; i++) {
|
||||
domain = addresses[i].split("@")[1].toLowerCase();
|
||||
domain = address.split("@")[1].toLowerCase();
|
||||
if (domains.indexOf(domain) < 0 && $window.forwardConstraints == 1) {
|
||||
Dialog.alert(l('Error'), l("You are not allowed to forward your messages to an external email address."));
|
||||
sendForm = false;
|
||||
throw new Error(l("You are not allowed to forward your messages to an external email address."));
|
||||
}
|
||||
else if (domains.indexOf(domain) >= 0 && $window.forwardConstraints == 2) {
|
||||
Dialog.alert(l('Error'), l("You are not allowed to forward your messages to an internal email address."));
|
||||
sendForm = false;
|
||||
throw new Error(l("You are not allowed to forward your messages to an internal email address."));
|
||||
}
|
||||
else if ($window.forwardConstraints == 2 &&
|
||||
$window.forwardConstraintsDomains.length > 0 &&
|
||||
$window.forwardConstraintsDomains.indexOf(domain) < 0) {
|
||||
Dialog.alert(l('Error'), l("You are not allowed to forward your messages to this domain:") + " " + domain);
|
||||
throw new Error(l("You are not allowed to forward your messages to this domain:") + " " + domain);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
this.save = function(form, options) {
|
||||
var i, sendForm, addresses;
|
||||
|
||||
sendForm = true;
|
||||
|
||||
// We do some sanity checks
|
||||
|
||||
// We check if we're allowed or not to forward based on the domain defaults
|
||||
addresses = this.preferences.defaults.Forward.forwardAddress;
|
||||
try {
|
||||
for (i = 0; i < addresses.length; i++) {
|
||||
validateForwardAddress(addresses[i]);
|
||||
}
|
||||
} catch (err) {
|
||||
Dialog.alert(l('Error'), err);
|
||||
sendForm = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IMAP labels must be unique
|
||||
if (this.preferences.defaults.SOGoMailLabelsColorsKeys.length !=
|
||||
|
@ -441,7 +453,7 @@
|
|||
}
|
||||
});
|
||||
|
||||
return $q.reject();
|
||||
return $q.reject('Invalid form');
|
||||
};
|
||||
|
||||
this.canChangePassword = function() {
|
||||
|
|
Loading…
Reference in New Issue