@@ -412,18 +374,6 @@
diff --git a/dashboard/src/views/email.js b/dashboard/src/views/email.js
index 5406c0536..9287c0bde 100644
--- a/dashboard/src/views/email.js
+++ b/dashboard/src/views/email.js
@@ -377,172 +377,6 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
}
};
- $scope.mailboxImport = {
- busy: false,
- done: false,
- error: null,
- percent: 0,
- success: 0,
- mailboxes: [],
-
- reset: function () {
- $scope.mailboxImport.busy = false;
- $scope.mailboxImport.error = null;
- $scope.mailboxImport.mailboxes = [];
- $scope.mailboxImport.percent = 0;
- $scope.mailboxImport.success = 0;
- $scope.mailboxImport.done = false;
- },
-
- handleFileChanged: function () {
- $scope.mailboxImport.reset();
-
- var fileInput = document.getElementById('mailboxImportFileInput');
- if (!fileInput.files || !fileInput.files[0]) return;
-
- var file = fileInput.files[0];
- if (file.type !== 'application/json' && file.type !== 'text/csv') return console.log('Unsupported file type.');
-
- const reader = new FileReader();
- reader.addEventListener('load', function () {
- $scope.$apply(function () {
- $scope.mailboxImport.mailboxes = [];
- var mailboxes = [];
-
- if (file.type === 'text/csv') {
- var lines = reader.result.split('\n');
- if (lines.length === 0) return $scope.mailboxImport.error = { file: 'Imported file has no lines' };
-
- for (var i = 0; i < lines.length; i++) {
- var line = lines[i].trim();
- if (!line) continue;
- var items = line.split(',');
- if (items.length !== 4) {
- $scope.mailboxImport.error = { file: 'Line ' + (i+1) + ' has wrong column count. Expecting 4' };
- return;
- }
- mailboxes.push({
- name: items[0].trim(),
- domain: items[1].trim(),
- owner: items[2].trim(),
- ownerType: items[3].trim(),
- });
- }
- } else {
- try {
- mailboxes = JSON.parse(reader.result).map(function (mailbox) {
- return {
- name: mailbox.name,
- domain: mailbox.domain,
- owner: mailbox.owner,
- ownerType: mailbox.ownerType
- };
- });
- } catch (e) {
- console.error('Failed to parse mailboxes.', e);
- $scope.mailboxImport.error = { file: 'Imported file is not valid JSON' };
- }
- }
-
- $scope.mailboxImport.mailboxes = mailboxes;
- });
- }, false);
- reader.readAsText(file);
- },
-
- show: function () {
- $scope.mailboxImport.reset();
-
- // named so no duplactes
- document.getElementById('mailboxImportFileInput').addEventListener('change', $scope.mailboxImport.handleFileChanged);
-
- $('#mailboxImportModal').modal('show');
- },
-
- openFileInput: function () {
- $('#mailboxImportFileInput').click();
- },
-
- import: function () {
- $scope.mailboxImport.percent = 0;
- $scope.mailboxImport.success = 0;
- $scope.mailboxImport.done = false;
- $scope.mailboxImport.error = { import: [] };
- $scope.mailboxImport.busy = true;
-
- var processed = 0;
-
- async.eachSeries($scope.mailboxImport.mailboxes, function (mailbox, callback) {
- var owner = $scope.owners.find(function (o) { return o.display === mailbox.owner && o.type === mailbox.ownerType; }); // owner may not exist
- if (!owner) {
- $scope.mailboxImport.error.import.push({ error: new Error('Could not detect owner'), mailbox: mailbox });
- ++processed;
- $scope.mailboxImport.percent = 100 * processed / $scope.mailboxImport.mailboxes.length;
- return callback();
- }
-
- Client.addMailbox(mailbox.domain, mailbox.name, owner.id, mailbox.ownerType, function (error) {
- if (error) $scope.mailboxImport.error.import.push({ error: error, mailbox: mailbox });
- else ++$scope.mailboxImport.success;
-
- ++processed;
- $scope.mailboxImport.percent = 100 * processed / $scope.mailboxImport.mailboxes.length;
-
- callback();
- });
- }, function (error) {
- if (error) return console.error(error);
-
- $scope.mailboxImport.busy = false;
- $scope.mailboxImport.done = true;
- if ($scope.mailboxImport.success) $scope.mailboxes.refresh();
- });
- }
- };
-
- $scope.mailboxExport = function (type) {
- // FIXME only does first 10k mailboxes
- Client.listMailboxes($scope.domain.domain, '', 1, 10000, function (error, result) {
- if (error) {
- Client.error('Failed to list mailboxes. Full error in the webinspector.');
- return console.error('Failed to list mailboxes.', error);
- }
-
- var content = '';
-
- if (type === 'json') {
- content = JSON.stringify(result.map(function (mailbox) {
- var owner = $scope.owners.find(function (o) { return o.id === mailbox.ownerId; }); // owner may not exist
-
- return {
- name: mailbox.name,
- domain: mailbox.domain,
- owner: owner ? owner.display : '', // this meta property is set when we get the user list
- ownerType: owner ? owner.type : '',
- active: mailbox.active,
- aliases: mailbox.aliases
- };
- }), null, 2);
- } else if (type === 'csv') {
- content = result.map(function (mailbox) {
- var owner = $scope.owners.find(function (o) { return o.id === mailbox.ownerId; }); // owner may not exist
-
- var aliases = mailbox.aliases.map(function (a) { return a.name + '@' + a.domain; }).join(' ');
- return [ mailbox.name, mailbox.domain, owner ? owner.display : '', owner ? owner.type : '', aliases, mailbox.active ].join(',');
- }).join('\n');
- } else {
- return;
- }
-
- var file = new Blob([ content ], { type: type === 'json' ? 'application/json' : 'text/csv' });
- var a = document.createElement('a');
- a.href = URL.createObjectURL(file);
- a.download = $scope.domain.domain.replaceAll('.','_') + '-mailboxes.' + type;
- document.body.appendChild(a);
- a.click();
- });
- };
-
$scope.mailboxes = {
mailboxes: [],
search: '',