2018-01-22 13:01:38 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
2019-01-22 10:54:03 +01:00
|
|
|
/* global angular:false */
|
|
|
|
|
/* global $:false */
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
angular.module('Application').controller('EmailController', ['$scope', '$location', '$timeout', '$routeParams', 'Client', function ($scope, $location, $timeout, $routeParams, Client) {
|
2018-08-03 10:09:04 -07:00
|
|
|
Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); });
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
var domainName = $routeParams.domain;
|
|
|
|
|
if (!domainName) return $location.path('/email');
|
|
|
|
|
|
2018-01-23 12:30:35 +01:00
|
|
|
$scope.ready = false;
|
|
|
|
|
$scope.refreshBusy = true;
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.client = Client;
|
|
|
|
|
$scope.user = Client.getUserInfo();
|
|
|
|
|
$scope.config = Client.getConfig();
|
2018-12-06 10:28:42 -08:00
|
|
|
$scope.apps = Client.getInstalledApps();
|
2018-01-23 15:11:33 +01:00
|
|
|
$scope.users = [];
|
2020-02-11 21:06:34 +01:00
|
|
|
$scope.domain = null;
|
2019-12-31 10:33:09 -08:00
|
|
|
$scope.adminDomain = null;
|
2018-01-23 12:30:35 +01:00
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.expectedDnsRecords = {
|
|
|
|
|
mx: { },
|
|
|
|
|
dkim: { },
|
|
|
|
|
spf: { },
|
|
|
|
|
dmarc: { },
|
|
|
|
|
ptr: { }
|
|
|
|
|
};
|
|
|
|
|
$scope.expectedDnsRecordsTypes = [
|
|
|
|
|
{ name: 'MX', value: 'mx' },
|
|
|
|
|
{ name: 'DKIM', value: 'dkim' },
|
|
|
|
|
{ name: 'SPF', value: 'spf' },
|
|
|
|
|
{ name: 'DMARC', value: 'dmarc' },
|
|
|
|
|
{ name: 'PTR', value: 'ptr' }
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$scope.catchall = {
|
2018-04-12 13:02:32 +02:00
|
|
|
mailboxes: [],
|
2018-01-22 13:01:38 -08:00
|
|
|
busy: false,
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.catchall.busy = true;
|
|
|
|
|
|
2018-04-12 13:02:32 +02:00
|
|
|
var addresses = $scope.catchall.mailboxes.map(function (m) { return m.name; });
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.setCatchallAddresses($scope.domain.domain, addresses, function (error) {
|
2018-01-22 13:01:38 -08:00
|
|
|
if (error) console.error('Unable to add catchall address.', error);
|
|
|
|
|
|
2019-01-31 12:24:27 -08:00
|
|
|
$timeout(function () { $scope.catchall.busy = false; }, 2000); // otherwise, it's too fast
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
2018-04-12 13:02:32 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
refresh: function () {
|
2020-02-11 21:06:34 +01:00
|
|
|
$scope.catchall.mailboxes = $scope.domain.mailConfig.catchAll.map(function (name) {
|
2018-04-12 13:02:32 +02:00
|
|
|
return $scope.mailboxes.mailboxes.find(function (m) { return m.name === name; });
|
|
|
|
|
}).filter(function (m) { return !!m; });
|
2018-01-22 13:01:38 -08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-04-01 21:58:12 +02:00
|
|
|
$scope.mailinglists = {
|
|
|
|
|
busy: false,
|
2018-04-06 16:43:43 +02:00
|
|
|
mailinglists: [],
|
2019-10-22 12:47:32 +02:00
|
|
|
search: '',
|
2018-04-01 21:58:12 +02:00
|
|
|
|
2018-04-06 16:43:43 +02:00
|
|
|
add: {
|
|
|
|
|
busy: false,
|
2019-09-11 14:09:53 -07:00
|
|
|
error: {},
|
2018-04-06 16:43:43 +02:00
|
|
|
name: '',
|
2019-09-11 14:09:53 -07:00
|
|
|
membersTxt: '',
|
2018-04-06 16:43:43 +02:00
|
|
|
|
2018-04-09 16:12:18 +02:00
|
|
|
reset: function () {
|
|
|
|
|
$scope.mailinglists.add.busy = false;
|
2019-09-11 14:09:53 -07:00
|
|
|
$scope.mailinglists.add.error = {};
|
2018-04-09 16:12:18 +02:00
|
|
|
$scope.mailinglists.add.name = '';
|
2019-09-11 14:09:53 -07:00
|
|
|
$scope.mailinglists.add.membersTxt = '';
|
2018-04-09 16:12:18 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
show: function () {
|
|
|
|
|
$scope.mailinglists.add.reset();
|
|
|
|
|
$('#mailinglistAddModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
2018-04-06 16:43:43 +02:00
|
|
|
submit: function () {
|
|
|
|
|
$scope.mailinglists.add.busy = true;
|
2018-04-01 21:58:12 +02:00
|
|
|
|
2019-09-11 14:09:53 -07:00
|
|
|
var members = $scope.mailinglists.add.membersTxt
|
|
|
|
|
.split(/[\n,]/)
|
|
|
|
|
.map(function (m) { return m.trim(); })
|
|
|
|
|
.filter(function (m) { return m.length !== 0; });
|
2018-04-12 11:57:15 +02:00
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.addMailingList($scope.domain.domain, $scope.mailinglists.add.name, members, function (error) {
|
2019-09-11 14:09:53 -07:00
|
|
|
$scope.mailinglists.add.busy = false;
|
|
|
|
|
$scope.mailinglists.add.error = {};
|
|
|
|
|
|
2018-04-06 16:43:43 +02:00
|
|
|
if (error) {
|
2019-09-11 14:09:53 -07:00
|
|
|
if (error.statusCode === 400 && error.message.indexOf('member') !== -1) {
|
|
|
|
|
$scope.mailinglists.add.error.members = error.message;
|
|
|
|
|
} else {
|
|
|
|
|
$scope.mailinglists.add.error.name = error.message;
|
|
|
|
|
}
|
2018-04-06 16:43:43 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-09 16:12:18 +02:00
|
|
|
$scope.mailinglists.add.reset();
|
2018-04-06 16:43:43 +02:00
|
|
|
$scope.mailinglists.refresh();
|
2018-04-09 16:12:18 +02:00
|
|
|
|
|
|
|
|
$('#mailinglistAddModal').modal('hide');
|
2018-04-01 21:58:12 +02:00
|
|
|
});
|
2018-04-06 16:43:43 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2018-04-09 15:01:12 +02:00
|
|
|
edit: {
|
|
|
|
|
busy: false,
|
2019-09-11 14:09:53 -07:00
|
|
|
error: {},
|
2018-04-12 12:02:20 +02:00
|
|
|
name: '',
|
2019-09-11 14:09:53 -07:00
|
|
|
membersTxt: '',
|
2018-04-09 15:01:12 +02:00
|
|
|
|
|
|
|
|
show: function (list) {
|
2018-04-12 12:02:20 +02:00
|
|
|
$scope.mailinglists.edit.name = list.name;
|
2019-09-11 14:09:53 -07:00
|
|
|
$scope.mailinglists.edit.membersTxt = list.members.sort().join('\n');
|
2018-04-09 15:01:12 +02:00
|
|
|
|
|
|
|
|
$('#mailinglistEditModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.mailinglists.edit.busy = true;
|
|
|
|
|
|
2019-09-11 14:09:53 -07:00
|
|
|
var members = $scope.mailinglists.edit.membersTxt.split(/[\n,]/)
|
|
|
|
|
.map(function (m) { return m.trim(); })
|
|
|
|
|
.filter(function (m) { return m.length !== 0; });
|
2018-04-12 12:02:20 +02:00
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.updateMailingList($scope.domain.domain, $scope.mailinglists.edit.name, members, function (error) {
|
2018-04-09 15:01:12 +02:00
|
|
|
$scope.mailinglists.edit.busy = false;
|
2019-09-11 14:09:53 -07:00
|
|
|
$scope.mailinglists.edit.error = {};
|
2018-04-09 15:01:12 +02:00
|
|
|
|
2019-09-11 14:09:53 -07:00
|
|
|
if (error) {
|
|
|
|
|
$scope.mailinglists.edit.error.members = error.message;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-04-09 15:01:12 +02:00
|
|
|
|
2018-04-12 12:12:22 +02:00
|
|
|
$scope.mailinglists.refresh();
|
|
|
|
|
|
2018-04-09 15:01:12 +02:00
|
|
|
$('#mailinglistEditModal').modal('hide');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2018-04-06 16:43:43 +02:00
|
|
|
remove: {
|
|
|
|
|
busy: false,
|
|
|
|
|
list: null,
|
|
|
|
|
|
|
|
|
|
show: function (list) {
|
|
|
|
|
$scope.mailinglists.remove.list = list;
|
|
|
|
|
|
|
|
|
|
$('#mailinglistRemoveModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.mailinglists.remove.busy = true;
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.removeMailingList($scope.domain.domain, $scope.mailinglists.remove.list.name, function (error) {
|
2018-04-06 16:43:43 +02:00
|
|
|
$scope.mailinglists.remove.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.mailinglists.remove.list = null;
|
|
|
|
|
$scope.mailinglists.refresh();
|
|
|
|
|
|
|
|
|
|
$('#mailinglistRemoveModal').modal('hide');
|
2018-04-01 21:58:12 +02:00
|
|
|
});
|
2018-04-06 16:43:43 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2018-04-12 13:02:32 +02:00
|
|
|
refresh: function (callback) {
|
|
|
|
|
callback = typeof callback === 'function' ? callback : function (error) { if (error) return console.error(error); };
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.listMailingLists($scope.domain.domain, function (error, result) {
|
2018-04-12 13:02:32 +02:00
|
|
|
if (error) return callback(error);
|
2018-04-06 16:43:43 +02:00
|
|
|
|
2018-04-12 12:15:23 +02:00
|
|
|
$scope.mailinglists.mailinglists = result;
|
2018-04-12 13:02:32 +02:00
|
|
|
|
|
|
|
|
callback();
|
2018-04-01 21:58:12 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-05-23 23:34:09 -07:00
|
|
|
$scope.toggleMailFromValidation = function () {
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.setMailFromValidation($scope.domain.domain, !$scope.domain.mailConfig.mailFromValidation, function (error) {
|
2018-05-23 23:34:09 -07:00
|
|
|
if (error) return console.error(error);
|
|
|
|
|
$scope.refreshDomain();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-30 11:26:26 -07:00
|
|
|
$scope.incomingEmail = {
|
|
|
|
|
busy: false,
|
2019-05-09 15:40:48 -07:00
|
|
|
setupDns: true,
|
|
|
|
|
setupDnsBusy: false,
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-07-30 11:26:26 -07:00
|
|
|
toggleEmailEnabled: function () {
|
2020-02-11 21:06:34 +01:00
|
|
|
if ($scope.domain.mailConfig.enabled) {
|
2018-07-30 11:26:26 -07:00
|
|
|
$('#disableEmailModal').modal('show');
|
|
|
|
|
} else {
|
|
|
|
|
$('#enableEmailModal').modal('show');
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-05-29 17:17:53 +02:00
|
|
|
|
2019-05-09 15:40:48 -07:00
|
|
|
setDnsRecords: function (callback) {
|
|
|
|
|
$scope.incomingEmail.setupDnsBusy = true;
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.setDnsRecords($scope.domain.domain, function (error) {
|
2019-05-09 15:40:48 -07:00
|
|
|
if (error) console.error(error);
|
|
|
|
|
|
|
|
|
|
$timeout(function () { $scope.incomingEmail.setupDnsBusy = false; }, 2000); // otherwise, it's too fast
|
|
|
|
|
|
|
|
|
|
if (callback) callback();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2018-07-30 11:26:26 -07:00
|
|
|
enable: function () {
|
|
|
|
|
$('#enableEmailModal').modal('hide');
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-07-30 11:26:26 -07:00
|
|
|
$scope.incomingEmail.busy = true;
|
2018-07-25 10:51:58 -07:00
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.enableMailForDomain($scope.domain.domain, true , function (error) {
|
2018-07-25 10:51:58 -07:00
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
2018-08-12 13:13:52 -07:00
|
|
|
$scope.reconfigureEmailApps();
|
|
|
|
|
|
2019-05-09 15:40:48 -07:00
|
|
|
let maybeSetupDns = $scope.incomingEmail.setupDns ? $scope.incomingEmail.setDnsRecords : function (next) { next(); };
|
|
|
|
|
|
|
|
|
|
maybeSetupDns(function (error) {
|
2018-07-30 11:26:26 -07:00
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.refreshDomain();
|
|
|
|
|
|
|
|
|
|
$scope.incomingEmail.busy = false;
|
|
|
|
|
});
|
2018-07-25 10:51:58 -07:00
|
|
|
});
|
2018-07-30 11:26:26 -07:00
|
|
|
},
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-07-30 11:26:26 -07:00
|
|
|
disable: function () {
|
|
|
|
|
$('#disableEmailModal').modal('hide');
|
2018-05-06 23:36:40 -07:00
|
|
|
|
2018-07-30 11:26:26 -07:00
|
|
|
$scope.incomingEmail.busy = true;
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.enableMailForDomain($scope.domain.domain, false , function (error) {
|
2018-07-30 11:26:26 -07:00
|
|
|
if (error) return console.error(error);
|
2018-08-12 13:13:52 -07:00
|
|
|
|
|
|
|
|
$scope.reconfigureEmailApps();
|
2018-07-30 11:26:26 -07:00
|
|
|
$scope.refreshDomain();
|
|
|
|
|
$scope.incomingEmail.busy = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-01-22 13:01:38 -08:00
|
|
|
};
|
|
|
|
|
|
2018-03-30 18:06:40 +02:00
|
|
|
$scope.mailboxes = {
|
2018-04-05 21:00:33 +02:00
|
|
|
mailboxes: [],
|
2019-10-22 12:47:32 +02:00
|
|
|
search: '',
|
2018-04-06 16:51:57 +02:00
|
|
|
|
2018-04-05 21:00:33 +02:00
|
|
|
add: {
|
2018-04-09 15:56:20 +02:00
|
|
|
error: null,
|
2018-04-05 21:00:33 +02:00
|
|
|
busy: false,
|
|
|
|
|
name: '',
|
|
|
|
|
owner: null,
|
|
|
|
|
|
2018-04-09 15:56:20 +02:00
|
|
|
reset: function () {
|
|
|
|
|
$scope.mailboxes.add.busy = false;
|
|
|
|
|
$scope.mailboxes.add.error = null;
|
|
|
|
|
$scope.mailboxes.add.name = '';
|
|
|
|
|
$scope.mailboxes.add.owner = null;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
show: function () {
|
|
|
|
|
$scope.mailboxes.add.reset();
|
|
|
|
|
$('#mailboxAddModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
2018-04-05 21:00:33 +02:00
|
|
|
submit: function () {
|
|
|
|
|
$scope.mailboxes.add.busy = true;
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.addMailbox($scope.domain.domain, $scope.mailboxes.add.name, $scope.mailboxes.add.owner.id, function (error) {
|
2018-04-06 16:51:57 +02:00
|
|
|
if (error) {
|
2018-04-09 15:56:20 +02:00
|
|
|
$scope.mailboxes.add.busy = false;
|
2018-04-09 16:21:32 +02:00
|
|
|
$scope.mailboxes.add.error = error;
|
2018-04-06 16:51:57 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-09 15:56:20 +02:00
|
|
|
$scope.mailboxes.add.reset();
|
2018-04-12 13:02:32 +02:00
|
|
|
$scope.mailboxes.refresh(function (error) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.catchall.refresh();
|
2018-04-09 15:56:20 +02:00
|
|
|
|
2018-04-12 13:02:32 +02:00
|
|
|
$('#mailboxAddModal').modal('hide');
|
|
|
|
|
});
|
2018-04-05 21:00:33 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2018-04-09 12:42:14 +02:00
|
|
|
edit: {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: null,
|
2018-04-12 12:26:51 +02:00
|
|
|
name: '',
|
|
|
|
|
owner: null,
|
|
|
|
|
aliases: '',
|
2018-04-09 12:42:14 +02:00
|
|
|
|
|
|
|
|
show: function (mailbox) {
|
2018-04-12 12:26:51 +02:00
|
|
|
$scope.mailboxes.edit.name = mailbox.name;
|
2019-01-10 13:31:49 -08:00
|
|
|
$scope.mailboxes.edit.owner = mailbox.owner; // this can be null if mailbox had no owner
|
2018-04-12 12:26:51 +02:00
|
|
|
$scope.mailboxes.edit.aliases = mailbox.aliases;
|
2018-04-09 12:42:14 +02:00
|
|
|
|
|
|
|
|
$('#mailboxEditModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
2018-04-09 15:01:12 +02:00
|
|
|
$scope.mailboxes.edit.busy = true;
|
2018-04-09 12:42:14 +02:00
|
|
|
|
2019-01-10 13:31:49 -08:00
|
|
|
// $scope.mailboxes.edit.owner is expected to be validated by the UI
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.updateMailbox($scope.domain.domain, $scope.mailboxes.edit.name, $scope.mailboxes.edit.owner.id, function (error) {
|
2018-04-09 12:42:14 +02:00
|
|
|
if (error) {
|
|
|
|
|
$scope.mailboxes.edit.error = error;
|
|
|
|
|
$scope.mailboxes.edit.busy = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-12 12:26:51 +02:00
|
|
|
var aliases = $scope.mailboxes.edit.aliases.split(',').map(function (a) { return a.trim(); }).filter(function (a) { return !!a; });
|
2018-04-09 12:42:14 +02:00
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.setAliases($scope.domain.domain, $scope.mailboxes.edit.name, aliases, function (error) {
|
2018-04-09 12:42:14 +02:00
|
|
|
if (error) {
|
|
|
|
|
$scope.mailboxes.edit.error = error;
|
|
|
|
|
$scope.mailboxes.edit.busy = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.mailboxes.edit.busy = false;
|
|
|
|
|
$scope.mailboxes.edit.error = null;
|
2018-04-12 12:26:51 +02:00
|
|
|
$scope.mailboxes.edit.name = '';
|
|
|
|
|
$scope.mailboxes.edit.owner = null;
|
|
|
|
|
$scope.mailboxes.edit.aliases = '';
|
2018-04-09 12:42:14 +02:00
|
|
|
$scope.mailboxes.refresh();
|
|
|
|
|
|
|
|
|
|
$('#mailboxEditModal').modal('hide');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2018-04-05 21:22:07 +02:00
|
|
|
remove: {
|
|
|
|
|
busy: false,
|
|
|
|
|
mailbox: null,
|
|
|
|
|
|
|
|
|
|
show: function (mailbox) {
|
|
|
|
|
$scope.mailboxes.remove.mailbox = mailbox;
|
|
|
|
|
|
|
|
|
|
$('#mailboxRemoveModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.mailboxes.remove.busy = true;
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.removeMailbox($scope.domain.domain, $scope.mailboxes.remove.mailbox.name, function (error) {
|
2018-04-05 21:22:07 +02:00
|
|
|
$scope.mailboxes.remove.busy = false;
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.mailboxes.remove.mailbox = null;
|
2018-04-12 13:02:32 +02:00
|
|
|
$scope.mailboxes.refresh(function (error) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.catchall.refresh();
|
2018-04-05 21:22:07 +02:00
|
|
|
|
2018-04-12 13:02:32 +02:00
|
|
|
$('#mailboxRemoveModal').modal('hide');
|
|
|
|
|
});
|
2018-04-05 21:22:07 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2018-04-12 13:02:32 +02:00
|
|
|
refresh: function (callback) {
|
|
|
|
|
callback = typeof callback === 'function' ? callback : function (error) { if (error) return console.error(error); };
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.getMailboxes($scope.domain.domain, function (error, mailboxes) {
|
2018-04-12 13:02:32 +02:00
|
|
|
if (error) return callback(error);
|
2018-04-05 21:00:33 +02:00
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.listAliases($scope.domain.domain, function (error, aliases) {
|
2018-04-12 13:02:32 +02:00
|
|
|
if (error) return callback(error);
|
2018-04-05 21:00:33 +02:00
|
|
|
|
|
|
|
|
$scope.mailboxes.mailboxes = mailboxes.map(function (m) {
|
2018-04-05 21:15:02 +02:00
|
|
|
m.aliases = aliases.filter(function (a) { return a.aliasTarget === m.name; }).map(function (a) { return a.name; }).join(',');
|
2019-01-10 13:31:49 -08:00
|
|
|
m.owner = $scope.users.find(function (u) { return u.id === m.ownerId; }); // owner may not exist
|
|
|
|
|
m.ownerDisplayName = m.owner ? m.owner.display : ''; // this meta property is set when we get the user list
|
2018-12-06 10:28:42 -08:00
|
|
|
|
2018-04-05 21:00:33 +02:00
|
|
|
return m;
|
|
|
|
|
});
|
2018-04-12 13:02:32 +02:00
|
|
|
|
|
|
|
|
callback();
|
2018-04-05 21:00:33 +02:00
|
|
|
});
|
|
|
|
|
});
|
2018-03-30 18:06:40 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.mailRelayPresets = [
|
|
|
|
|
{ provider: 'cloudron-smtp', name: 'Built-in SMTP server' },
|
|
|
|
|
{ provider: 'external-smtp', name: 'External SMTP server', host: '', port: 587 },
|
2019-04-22 16:49:59 -07:00
|
|
|
{ provider: 'external-smtp-noauth', name: 'External SMTP server (No Authentication)', host: '', port: 587 },
|
2019-08-02 12:42:10 -07:00
|
|
|
{ provider: 'ses-smtp', name: 'Amazon SES', host: 'email-smtp.us-east-1.amazonaws.com', port: 587, spfDoc: 'https://docs.aws.amazon.com/ses/latest/DeveloperGuide/spf.html' },
|
|
|
|
|
{ provider: 'google-smtp', name: 'Google', host: 'smtp.gmail.com', port: 587, spfDoc: 'https://support.google.com/a/answer/33786?hl=en' },
|
|
|
|
|
{ provider: 'mailgun-smtp', name: 'Mailgun', host: 'smtp.mailgun.org', port: 587, spfDoc: 'https://www.mailgun.com/blog/white-labeling-dns-records-your-customers-tips-tricks' },
|
|
|
|
|
{ provider: 'mailjet-smtp', name: 'Mailjet', host: '', port: 587, spfDoc: 'https://app.mailjet.com/docs/spf-dkim-guide' },
|
|
|
|
|
{ provider: 'postmark-smtp', name: 'Postmark', host: 'smtp.postmarkapp.com', port: 587, spfDoc: 'https://postmarkapp.com/support/article/1092-how-do-i-set-up-spf-for-postmark' },
|
|
|
|
|
{ provider: 'sendgrid-smtp', name: 'SendGrid', host: 'smtp.sendgrid.net', port: 587, username: 'apikey', spfDoc: 'https://sendgrid.com/docs/ui/account-and-settings/spf-records/' },
|
|
|
|
|
{ provider: 'sparkpost-smtp', name: 'SparkPost', host: 'smtp.sparkpostmail.com', port: 587, username: 'SMTP_Injection', spfDoc: 'https://www.sparkpost.com/resources/email-explained/spf-sender-policy-framework/' },
|
2019-03-15 11:16:43 -07:00
|
|
|
{ provider: 'noop', name: 'Disable' },
|
2018-01-22 13:01:38 -08:00
|
|
|
];
|
|
|
|
|
|
2019-04-22 16:49:59 -07:00
|
|
|
$scope.usesTokenAuth = function (provider) {
|
2019-07-15 10:49:13 -07:00
|
|
|
return provider === 'postmark-smtp' || provider === 'sendgrid-smtp' || provider === 'sparkpost-smtp';
|
2019-04-22 16:49:59 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.usesExternalServer = function (provider) {
|
|
|
|
|
return provider !== 'cloudron-smtp' && provider !== 'noop';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.usesPasswordAuth = function (provider) {
|
|
|
|
|
return provider === 'external-smtp'
|
|
|
|
|
|| provider === 'ses-smtp'
|
|
|
|
|
|| provider === 'google-smtp'
|
|
|
|
|
|| provider === 'mailgun-smtp'
|
|
|
|
|
|| provider === 'mailjet-smtp';
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.mailRelay = {
|
|
|
|
|
error: null,
|
|
|
|
|
success: false,
|
|
|
|
|
busy: false,
|
|
|
|
|
preset: $scope.mailRelayPresets[0],
|
|
|
|
|
|
|
|
|
|
presetChanged: function () {
|
|
|
|
|
$scope.mailRelay.error = null;
|
|
|
|
|
|
|
|
|
|
$scope.mailRelay.relay.provider = $scope.mailRelay.preset.provider;
|
|
|
|
|
$scope.mailRelay.relay.host = $scope.mailRelay.preset.host;
|
|
|
|
|
$scope.mailRelay.relay.port = $scope.mailRelay.preset.port;
|
|
|
|
|
$scope.mailRelay.relay.username = '';
|
|
|
|
|
$scope.mailRelay.relay.password = '';
|
|
|
|
|
$scope.mailRelay.relay.serverApiToken = '';
|
2019-04-23 15:24:31 -07:00
|
|
|
$scope.mailRelay.relay.acceptSelfSignedCerts = false;
|
2018-01-22 13:01:38 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// form data to be set on load
|
|
|
|
|
relay: {
|
|
|
|
|
provider: 'cloudron-smtp',
|
|
|
|
|
host: '',
|
|
|
|
|
port: 25,
|
|
|
|
|
username: '',
|
|
|
|
|
password: '',
|
2019-04-23 15:24:31 -07:00
|
|
|
serverApiToken: '',
|
|
|
|
|
acceptSelfSignedCerts: false
|
2018-01-22 13:01:38 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.mailRelay.error = null;
|
|
|
|
|
$scope.mailRelay.busy = true;
|
|
|
|
|
$scope.mailRelay.success = false;
|
|
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
|
provider: $scope.mailRelay.relay.provider,
|
|
|
|
|
host: $scope.mailRelay.relay.host,
|
2019-04-23 15:24:31 -07:00
|
|
|
port: $scope.mailRelay.relay.port,
|
|
|
|
|
acceptSelfSignedCerts: $scope.mailRelay.relay.acceptSelfSignedCerts
|
2018-01-22 13:01:38 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// fill in provider specific username/password usage
|
|
|
|
|
if (data.provider === 'postmark-smtp') {
|
|
|
|
|
data.username = $scope.mailRelay.relay.serverApiToken;
|
|
|
|
|
data.password = $scope.mailRelay.relay.serverApiToken;
|
|
|
|
|
} else if (data.provider === 'sendgrid-smtp') {
|
|
|
|
|
data.username = 'apikey';
|
|
|
|
|
data.password = $scope.mailRelay.relay.serverApiToken;
|
2019-07-15 10:49:13 -07:00
|
|
|
} else if (data.provider === 'sparkpost-smtp') {
|
|
|
|
|
data.username = 'SMTP_Injection';
|
|
|
|
|
data.password = $scope.mailRelay.relay.serverApiToken;
|
2018-01-22 13:01:38 -08:00
|
|
|
} else {
|
|
|
|
|
data.username = $scope.mailRelay.relay.username;
|
|
|
|
|
data.password = $scope.mailRelay.relay.password;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.setMailRelay($scope.domain.domain, data, function (error) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.mailRelay.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
$scope.mailRelay.error = error.message;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
$scope.domain.relay = data;
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.mailRelay.success = true;
|
2018-01-23 12:30:35 +01:00
|
|
|
$scope.refreshDomain();
|
|
|
|
|
|
|
|
|
|
// clear success indicator after 3sec
|
|
|
|
|
$timeout(function () { $scope.mailRelay.success = false; }, 3000);
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-05-06 23:47:38 -07:00
|
|
|
function resetDnsRecords() {
|
2018-01-23 12:30:35 +01:00
|
|
|
$scope.expectedDnsRecordsTypes.forEach(function (record) {
|
|
|
|
|
var type = record.value;
|
2018-05-06 23:47:38 -07:00
|
|
|
$scope.expectedDnsRecords[type] = {};
|
|
|
|
|
|
2018-01-23 12:30:35 +01:00
|
|
|
$('#collapse_dns_' + type).collapse('hide');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#collapse_outbound_smtp').collapse('hide');
|
|
|
|
|
$('#collapse_rbl').collapse('hide');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showExpectedDnsRecords() {
|
|
|
|
|
// open the record details if they are not correct
|
|
|
|
|
$scope.expectedDnsRecordsTypes.forEach(function (record) {
|
|
|
|
|
var type = record.value;
|
2020-02-11 21:06:34 +01:00
|
|
|
$scope.expectedDnsRecords[type] = $scope.domain.mailStatus.dns[type] || {};
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-01-23 12:30:35 +01:00
|
|
|
if (!$scope.expectedDnsRecords[type].status) {
|
|
|
|
|
$('#collapse_dns_' + type).collapse('show');
|
|
|
|
|
}
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
2018-01-23 12:30:35 +01:00
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
if (!$scope.domain.mailStatus.relay.status) {
|
2018-01-23 12:30:35 +01:00
|
|
|
$('#collapse_outbound_smtp').collapse('show');
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
if (!$scope.domain.mailStatus.rbl.status) {
|
2018-01-23 12:30:35 +01:00
|
|
|
$('#collapse_rbl').collapse('show');
|
|
|
|
|
}
|
2018-01-22 13:01:38 -08:00
|
|
|
}
|
|
|
|
|
|
2018-04-09 18:00:08 +02:00
|
|
|
$scope.selectDomain = function () {
|
2020-02-11 21:06:34 +01:00
|
|
|
$location.path('/email/' + $scope.domain.domain, false);
|
2018-04-09 18:00:08 +02:00
|
|
|
};
|
|
|
|
|
|
2018-08-12 13:13:52 -07:00
|
|
|
// this is required because we need to rewrite the MAIL_DOMAINS env var
|
|
|
|
|
$scope.reconfigureEmailApps = function () {
|
|
|
|
|
var installedApps = Client.getInstalledApps();
|
|
|
|
|
for (var i = 0; i < installedApps.length; i++) {
|
|
|
|
|
if (!installedApps[i].manifest.addons.email) continue;
|
|
|
|
|
|
2019-10-04 11:20:27 -07:00
|
|
|
Client.repairApp(installedApps[i].id, { }, function (error) {
|
2018-08-12 13:13:52 -07:00
|
|
|
if (error) console.error(error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-23 12:30:35 +01:00
|
|
|
$scope.refreshDomain = function () {
|
|
|
|
|
$scope.refreshBusy = true;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-05-06 23:47:38 -07:00
|
|
|
resetDnsRecords();
|
2018-01-23 12:30:35 +01:00
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.getMailConfigForDomain(domainName, function (error, mailConfig) {
|
2018-01-23 12:30:35 +01:00
|
|
|
if (error) {
|
|
|
|
|
$scope.refreshBusy = false;
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pre-fill the form
|
|
|
|
|
$scope.mailRelay.relay.provider = mailConfig.relay.provider;
|
|
|
|
|
$scope.mailRelay.relay.host = mailConfig.relay.host;
|
|
|
|
|
$scope.mailRelay.relay.port = mailConfig.relay.port;
|
2019-04-23 15:24:31 -07:00
|
|
|
$scope.mailRelay.relay.acceptSelfSignedCerts = !!mailConfig.relay.acceptSelfSignedCerts;
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.mailRelay.relay.username = '';
|
|
|
|
|
$scope.mailRelay.relay.password = '';
|
|
|
|
|
$scope.mailRelay.relay.serverApiToken = '';
|
|
|
|
|
|
2018-01-23 12:30:35 +01:00
|
|
|
if (mailConfig.relay.provider === 'postmark-smtp') {
|
|
|
|
|
$scope.mailRelay.relay.serverApiToken = mailConfig.relay.username;
|
|
|
|
|
} else if (mailConfig.relay.provider === 'sendgrid-smtp') {
|
|
|
|
|
$scope.mailRelay.relay.serverApiToken = mailConfig.relay.password;
|
2019-07-15 10:49:13 -07:00
|
|
|
} else if (mailConfig.relay.provider === 'sparkpost-smtp') {
|
|
|
|
|
$scope.mailRelay.relay.serverApiToken = mailConfig.relay.password;
|
2018-01-22 13:01:38 -08:00
|
|
|
} else {
|
2018-01-23 12:30:35 +01:00
|
|
|
$scope.mailRelay.relay.username = mailConfig.relay.username;
|
|
|
|
|
$scope.mailRelay.relay.password = mailConfig.relay.password;
|
2018-01-22 13:01:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < $scope.mailRelayPresets.length; i++) {
|
2018-01-23 12:30:35 +01:00
|
|
|
if ($scope.mailRelayPresets[i].provider === mailConfig.relay.provider) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.mailRelay.preset = $scope.mailRelayPresets[i];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-23 12:41:52 +01:00
|
|
|
// amend to selected domain to be available for the UI
|
2020-02-11 21:06:34 +01:00
|
|
|
$scope.domain.mailConfig = mailConfig;
|
|
|
|
|
$scope.domain.mailStatus = {};
|
2018-01-23 12:41:52 +01:00
|
|
|
|
2018-04-12 13:02:32 +02:00
|
|
|
$scope.mailboxes.refresh(function (error) {
|
|
|
|
|
if (error) console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.mailinglists.refresh();
|
|
|
|
|
$scope.catchall.refresh();
|
|
|
|
|
});
|
2018-04-01 21:58:12 +02:00
|
|
|
|
2018-01-23 12:41:52 +01:00
|
|
|
// we will fetch the status without blocking the ui
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.getMailStatusForDomain($scope.domain.domain, function (error, mailStatus) {
|
2018-01-23 12:41:52 +01:00
|
|
|
$scope.refreshBusy = false;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-01-23 12:41:52 +01:00
|
|
|
if (error) return console.error(error);
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
$scope.domain.mailStatus = mailStatus;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-01-23 12:30:35 +01:00
|
|
|
showExpectedDnsRecords();
|
|
|
|
|
});
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
2018-01-23 12:30:35 +01:00
|
|
|
};
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-01-23 12:38:19 +01:00
|
|
|
$scope.refreshStatus = function () {
|
|
|
|
|
$scope.refreshBusy = true;
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.getMailStatusForDomain($scope.domain.domain, function (error, mailStatus) {
|
2018-01-23 12:38:19 +01:00
|
|
|
if (error) {
|
|
|
|
|
$scope.refreshBusy = false;
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// overwrite the selected domain status to be available for the UI
|
2020-02-11 21:06:34 +01:00
|
|
|
$scope.domain.mailStatus = mailStatus;
|
2018-01-23 12:38:19 +01:00
|
|
|
|
|
|
|
|
showExpectedDnsRecords();
|
|
|
|
|
|
|
|
|
|
$scope.refreshBusy = false;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-23 15:11:33 +01:00
|
|
|
Client.onReady(function () {
|
2020-02-11 21:06:34 +01:00
|
|
|
$scope.isAdminDomain = $scope.config.adminDomain === domainName;
|
2018-04-09 18:00:08 +02:00
|
|
|
|
2018-01-23 15:11:33 +01:00
|
|
|
Client.getUsers(function (error, users) {
|
|
|
|
|
if (error) return console.error('Unable to get user listing.', error);
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-04-05 21:00:33 +02:00
|
|
|
// ensure we have a display value available
|
|
|
|
|
$scope.users = users.map(function (u) {
|
|
|
|
|
u.display = u.username || u.email;
|
|
|
|
|
return u;
|
|
|
|
|
});
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-12-06 10:28:42 -08:00
|
|
|
$scope.users = users;
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.getDomain(domainName, function (error, result) {
|
|
|
|
|
if (error) return console.error('Unable to get view domain.', error);
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
$scope.domain = result;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.getDomain($scope.config.adminDomain, function (error, result) {
|
|
|
|
|
if (error) return console.error('Unable to get admin domain.', error);
|
2018-04-09 18:00:08 +02:00
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
$scope.adminDomain = result;
|
2018-04-09 18:00:08 +02:00
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
$scope.refreshDomain();
|
2018-04-09 18:00:08 +02:00
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
$scope.ready = true;
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-04-09 18:00:08 +02:00
|
|
|
});
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// setup all the dialog focus handling
|
2020-02-12 14:51:06 +01:00
|
|
|
['mailboxAddModal', 'mailboxEditModal', 'mailinglistEditModal', 'mailinglistAddModal'].forEach(function (id) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$('#' + id).on('shown.bs.modal', function () {
|
2019-09-11 14:09:53 -07:00
|
|
|
$(this).find('[autofocus]:first').focus();
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.modal-backdrop').remove();
|
|
|
|
|
}]);
|