!function(){"use strict";function configure($stateProvider,$urlRouterProvider){$stateProvider.state("mail",{url:"/Mail",views:{mailboxes:{templateUrl:"UIxMailMainFrame",controller:"MailboxesController",controllerAs:"app"}},resolve:{stateAccounts:stateAccounts}}).state("mail.account",{url:"/:accountId","abstract":!0,views:{mailbox:{template:""}},resolve:{stateAccount:stateAccount}}).state("mail.account.mailbox",{url:"/:mailboxId",views:{"mailbox@mail":{templateUrl:"UIxMailFolderTemplate",controller:"MailboxController",controllerAs:"mailbox"}},resolve:{stateMailbox:stateMailbox,stateMessages:stateMessages}}).state("mail.account.mailbox.message",{url:"/:messageId",views:{message:{templateUrl:"UIxMailViewTemplate",controller:"MessageController",controllerAs:"viewer"}},resolve:{stateMessage:stateMessage}}),$urlRouterProvider.otherwise("/Mail")}function stateAccounts($q,Account){var accounts=Account.$findAll(mailAccounts),promises=[];return angular.forEach(accounts,function(account,i){var mailboxes=account.$getMailboxes();promises.push(mailboxes.then(function(objects){return account}))}),$q.all(promises)}function stateAccount($stateParams,stateAccounts){return _.find(stateAccounts,function(account){return account.id==$stateParams.accountId})}function stateMailbox($stateParams,stateAccount,decodeUriFilter){var _find,mailboxId=decodeUriFilter($stateParams.mailboxId);return(_find=function(mailboxes){var mailbox=_.find(mailboxes,function(o){return o.path==mailboxId});return mailbox||angular.forEach(mailboxes,function(o){!mailbox&&o.children&&o.children.length>0&&(mailbox=_find(o.children))}),mailbox})(stateAccount.$mailboxes)}function stateMessages(stateMailbox){return stateMailbox.$filter()}function stateMessage(encodeUriFilter,$stateParams,$state,stateMailbox,stateMessages){var message=_.find(stateMailbox.$messages,function(messageObject){return messageObject.uid==$stateParams.messageId});return message?(stateMailbox.selectedMessage=$stateParams.messageId,message.$reload()):void $state.go("mail.account.mailbox",{accountId:stateMailbox.$account.id,mailboxId:encodeUriFilter(stateMailbox.path)})}function runBlock($rootScope){$rootScope.$on("$routeChangeError",function(event,current,previous,rejection){console.error(event,current,previous,rejection)})}angular.module("SOGo.MailerUI",["ngSanitize","ui.router","ck","angularFileUpload","SOGo.Common","SOGo.ContactsUI","ngAnimate","SOGo.PreferencesUI"]).config(configure).run(runBlock),configure.$inject=["$stateProvider","$urlRouterProvider"],stateAccounts.$inject=["$q","Account"],stateAccount.$inject=["$stateParams","stateAccounts"],stateMailbox.$inject=["$stateParams","stateAccount","decodeUriFilter"],stateMessages.$inject=["stateMailbox"],stateMessage.$inject=["encodeUriFilter","$stateParams","$state","stateMailbox","stateMessages"],runBlock.$inject=["$rootScope"]}(),function(){"use strict";function MailboxController($state,$timeout,$mdDialog,stateAccounts,stateAccount,stateMailbox,encodeUriFilter,focus,Dialog,Account,Mailbox){function selectMessage(message){$state.go("mail.account.mailbox.message",{accountId:stateAccount.id,mailboxId:encodeUriFilter(stateMailbox.path),messageId:message.uid})}function unselectMessages(){_.each(vm.selectedFolder.$messages,function(message){message.selected=!1})}function confirmDeleteSelectedMessages(){Dialog.confirm(l("Warning"),l("Are you sure you want to delete the selected messages?")).then(function(){var selectedMessages=_.filter(vm.selectedFolder.$messages,function(message){return message.selected}),selectedUIDs=_.pluck(selectedMessages,"uid");vm.selectedFolder.$deleteMessages(selectedUIDs).then(function(){var unseenCount=_.filter(selectedMessages,function(message){return!message.isread});vm.selectedFolder.$messages=_.difference(vm.selectedFolder.$messages,selectedMessages),vm.selectedFolder.unseenCount=-unseenCount},function(error){Dialog.alert(l("Error"),error)})})}function copySelectedMessages(folder){var selectedMessages=_.filter(vm.selectedFolder.$messages,function(message){return message.selected}),selectedUIDs=_.pluck(selectedMessages,"uid");vm.selectedFolder.$copyMessages(selectedUIDs,"/"+folder).then(function(){},function(error){Dialog.alert(l("Error"),error)})}function saveSelectedMessages(){var selectedMessages=_.filter(vm.selectedFolder.$messages,function(message){return message.selected}),selectedUIDs=_.pluck(selectedMessages,"uid");window.location.href=ApplicationBaseURL+"/"+vm.selectedFolder.id+"/saveMessages?uid="+selectedUIDs.join(",")}function selectAll(){_.each(vm.selectedFolder.$messages,function(message){message.selected=!0})}function markSelectedMessagesAsFlagged(){var selectedMessages=_.filter(vm.selectedFolder.$messages,function(message){return message.selected}),selectedUIDs=_.pluck(selectedMessages,"uid");vm.selectedFolder.$flagMessages(selectedUIDs,"\\Flagged","add").then(function(d){_.forEach(selectedMessages,function(message){message.isflagged=!0})})}function markSelectedMessagesAsUnread(){var selectedMessages=_.filter(vm.selectedFolder.$messages,function(message){return message.selected}),selectedUIDs=_.pluck(selectedMessages,"uid");vm.selectedFolder.$flagMessages(selectedUIDs,"seen","remove").then(function(d){_.forEach(selectedMessages,function(message){message.isread=!1,vm.selectedFolder.unseenCount++})})}function sort(field){vm.selectedFolder.$filter({sort:field})}function sortedBy(field){return Mailbox.$query.sort==field}function cancelSearch(){vm.mode.search=!1,vm.selectedFolder.$filter()}function newMessage($event){var message=vm.account.$newMessage();$mdDialog.show({parent:angular.element(document.body),targetEvent:$event,clickOutsideToClose:!1,escapeToClose:!1,templateUrl:"UIxMailEditor",controller:"MessageEditorController",controllerAs:"editor",locals:{stateAccounts:vm.accounts,stateMessage:message,stateRecipients:[]}})}var vm=this;Mailbox.selectedFolder=stateMailbox,vm.service=Mailbox,vm.accounts=stateAccounts,vm.account=stateAccount,vm.selectedFolder=stateMailbox,vm.selectMessage=selectMessage,vm.unselectMessages=unselectMessages,vm.confirmDeleteSelectedMessages=confirmDeleteSelectedMessages,vm.copySelectedMessages=copySelectedMessages,vm.saveSelectedMessages=saveSelectedMessages,vm.markSelectedMessagesAsFlagged=markSelectedMessagesAsFlagged,vm.markSelectedMessagesAsUnread=markSelectedMessagesAsUnread,vm.selectAll=selectAll,vm.sort=sort,vm.sortedBy=sortedBy,vm.cancelSearch=cancelSearch,vm.newMessage=newMessage,vm.mode={search:!1}}MailboxController.$inject=["$state","$timeout","$mdDialog","stateAccounts","stateAccount","stateMailbox","encodeUriFilter","sgFocus","Dialog","Account","Mailbox"],angular.module("SOGo.MailerUI").controller("MailboxController",MailboxController)}(),function(){"use strict";function MailboxesController($state,$timeout,$mdDialog,focus,encodeUriFilter,Dialog,Settings,Account,Mailbox,User,Preferences,stateAccounts){function newFolder(parentFolder){Dialog.prompt(l("New folder"),l("Enter the new name of your folder :")).then(function(name){parentFolder.$newMailbox(parentFolder.id,name).then(function(){},function(data,status){Dialog.alert(l('An error occured while creating the mailbox "%{0}".',name),l(data.error))})})}function delegate(account){function MailboxDelegationController($scope,$mdDialog,User,account){function userFilter($query){return User.$filter($query,account.delegates)}function closeModal(){$mdDialog.hide()}function removeUser(user){account.$removeDelegate(user.uid)["catch"](function(data,status){Dialog.alert(l("Warning"),l("An error occured please try again."))})}function addUser(data){data&&account.$addDelegate(data).then(function(){vm.userToAdd="",vm.searchText=""},function(error){Dialog.alert(l("Warning"),error)})}var vm=this;vm.users=account.delegates,vm.account=account,vm.userToAdd="",vm.searchText="",vm.userFilter=userFilter,vm.closeModal=closeModal,vm.removeUser=removeUser,vm.addUser=addUser}$mdDialog.show({templateUrl:account.id+"/delegation",controller:MailboxDelegationController,controllerAs:"delegate",clickOutsideToClose:!0,escapeToClose:!0,locals:{User:User,account:account}}),MailboxDelegationController.$inject=["$scope","$mdDialog","User","account"]}function editFolder(folder){vm.editMode=folder.path,focus("mailboxName_"+folder.path)}function revertEditing(folder){folder.$reset(),vm.editMode=!1}function selectFolder(account,folder){vm.editMode!=folder.path&&(vm.editMode=!1,$state.go("mail.account.mailbox",{accountId:account.id,mailboxId:encodeUriFilter(folder.path)}))}function saveFolder(folder){folder.$rename()}function compactFolder(folder){folder.$compact().then(function(){},function(error){Dialog.alert(l("Warning"),error)})}function emptyTrashFolder(folder){folder.$emptyTrash().then(function(){},function(error){Dialog.alert(l("Warning"),error)})}function exportMails(folder){window.location.href=ApplicationBaseURL+"/"+folder.id+"/exportFolder"}function confirmDelete(folder){Dialog.confirm(l("Confirmation"),l("Do you really want to move this folder into the trash ?")).then(function(){folder.$delete().then(function(){$state.go("mail")},function(data,status){Dialog.alert(l('An error occured while deleting the mailbox "%{0}".',folder.name),l(data.error))})})}function markFolderRead(folder){folder.$markAsRead()}function share(folder){folder.$acl.$users().then(function(){$mdDialog.show({templateUrl:folder.id+"/UIxAclEditor",controller:"AclController",controllerAs:"acl",clickOutsideToClose:!0,escapeToClose:!0,locals:{usersWithACL:folder.$acl.users,User:User,folder:folder}})})}function metadataForFolder(folder){return"inbox"==folder.type?{name:folder.name,icon:"inbox"}:"draft"==folder.type?{name:l("DraftsFolderName"),icon:"drafts"}:"sent"==folder.type?{name:l("SentFolderName"),icon:"send"}:"trash"==folder.type?{name:l("TrashFolderName"),icon:"delete"}:"additional"==folder.type?{name:folder.name,icon:"folder_shared"}:{name:folder.name,icon:"folder"}}function setFolderAs(folder,type){folder.$setFolderAs(type).then(function(){folder.$account.$getMailboxes({reload:!0})},function(error){Dialog.alert(l("Warning"),error)})}function refreshUnseenCount(){var unseenCountFolders=window.unseenCountFolders;_.forEach(vm.accounts,function(account){_.includes(unseenCountFolders,account.id+"/folderINBOX")||unseenCountFolders.push(account.id+"/folderINBOX"),_.forEach(account.$$flattenMailboxes,function(mailbox){angular.isDefined(mailbox.unseenCount)&&!_.includes(unseenCountFolders,mailbox.id)&&unseenCountFolders.push(mailbox.id)})}),Account.$$resource.post("","unseenCount",{mailboxes:unseenCountFolders}).then(function(data){_.forEach(vm.accounts,function(account){_.forEach(account.$$flattenMailboxes,function(mailbox){data[mailbox.id]&&(mailbox.unseenCount=data[mailbox.id])})})}),Preferences.ready().then(function(){var refreshViewCheck=Preferences.defaults.SOGoRefreshViewCheck;refreshViewCheck&&"manually"!=refreshViewCheck&&$timeout(vm.refreshUnseenCount,1e3*refreshViewCheck.timeInterval())})}var account,mailbox,vm=this;vm.service=Mailbox,vm.accounts=stateAccounts,vm.newFolder=newFolder,vm.delegate=delegate,vm.editFolder=editFolder,vm.revertEditing=revertEditing,vm.selectFolder=selectFolder,vm.saveFolder=saveFolder,vm.compactFolder=compactFolder,vm.emptyTrashFolder=emptyTrashFolder,vm.exportMails=exportMails,vm.confirmDelete=confirmDelete,vm.markFolderRead=markFolderRead,vm.share=share,vm.metadataForFolder=metadataForFolder,vm.setFolderAs=setFolderAs,vm.refreshUnseenCount=refreshUnseenCount,"mail"==$state.current.name&&vm.accounts.length>0&&vm.accounts[0].$mailboxes.length>0&&(account=vm.accounts[0],mailbox=account.$mailboxes[0],$state.go("mail.account.mailbox",{accountId:account.id,mailboxId:encodeUriFilter(mailbox.path)})),vm.refreshUnseenCount()}MailboxesController.$inject=["$state","$timeout","$mdDialog","sgFocus","encodeUriFilter","Dialog","sgSettings","Account","Mailbox","User","Preferences","stateAccounts"],angular.module("SOGo.MailerUI").controller("MailboxesController",MailboxesController)}(),function(){"use strict";function MessageController($scope,$state,$mdDialog,stateAccounts,stateAccount,stateMailbox,stateMessage,encodeUriFilter,focus,Dialog,Account,Mailbox,Message){function doDelete(){stateMailbox.$deleteMessages([stateMessage.uid]).then(function(){var index=_.findIndex(stateMailbox.$messages,function(o){return o.uid==stateMessage.uid});-1!=index&&stateMailbox.$messages.splice(index,1),vm.message=null,$state.go("mail.account.mailbox",{accountId:stateAccount.id,mailboxId:encodeUriFilter(stateMailbox.path)})})}function showMailEditor($event,message,recipients){angular.isDefined(recipients)||(recipients=[]),$mdDialog.show({parent:angular.element(document.body),targetEvent:$event,clickOutsideToClose:!1,escapeToClose:!1,templateUrl:"UIxMailEditor",controller:"MessageEditorController",controllerAs:"editor",locals:{stateAccounts:vm.accounts,stateMessage:message,stateRecipients:recipients}})}function reply($event){var message=vm.message.$reply();showMailEditor($event,message)}function replyAll($event){var message=vm.message.$replyAll();showMailEditor($event,message)}function forward($event){var message=vm.message.$forward();showMailEditor($event,message)}function edit($event){vm.message.$editableContent().then(function(){showMailEditor($event,vm.message)})}function newMessage($event,recipient){var message=vm.account.$newMessage();showMailEditor($event,message,[recipient])}function viewRawSource($event){Message.$$resource.post(vm.message.id,"viewsource").then(function(data){function MessageRawSourceDialogController(scope,$mdDialog){scope.close=function(){$mdDialog.hide()}}$mdDialog.show({parent:angular.element(document.body),targetEvent:$event,clickOutsideToClose:!0,escapeToClose:!0,template:[''," "," ",data,"
"," ",' ',' '+l("Close")+"","
",""].join(""),controller:MessageRawSourceDialogController}),MessageRawSourceDialogController.$inject=["scope","$mdDialog"]})}var vm=this;vm.accounts=stateAccounts,vm.account=stateAccount,vm.mailbox=stateMailbox,vm.message=stateMessage,vm.service=Message,vm.tags={searchText:"",selected:""},vm.doDelete=doDelete,vm.reply=reply,vm.replyAll=replyAll,vm.forward=forward,vm.edit=edit,vm.newMessage=newMessage,vm.viewRawSource=viewRawSource,$scope.$watchCollection("viewer.message.flags",function(oldTags,newTags){_.each(_.difference(newTags,oldTags),function(tag){vm.message.removeTag(tag)})})}MessageController.$inject=["$scope","$state","$mdDialog","stateAccounts","stateAccount","stateMailbox","stateMessage","encodeUriFilter","sgFocus","Dialog","Account","Mailbox","Message"],angular.module("SOGo.MailerUI").controller("MessageController",MessageController)}(),function(){"use strict";function MessageEditorController($stateParams,$state,$q,$mdDialog,FileUploader,stateAccounts,stateMessage,stateRecipients,$timeout,encodeUriFilter,focus,Dialog,Account,Mailbox,AddressBook,Preferences){function cancel(){vm.autosave&&$timeout.cancel(vm.autosave),$mdDialog.cancel()}function send(){vm.autosave&&$timeout.cancel(vm.autosave),vm.message.$send().then(function(data){$mdDialog.hide()},function(data){Dialog.alert(l(data.status),l(data.message))})}function contactFilter($query){var deferred=$q.defer();return AddressBook.$filterAll($query).then(function(results){deferred.resolve(_.invoke(results,"$shortFormat",$query))}),deferred.promise}function autosaveDrafts(){vm.message.$save(),Preferences.defaults.SOGoMailAutoSave&&(vm.autosave=$timeout(vm.autosaveDrafts,1e3*Preferences.defaults.SOGoMailAutoSave*60))}var vm=this;vm.autocomplete={to:{},cc:{},bcc:{}},vm.autosave=null,vm.autosaveDrafts=autosaveDrafts,vm.hideCc=!0,vm.hideBcc=!0,vm.cancel=cancel,vm.send=send,vm.contactFilter=contactFilter,vm.identities=_.pluck(_.flatten(_.pluck(stateAccounts,"identities")),"full"),vm.uploader=new FileUploader({url:stateMessage.$absolutePath({asDraft:!0})+"/save",autoUpload:!0,alias:"attachments",onProgressItem:function(item,progress){console.debug(item),console.debug(progress)},onSuccessItem:function(item,response,status,headers){stateMessage.$setUID(response.uid),stateMessage.$reload(),console.debug(item),console.debug("success = "+JSON.stringify(response,void 0,2))},onCancelItem:function(item,response,status,headers){console.debug(item),console.debug("cancel = "+JSON.stringify(response,void 0,2)),stateMessage.$deleteAttachment(item.file.name),this.removeFromQueue(item)},onErrorItem:function(item,response,status,headers){console.debug(item),console.debug("error = "+JSON.stringify(response,void 0,2))}}),"reply"==$stateParams.actionName?stateMessage.$reply().then(function(msgObject){vm.message=msgObject,vm.hideCc=!msgObject.editable.cc||0===msgObject.editable.cc.length,vm.hideBcc=!msgObject.editable.bcc||0===msgObject.editable.bcc.length}):"replyall"==$stateParams.actionName?stateMessage.$replyAll().then(function(msgObject){vm.message=msgObject,vm.hideCc=!msgObject.editable.cc||0===msgObject.editable.cc.length,vm.hideBcc=!msgObject.editable.bcc||0===msgObject.editable.bcc.length}):"forward"==$stateParams.actionName?stateMessage.$forward().then(function(msgObject){vm.message=msgObject}):angular.isDefined(stateMessage)&&(vm.message=stateMessage),angular.isDefined(stateRecipients)&&(vm.message.editable.to=_.union(vm.message.editable.to,_.pluck(stateRecipients,"full"))),Preferences.ready().then(function(){Preferences.defaults.SOGoMailAutoSave&&(vm.autosave=$timeout(vm.autosaveDrafts,1e3*Preferences.defaults.SOGoMailAutoSave*60)),vm.localeCode=Preferences.defaults.LocaleCode})}MessageEditorController.$inject=["$stateParams","$state","$q","$mdDialog","FileUploader","stateAccounts","stateMessage","stateRecipients","$timeout","encodeUriFilter","sgFocus","Dialog","Account","Mailbox","AddressBook","Preferences"],angular.module("SOGo.MailerUI").controller("MessageEditorController",MessageEditorController)}(),function(){"use strict";function sgImip(){function link(scope,iElement,attrs,ctrl){ctrl.pathToAttachment=attrs.sgImipPath}return{restrict:"A",link:link,controller:"sgImipController"}}function sgImipController($scope,User){var vm=this;$scope.delegateInvitation=!1,$scope.delegatedTo="",$scope.searchText="",$scope.userFilter=function($query){return User.$filter($query)},$scope.iCalendarAction=function(action){var data;"delegate"==action&&(data={receiveUpdates:!1,delegatedTo:$scope.delegatedTo.c_email}),$scope.viewer.message.$imipAction(vm.pathToAttachment,action,data)}}sgImipController.$inject=["$scope","User"],angular.module("SOGo.MailerUI").controller("sgImipController",sgImipController).directive("sgImip",sgImip)}();
//# sourceMappingURL=Mailer.js.map