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