diff --git a/UI/WebServerResources/js/Mailer/Account.service.js b/UI/WebServerResources/js/Mailer/Account.service.js index 03b80e4fb..da8049440 100644 --- a/UI/WebServerResources/js/Mailer/Account.service.js +++ b/UI/WebServerResources/js/Mailer/Account.service.js @@ -8,7 +8,8 @@ * @constructor * @param {object} futureAccountData */ - function Account(futureAccountData) { + function Account(futureAccountData) { + var _this = this; // Data is immediately available if (typeof futureAccountData.then !== 'function') { angular.extend(this, futureAccountData); @@ -24,7 +25,9 @@ identity.textSignature = _.map(element.contents(), 'textContent').join(' ').trim(); } }); - Account.$log.debug('Account: ' + JSON.stringify(futureAccountData, undefined, 2)); + _.forEach(this.$mailboxes, function(mailboxData, i, mailboxes) { + mailboxes[i] = new Account.$Mailbox(_this, mailboxData); + }); } else { // The promise will be unwrapped first @@ -339,7 +342,7 @@ * @function $getMailboxByPath * @memberof Account.prototype * @desc Recursively find a mailbox using its path - * @returns a promise of the HTTP operation + * @returns the Mailbox instance or null if not found */ Account.prototype.$getMailboxByPath = function(path) { var mailbox = null, @@ -551,8 +554,8 @@ * @desc Return a sanitized object used to send to the server. * @return an object literal copy of the Account instance */ - Account.prototype.$omit = function () { - var account = {}, identities = [], defaultIdentity = false; + Account.prototype.$omit = function (deep) { + var account = {}, identities = [], mailboxes = [], defaultIdentity = false; angular.forEach(this, function(value, key) { if (key != 'constructor' && key !='identities' && key[0] != '$') { @@ -560,6 +563,13 @@ } }); + if (deep) { + _.forEach(this.$mailboxes, function(mailbox) { + mailboxes.push(mailbox.$omit()); + }); + account.$mailboxes = mailboxes; + } + _.forEach(this.identities, function (identity) { if (!identity.isReadOnly) identities.push(_.pick(identity, ['email', 'fullName', 'replyTo', 'signature', 'isDefault'])); diff --git a/UI/WebServerResources/js/Mailer/Mailer.popup.js b/UI/WebServerResources/js/Mailer/Mailer.popup.js index 528bee49a..23f80b042 100644 --- a/UI/WebServerResources/js/Mailer/Mailer.popup.js +++ b/UI/WebServerResources/js/Mailer/Mailer.popup.js @@ -130,13 +130,24 @@ /** * @ngInject */ - stateAccount.$inject = ['$q', '$stateParams', 'stateAccounts']; - function stateAccount($q, $stateParams, stateAccounts) { - var account; + stateAccount.$inject = ['$q', '$window', '$stateParams', 'Account', 'stateAccounts']; + function stateAccount($q, $window, $stateParams, Account, stateAccounts) { + var account = null; - account = _.find(stateAccounts, function(account) { - return account.id == $stateParams.accountId; - }); + if ($window.opener) { + if ('$mailboxController' in $window.opener && + 'account' in $window.opener.$mailboxController && + $window.opener.$mailboxController.account.id == $stateParams.accountId) { + // The message account is selected in the parent window + account = new Account($window.opener.$mailboxController.account.$omit(true)); + } + } + + if (!account) { + account = _.find(stateAccounts, function(account) { + return account.id == $stateParams.accountId; + }); + } if (account) { return $q.when(account); } @@ -163,7 +174,8 @@ $window.opener.$mailboxController.account.id == stateAccount.id && $window.opener.$mailboxController.selectedFolder.path == mailboxId) { // The message mailbox is opened in the parent window - mailbox = $window.opener.$mailboxController.selectedFolder; + mailbox = new Mailbox(stateAccount, + $window.opener.$mailboxController.selectedFolder.$omit()); } }