diff --git a/src/js/client.js b/src/js/client.js
index 9fda0c089..ff06219c6 100644
--- a/src/js/client.js
+++ b/src/js/client.js
@@ -2595,6 +2595,29 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
};
// Mailboxes
+ Client.prototype.getAllMailboxes = function (callback) {
+ var that = this;
+
+ this.getDomains(function (error, domains) {
+ if (error) return callback(error);
+
+ var mailboxes = [];
+ async.eachLimit(domains, 5, function (domain, callback) {
+ that.listMailboxes(domain.domain, '', 1, 1000, function (error, result) {
+ if (error) return callback(error);
+
+ mailboxes = mailboxes.concat(result);
+
+ callback();
+ });
+ }, function (error) {
+ if (error) return callback(error);
+
+ callback(null, mailboxes);
+ });
+ });
+ };
+
Client.prototype.getMailboxCount = function (domain, callback) {
get('/api/v1/mail/' + domain + '/mailbox_count', null, function (error, data, status) {
if (error) return callback(error);
diff --git a/src/views/app.html b/src/views/app.html
index b2a7ec275..32e9fe245 100644
--- a/src/views/app.html
+++ b/src/views/app.html
@@ -1019,43 +1019,22 @@
@@ -1067,7 +1046,7 @@
-
diff --git a/src/views/app.js b/src/views/app.js
index 6e5c1a13b..58d36a6d6 100644
--- a/src/views/app.js
+++ b/src/views/app.js
@@ -804,6 +804,10 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
}
};
+ function findInbox(inboxes, app) {
+ return inboxes.find(function (i) { return i.name === app.inboxName && i.domain === (app.inboxDomain || app.domain); });
+ }
+
$scope.email = {
enableMailbox: true,
mailboxName: '',
@@ -813,13 +817,12 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
mailboxError: {},
mailboxBusy: false,
- enableInbox: true,
- inboxName: '',
- inboxDomain: null,
- currentInboxName: '',
- currentInboxDomainName: '',
inboxError: {},
inboxBusy: false,
+ enableInbox: true,
+ inboxes: [],
+ currentInbox: null,
+ inbox: null,
show: function () {
var app = $scope.app;
@@ -832,13 +835,16 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
$scope.email.currentMailboxName = app.mailboxName || '';
$scope.email.currentMailboxDomainName = $scope.email.mailboxDomain ? $scope.email.mailboxDomain.domain : '';
- $scope.inboxForm.$setPristine();
$scope.email.inboxError = {};
- $scope.email.enableInbox = app.enableInbox ? '1' : '0';
- $scope.email.inboxName = app.inboxName || '';
- $scope.email.inboxDomain = $scope.domains.filter(function (d) { return d.domain === (app.inboxDomain || app.domain); })[0];
- $scope.email.currentInboxName = app.inboxName || '';
- $scope.email.currentInboxDomainName = $scope.email.inboxDomain ? $scope.email.inboxDomain.domain : '';
+ $scope.email.enableInbox = app.enableInbox ? true : false;
+
+ Client.getAllMailboxes(function (error, mailboxes) {
+ if (error) console.error('Failed to list mailboxes.', error);
+
+ $scope.email.inboxes = mailboxes.map(function (m) { return { display: m.name + '@' + m.domain, name: m.name, domain: m.domain }; });
+ $scope.email.currentInbox = findInbox($scope.email.inboxes, app);
+ $scope.email.inbox = findInbox($scope.email.inboxes, app);
+ });
},
submitMailbox: function () {
@@ -885,34 +891,29 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
$scope.email.inboxBusy = true;
var data = {
- enable: $scope.email.enableInbox === '1'
+ enable: $scope.email.enableInbox
};
if (data.enable) {
- data.inboxName = $scope.email.inboxName;
- data.inboxDomain = $scope.email.inboxDomain.domain;
+ data.inboxName = $scope.email.inbox.name;
+ data.inboxDomain = $scope.email.inbox.domain;
}
Client.configureApp($scope.app.id, 'inbox', data, function (error) {
if (error && error.statusCode === 400) {
$scope.email.inboxBusy = false;
$scope.email.error.inboxName = error.message;
- $scope.inboxForm.$setPristine();
return;
}
if (error) return Client.error(error);
- $scope.inboxForm.$setPristine();
-
refreshApp($scope.app.id, function (error) {
if (error) return Client.error(error);
// when the mailboxName is 'reset', this will fill it up with the default again
- $scope.email.enableInbox = $scope.app.enableInbox ? '1' : '0';
- $scope.email.inboxName = $scope.app.inboxName || '';
- $scope.email.inboxDomain = $scope.domains.filter(function (d) { return d.domain === ($scope.app.inboxDomain || $scope.app.domain); })[0];
- $scope.email.currentInboxName = $scope.app.inboxName || '';
- $scope.email.currentInboxDomainName = $scope.email.inboxDomain ? $scope.email.inboxDomain.domain : '';
+ $scope.email.enableInbox = $scope.app.enableInbox ? true : false;
+ $scope.email.currentInbox = findInbox($scope.email.inboxes, $scope.app);
+ $scope.email.inbox = findInbox($scope.email.inboxes, $scope.app);
$timeout(function () { $scope.email.inboxBusy = false; }, 1000);
});