Fix mailbox export
can also export as csv now
This commit is contained in:
@@ -441,7 +441,7 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
|
||||
}
|
||||
};
|
||||
|
||||
$scope.mailboxExport = function () {
|
||||
$scope.mailboxExport = function (type) {
|
||||
// FIXME only does first 10k mailboxes
|
||||
Client.listMailboxes($scope.domain.domain, '', 1, 10000, function (error, result) {
|
||||
if (error) {
|
||||
@@ -449,23 +449,36 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
|
||||
return console.error('Failed to list mailboxes.', error);
|
||||
}
|
||||
|
||||
var content = JSON.stringify(result.map(function (mailbox) {
|
||||
var owner = $scope.owners.find(function (o) { return o.id === mailbox.ownerId; }); // owner may not exist
|
||||
var content = '';
|
||||
|
||||
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);
|
||||
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
|
||||
|
||||
var file = new Blob([ content ], { type: 'application/json' });
|
||||
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.json';
|
||||
a.download = $scope.domain.domain.replaceAll('.','_') + '-mailboxes.' + type;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user