!function(){"use strict";function e(e,t){if(e.state("mail",{url:"/Mail",views:{mailboxes:{templateUrl:"UIxMailMainFrame",controller:"MailboxesController",controllerAs:"app"}},resolve:{stateAccounts:o}}).state("mail.account",{url:"/:accountId",abstract:!0,views:{mailbox:{template:"<ui-view/>"}},resolve:{stateAccount:r}}).state("mail.account.virtualMailbox",{url:"/virtual",views:{"mailbox@mail":{templateUrl:"UIxMailFolderTemplate",controller:"MailboxController",controllerAs:"mailbox"}},resolve:{stateMailbox:n}}).state("mail.account.virtualMailbox.message",{url:"/:mailboxId/:messageId",views:{message:{templateUrl:"UIxMailViewTemplate",controller:"MessageController",controllerAs:"viewer"}},resolve:{stateMailbox:c,stateMessages:l,stateMessage:u},onEnter:d,onExit:m}).state("mail.account.inbox",{url:"/inbox",onEnter:i}).state("mail.account.mailbox",{url:"/:mailboxId",views:{"mailbox@mail":{templateUrl:"UIxMailFolderTemplate",controller:"MailboxController",controllerAs:"mailbox"}},resolve:{stateMailbox:s,stateMessages:l}}).state("mail.account.mailbox.message",{url:"/:messageId",views:{message:{templateUrl:"UIxMailViewTemplate",controller:"MessageController",controllerAs:"viewer"}},onEnter:d,onExit:m,resolve:{stateMessage:u}}),t.rules.otherwise("/Mail/0/inbox"),navigator&&navigator.registerProtocolHandler){var a=window.location.origin+window.ApplicationBaseURL+"UIxMailPopupView#!/Mail/0/INBOX/new?%s";try{navigator.registerProtocolHandler("mailto",a,"SOGo")}catch(e){}}}function o(e,t,a){var o=a.$findAll(e.mailAccounts),r=[];return angular.forEach(o,function(t,e){var a=t.$getMailboxes();0===e?r.push(a.then(function(e){return t})):r.push(t)}),t.all(r)}function r(t,e){return _.find(e,function(e){return e.id==t.accountId})}function s(e,t,a,o,r){var i,l,n=o(o(t.mailboxId));return l=function(e){var t=_.find(e,function(e){return e.path==n});return t||angular.forEach(e,function(e){!t&&e.children&&0<e.children.length&&(t=l(e.children))}),t},r.selectedFolder&&!r.$virtualMode&&(r.selectedFolder.$isLoading=!0),a.$getMailboxes().then(function(e){if(i=l(e))return i.$topIndex=0,i.selectFolder(),i;$state.go("mail.account",{accountId:s.$account.id})})}function i(t,a,o){return t.injector().getAsync("stateAccount").then(function(e){return 0<e.$mailboxes.length?t.router.stateService.target("mail.account.mailbox",{accountId:e.id,mailboxId:a(e.$mailboxes[0].path)}):(o.selectedFolder=!1,t.router.stateService.target("mail"))})}function l(e,t,a,o){return a.$virtualMode?[]:o?o.$filter().catch(function(){return e.reject("Mailbox not found")}):e.reject("Mailbox doesn't exist")}function n(e,t){return t.$virtualMode?t.selectedFolder:e.reject("No virtual mailbox defined")}function c(e,t,a,o){var r=a(o.mailboxId);return t.$virtualMode?(t.selectedFolder.resetSelectedMessage(),_.find(t.selectedFolder.$mailboxes,function(e){return e.path==r})):e.reject("No virtual mailbox defined for message")}function u(e,t,a,o,r,i){var l;if(l=_.find(r.$messages,function(e){return e.uid==parseInt(a.messageId)}))return l.$reload({useCache:!0});o.go("mail.account.mailbox",{accountId:r.$account.id,mailboxId:t(r.path)})}function d(e,t){t.selectedMessage=parseInt(e.messageId)}function m(e){delete e.selectedMessage}function t(e,t,a,o,r){e.DebugEnabled||o.defaultErrorHandler(function(){}),t.onError({to:"mail.**"},function(e){"mail"!=e.to().name&&!e.ignored()&&e.error().message.indexOf("superseded")<0&&(a.error("transition error to "+e.to().name+": "+e.error().detail),r.selectedFolder=!1,o.go("mail"))})}angular.module("SOGo.MailerUI",["ngCookies","ui.router","ck","angularFileUpload","SOGo.Common","SOGo.ContactsUI","SOGo.SchedulerUI","ngAnimate","SOGo.PreferencesUI"]).config(e).run(t),e.$inject=["$stateProvider","$urlServiceProvider"],o.$inject=["$window","$q","Account"],r.$inject=["$stateParams","stateAccounts"],s.$inject=["$q","$stateParams","stateAccount","decodeUriFilter","Mailbox"],i.$inject=["$transition$","encodeUriFilter","Mailbox"],l.$inject=["$q","$state","Mailbox","stateMailbox"],n.$inject=["$q","Mailbox"],c.$inject=["$q","Mailbox","decodeUriFilter","$stateParams"],u.$inject=["Mailbox","encodeUriFilter","$stateParams","$state","stateMailbox","stateMessages"],d.$inject=["$stateParams","stateMailbox"],m.$inject=["stateMailbox"],t.$inject=["$window","$transitions","$log","$state","Mailbox"]}();
//# sourceMappingURL=Mailer.js.map