diff --git a/src/translation/en.json b/src/translation/en.json
index 0997f8e62..501a30af9 100644
--- a/src/translation/en.json
+++ b/src/translation/en.json
@@ -1137,7 +1137,11 @@
"aliases": "Aliases",
"usage": "Usage",
"importTooltip": "Import Mailboxes",
- "exportTooltip": "Export Mailboxes"
+ "exportTooltip": "Export Mailboxes",
+ "mailboxExport": {
+ "csv": "CSV",
+ "json": "JSON"
+ }
},
"mailinglists": {
"title": "Mailing Lists",
diff --git a/src/views/email.html b/src/views/email.html
index d8887a436..921a2bf71 100644
--- a/src/views/email.html
+++ b/src/views/email.html
@@ -408,7 +408,15 @@
diff --git a/src/views/email.js b/src/views/email.js
index b6816d257..f6149a4f4 100644
--- a/src/views/email.js
+++ b/src/views/email.js
@@ -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();
});
diff --git a/src/views/users.js b/src/views/users.js
index 42af81333..31b4858bf 100644
--- a/src/views/users.js
+++ b/src/views/users.js
@@ -258,7 +258,7 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
return;
}
- var file = new Blob([ content ], { type: 'application/json' });
+ var file = new Blob([ content ], { type: type === 'json' ? 'application/json' : 'text/csv' });
var a = document.createElement('a');
a.href = URL.createObjectURL(file);
a.download = type === 'json' ? 'users.json' : 'users.csv';