diff --git a/src/translation/en.json b/src/translation/en.json index 0215149c4..42abb13f3 100644 --- a/src/translation/en.json +++ b/src/translation/en.json @@ -1295,12 +1295,19 @@ "saveAction": "Save", "enable": "Use Cloudron Mail to send emails", "description2": "When enabled, the app is configured to send emails via the internal mail server using this address. The internal mail server will use the {{ domain }}'s Outbound Email settings to send mail. When disabled, you can configure the email settings within the app.", - "disable": "Do not configure mail settings", - "enableDescription": "The app is configured to send mails using the address below and the {{ domain }}'s Outbound Email settings.", + "disable": "Do not configure app's mail delivery settings", + "enableDescription": "The app is configured to send mails using the address below and {{ domain }}'s Outbound Email settings.", "disableDescription": "The app's mail delivery settings is left alone. You can configure it inside the app." }, "csp": { "title": "Content Security Policy" + }, + "inbox": { + "disable": "Do not configure inbox", + "disableDescription": "The app's incoming mail settings is left alone. You can configure it inside the app. Select this if the domain's email is not hosted on Cloudron.", + "title": "Incoming mail", + "enable": "Use Cloudron Mail to receive emails", + "enableDescription": "The app is configured to receive mails using the address below. Select this option if {{ domain }}'s email is hosted on this server." } }, "security": { diff --git a/src/views/app.html b/src/views/app.html index 7540c4fb8..91660c896 100644 --- a/src/views/app.html +++ b/src/views/app.html @@ -949,7 +949,7 @@
-
+
@@ -962,10 +962,10 @@

-
+
-
{{ email.error.mailboxName }}
+
{{ email.error.mailboxName }}
@@ -1000,10 +1000,72 @@
-
+

- +
+
+ +
+ +
+
+ + +
+ +
+ +
+

+ + +
+
+
{{ email.error.inboxName }}
+ +
+ + +
+ + +
+
+
+
+
+ + +
+ +
+ +
+ +
+

{{ 'app.email.inbox.disableDescription' | tr }}

+
+
+
+
+
+
+
diff --git a/src/views/app.js b/src/views/app.js index 3102f89dc..71dcffcc6 100644 --- a/src/views/app.js +++ b/src/views/app.js @@ -804,31 +804,55 @@ angular.module('Application').controller('AppController', ['$scope', '$location' $scope.email = { busy: false, - error: {}, enableMailbox: true, mailboxName: '', - mailboxDomain: '', + mailboxDomain: null, currentMailboxName: '', currentMailboxDomainName: '', + mailboxError: {}, + + enableInbox: true, + inboxName: '', + inboxDomain: null, + currentInboxName: '', + currentInboxDomainName: '', + inboxError: {}, show: function () { var app = $scope.app; $scope.emailForm.$setPristine(); - $scope.email.error = {}; + $scope.email.mailboxError = {}; $scope.email.enableMailbox = app.enableMailbox ? '1' : '0'; $scope.email.mailboxName = app.mailboxName || ''; - $scope.email.mailboxDomain = $scope.domains.filter(function (d) { return d.domain === app.mailboxDomain; })[0]; + $scope.email.mailboxDomain = $scope.domains.filter(function (d) { return d.domain === (app.mailboxDomain || app.domain); })[0]; $scope.email.currentMailboxName = app.mailboxName || ''; - $scope.email.currentMailboxDomainName = $scope.email.mailboxDomain.domain; + $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 : ''; }, - submit: function () { + submitMailbox: function () { $scope.email.error = {}; $scope.email.busy = true; - Client.configureApp($scope.app.id, 'mailbox', { enable: $scope.email.enableMailbox === '1', mailboxName: $scope.email.mailboxName || null, mailboxDomain: $scope.email.mailboxDomain.domain }, function (error) { + var data = { + enable: $scope.email.enableMailbox === '1' + }; + + if (data.enable) { + data.mailboxName = $scope.email.mailboxName || null; + data.mailboxDomain = $scope.email.mailboxDomain.domain; + } + + Client.configureApp($scope.app.id, 'mailbox', data, function (error) { if (error && error.statusCode === 400) { $scope.email.busy = false; $scope.email.error.mailboxName = error.message; @@ -845,9 +869,48 @@ angular.module('Application').controller('AppController', ['$scope', '$location' // when the mailboxName is 'reset', this will fill it up with the default again $scope.email.enableMailbox = $scope.app.enableMailbox ? '1' : '0'; $scope.email.mailboxName = $scope.app.mailboxName || ''; - $scope.email.mailboxDomain = $scope.domains.filter(function (d) { return d.domain === $scope.app.mailboxDomain; })[0]; + $scope.email.mailboxDomain = $scope.domains.filter(function (d) { return d.domain === ($scope.app.mailboxDomain || $scope.app.domain); })[0]; $scope.email.currentMailboxName = $scope.app.mailboxName || ''; - $scope.email.currentMailboxDomainName = $scope.email.mailboxDomain.domain; + $scope.email.currentMailboxDomainName = $scope.email.mailboxDomain ? $scope.email.mailboxDomain.domain : ''; + + $timeout(function () { $scope.email.busy = false; }, 1000); + }); + }); + }, + + submitInbox: function () { + $scope.email.error = {}; + $scope.email.busy = true; + + var data = { + enable: $scope.email.enableInbox === '1' + }; + + if (data.enable) { + data.inboxName = $scope.email.inboxName; + data.inboxDomain = $scope.email.inboxDomain.domain; + } + + Client.configureApp($scope.app.id, 'inbox', data, function (error) { + if (error && error.statusCode === 400) { + $scope.email.busy = 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 : ''; $timeout(function () { $scope.email.busy = false; }, 1000); });