dashboard: remove mailbox import/export feature
This commit is contained in:
@@ -205,44 +205,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal import mailboxes -->
|
||||
<div class="modal fade" id="mailboxImportModal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">{{ 'email.mailboxImportDialog.title' | tr }}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div ng-show="!mailboxImport.done">
|
||||
<div ng-show="!mailboxImport.busy">
|
||||
<p ng-bind-html=" 'email.mailboxImportDialog.description' | tr:{ docsLink: 'https://cloudron.io/documentation/email/#import-mailboxes' } "></p>
|
||||
<input type="file" style="display: none;" id="mailboxImportFileInput" accept="application/json,text/csv"/>
|
||||
<button class="btn btn-primary" ng-click="mailboxImport.openFileInput()">{{ 'email.mailboxImportDialog.fileInput' | tr }}</button>
|
||||
<br/>
|
||||
<br/>
|
||||
<p class="text-danger" ng-show="mailboxImport.error.file">{{ mailboxImport.error.file }}</p>
|
||||
<p class="text-info" ng-show="mailboxImport.mailboxes.length">{{ 'email.mailboxImportDialog.mailboxesFound' | tr:{ count: mailboxImport.mailboxes.length } }}</p>
|
||||
</div>
|
||||
<div ng-show="mailboxImport.busy" class="progress progress-striped active">
|
||||
<div class="progress-bar progress-bar-success" role="progressbar" style="width: {{ mailboxImport.percent }}%"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div ng-show="mailboxImport.done">
|
||||
<p>{{ 'email.mailboxImportDialog.success' | tr:{ count: mailboxImport.success } }}</p>
|
||||
<div ng-show="mailboxImport.error.import.length">
|
||||
<p class="text-danger">{{ 'email.mailboxImportDialog.failed' | tr }}</p>
|
||||
<div ng-repeat="tmp in mailboxImport.error.import"><b>{{ tmp.mailbox.name }}@{{ tmp.mailbox.domain }}:</b> {{ tmp.error.message }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">{{ 'main.dialog.close' | tr }}</button>
|
||||
<button type="button" class="btn btn-primary" ng-click="mailboxImport.import()" ng-show="!mailboxImport.done" ng-disabled="mailboxImport.busy || !mailboxImport.mailboxes.length"><i class="fa fa-circle-notch fa-spin" ng-show="mailboxImport.busy"></i> {{ 'email.mailboxImportDialog.importAction' | tr }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal add mailinglist -->
|
||||
<div class="modal fade" id="mailinglistAddModal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
@@ -412,18 +374,6 @@
|
||||
<div class="text-left">
|
||||
<h3 style="margin-bottom: 15px;">{{ 'email.incoming.mailboxes.title' | tr }}
|
||||
<button class="btn btn-primary btn-outline pull-right" ng-click="mailboxes.add.show()" ng-disabled="!domain.mailConfig.enabled" tooltip-enable="!domain.mailConfig.enabled" uib-tooltip="{{ 'email.incoming.mailboxes.disabledTooltip' | tr }}"><i class="fa fa-inbox"></i> {{ 'email.incoming.mailboxes.addAction' | tr }}</button>
|
||||
<div class="btn-group pull-right" style="margin-left: 5px;">
|
||||
<button class="btn btn-default" ng-click="mailboxImport.show()" uib-tooltip="{{ 'email.incoming.mailboxes.importTooltip' | tr }}" tooltip-append-to-body="true"><i class="fas fa-download"></i></button>
|
||||
<div class="btn-group" role="group">
|
||||
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" uib-tooltip="{{ 'email.incoming.mailboxes.exportTooltip' | tr }}" tooltip-append-to-body="true">
|
||||
<i class="fas fa-upload"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-right">
|
||||
<li><a href="" ng-click="mailboxExport('csv')">{{ 'email.incoming.mailboxes.mailboxExport.csv' | tr }}</a></li>
|
||||
<li><a href="" ng-click="mailboxExport('json')">{{ 'email.incoming.mailboxes.mailboxExport.json' | tr }}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<input class="form-control pull-right" style="width: 200px;" placeholder="{{ 'main.searchPlaceholder' | tr }}" type="text" ng-model="mailboxes.search" ng-model-options="{ debounce: 1000 }" ng-change="mailboxes.updateFilter()" />
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
@@ -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: '',
|
||||
|
||||
Reference in New Issue
Block a user