diff --git a/src/js/client.js b/src/js/client.js
index 253203e7c..4fe0f0687 100644
--- a/src/js/client.js
+++ b/src/js/client.js
@@ -2132,6 +2132,44 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
});
};
+ Client.prototype.getSpamAcl = function (callback) {
+ var config = {};
+
+ get('/api/v1/mailserver/spam_acl', config, function (error, data, status) {
+ if (error) return callback(error);
+ if (status !== 200) return callback(new ClientError(status, data));
+ callback(null, data);
+ });
+ };
+
+ Client.prototype.setSpamAcl = function (acl, callback) {
+ post('/api/v1/mailserver/spam_acl', { whitelist: acl.whitelist, blacklist: acl.blacklist }, null, function (error, data, status) {
+ if (error) return callback(error);
+ if (status !== 200) return callback(new ClientError(status, data));
+
+ callback(null);
+ });
+ };
+
+ Client.prototype.getSpamCustomConfig = function (callback) {
+ var config = {};
+
+ get('/api/v1/mailserver/spam_custom_config', config, function (error, data, status) {
+ if (error) return callback(error);
+ if (status !== 200) return callback(new ClientError(status, data));
+ callback(null, data.config);
+ });
+ };
+
+ Client.prototype.setSpamCustomConfig = function (config, callback) {
+ post('/api/v1/mailserver/spam_custom_config', { config: config }, null, function (error, data, status) {
+ if (error) return callback(error);
+ if (status !== 200) return callback(new ClientError(status, data));
+
+ callback(null);
+ });
+ };
+
Client.prototype.getMailConfigForDomain = function (domain, callback) {
get('/api/v1/mail/' + domain, null, function (error, data, status) {
if (error) return callback(error);
diff --git a/src/views/emails.html b/src/views/emails.html
index 6802570c0..604e12ce0 100644
--- a/src/views/emails.html
+++ b/src/views/emails.html
@@ -77,29 +77,32 @@
-
-
+
+
@@ -220,10 +223,10 @@
{{ maxEmailSize.currentSize | prettyDiskSize }}
- Always allowed origins
+ Spam filtering
-
0
+
{{ spamConfig.acl.blacklist.length }} address(es) blacklisted {{ spamConfig.customConfig ? ' + Custom Config' : '' }}
Blocked origins
@@ -237,7 +240,7 @@
-
+
diff --git a/src/views/emails.js b/src/views/emails.js
index d0dfdc5c4..ac7994e68 100644
--- a/src/views/emails.js
+++ b/src/views/emails.js
@@ -145,26 +145,71 @@ angular.module('Application').controller('EmailsController', ['$scope', '$locati
}
};
- $scope.blockAllowLists = {
+ $scope.spamConfig = {
busy: false,
- error: null,
- allowList: '',
- blockList: '',
+ error: {},
+ acl: { whitelist: [], blacklist: [] },
+ customConfig: '',
+
+ config: '',
+ blacklist: '', // currently, we don't support whitelist because it requires user to understand a bit more of what he is doing
+
+ refresh: function () {
+ Client.getSpamCustomConfig(function (error, config) {
+ if (error) return console.error('Failed to get custom spam config', error);
+
+ $scope.spamConfig.customConfig = config;
+ });
+
+ Client.getSpamAcl(function (error, acl) {
+ if (error) return console.error('Failed to get spam acl', error);
+
+ $scope.spamConfig.acl = acl;
+ });
+ },
show: function() {
- $scope.blockAllowLists.busy = false;
- $scope.blockAllowLists.error = null;
- $scope.blockAllowLists.allowList = '';
- $scope.blockAllowLists.blockList = '';
+ $scope.spamConfig.busy = false;
+ $scope.spamConfig.error = {};
- $scope.blockAllowListsChangeForm.$setUntouched();
- $scope.blockAllowListsChangeForm.$setPristine();
+ $scope.spamConfig.blacklist = $scope.spamConfig.acl.blacklist.join('\n');
+ $scope.spamConfig.config = $scope.spamConfig.customConfig;
- $('#blockAllowListsChangeModal').modal('show');
+ $scope.spamConfigChangeForm.$setUntouched();
+ $scope.spamConfigChangeForm.$setPristine();
+
+ $('#spamConfigChangeModal').modal('show');
},
submit: function () {
- console.log('tbd');
+ $scope.spamConfig.busy = true;
+ $scope.spamConfig.error = {};
+
+ var blacklist = $scope.spamConfig.blacklist.split('\n').filter(function (l) { return l !== ''; });
+
+ Client.setSpamAcl({ blacklist: blacklist, whitelist: [] }, function (error) {
+ if (error) {
+ $scope.spamConfig.busy = false;
+ $scope.spamConfig.error.blacklist = error.message;
+ $scope.spamConfigChangeForm.blacklist.$setPristine();
+ return;
+ }
+
+ Client.setSpamCustomConfig($scope.spamConfig.config, function (error) {
+ if (error) {
+ $scope.spamConfig.busy = false;
+ $scope.spamConfig.error.config = error.message;
+ $scope.spamConfigChangeForm.config.$setPristine();
+ return;
+ }
+
+ $scope.spamConfig.busy = false;
+
+ $scope.spamConfig.refresh();
+
+ $('#spamConfigChangeModal').modal('hide');
+ });
+ });
}
},
@@ -251,6 +296,8 @@ angular.module('Application').controller('EmailsController', ['$scope', '$locati
$scope.maxEmailSize.currentSize = size;
});
+
+ $scope.spamConfig.refresh();
});
}