!function(){"use strict";function c(e){"function"!=typeof e.then&&(angular.extend(this,e),_.forEach(this.identities,function(e){e.fullName?e.full=e.fullName+" <"+e.email+">":e.full="<"+e.email+">"}),c.$log.debug("Account: "+JSON.stringify(e,void 0,2)))}c.$factory=["$q","$timeout","$log","sgSettings","Resource","Preferences","Mailbox","Message",function(e,t,n,s,i,o,a,r){return angular.extend(c,{$q:e,$timeout:t,$log:n,$$resource:new i(s.activeUser("folderURL")+"Mail",s.activeUser()),$Preferences:o,$Mailbox:a,$Message:r}),c}];try{angular.module("SOGo.MailerUI")}catch(e){angular.module("SOGo.MailerUI",["SOGo.Common"])}angular.module("SOGo.MailerUI").factory("Account",c.$factory),c.$findAll=function(e){return e?c.$unwrapCollection(e):c.$accounts?c.$q.when(c.$accounts):c.$$resource.fetch("","mailAccounts").then(function(e){return c.$unwrapCollection(e)})},c.$unwrapCollection=function(e){var n=[];return angular.forEach(e,function(e,t){e.id=t,n[t]=new c(e)}),c.$accounts=n},c.prototype.getLength=function(){return this.$expanded?this.$flattenMailboxes().length:0},c.prototype.getItemAtIndex=function(e){var t;return t=this.$flattenMailboxes(),0<=e&&ee.uids.length-1)&&(l.$topIndex=0),l.init(e),l.uids&&(c.$log.debug("unwrapping "+l.uids.length+" messages"),s=_.invokeMap(l.headers[0],"toLowerCase"),l.headers.splice(0,1),l.threaded&&(a=l.uids[0],l.uids.splice(0,1)),_.reduce(l.uids,function(e,t,n){var s,i;if(l.threaded){if(1===(s=_.zipObject(a,t)).first){for(var o=1;l.uids[n+o]&&0<=l.uids[n+o][1]&&1!==l.uids[n+o][2];)o++;s.count=o,s.collapsed=!1,0<=l.$collapsedThreads.indexOf(s.uid.toString())&&(s.collapsed=!0)}}else s={uid:t.toString()};return l.uidsMap[s.uid]=n,(i=new c.$Message(l.$account.id,l,s,!0)).selected=-1",e.name.length<10?e.shortname=e.name:e.name.split(" ").length&&(e.shortname=_.first(_.last(e.name.split(/, */)).split(/ +/)).replace("'",""))):e.email&&(e.full="<"+e.email+">",e.shortname=e.email.split("@")[0]),e.image=r.$avatar(e.email,32),0<=_.indexOf(n,e.email)&&(e.shortname=l("me"))})})},r.prototype.$shortRecipients=function(n){var t=this,s=[],i=0,o=0;return _.forEach(["to","cc","bcc"],function(e){o+=t[e]?t[e].length:0,_.forEach(t[e],function(e,t){i"}),s={to:e},_.forEach(["subject","body"],function(e){var t=new RegExp(e+"=([^&]+)");e="body"==e?"text":e,(i=t.exec(n))&&(s[e]=decodeURIComponent(i[1]))}),_.forEach(["cc","bcc"],function(e){var t=new RegExp(e+"=([^&]+)");(i=t.exec(n))&&(s[e]=_.map(decodeURIComponent(i[1]).split(","),function(e){return"<"+e.trim()+">"}))}),angular.extend(this.editable,s))},r.prototype.$reply=function(){return this.$newDraft("reply")},r.prototype.$replyAll=function(){return this.$newDraft("replyall")},r.prototype.$forward=function(){return this.$newDraft("forward")},r.prototype.$newDraft=function(s){var i=this;return r.$$resource.fetch(this.$absolutePath(),s).then(function(e){var t,n;return r.$log.debug("New "+s+": "+JSON.stringify(e,void 0,2)),t=i.$mailbox.$account.$getMailboxByPath(e.mailboxPath),n=new r(e.accountId,t,e),r.$$resource.fetch(n.$absolutePath({asDraft:!0}),"edit").then(function(e){r.$log.debug("New "+s+": "+JSON.stringify(e,void 0,2)+" original UID: "+i.uid);var t=r.$Preferences.defaults.AuxiliaryMailAccounts[i.$mailbox.$account.id];return t.security&&(t.security.alwaysSign&&(e.sign=!0),t.security.alwaysEncrypt&&(e.encrypt=!0)),angular.extend(n.editable,e),n.origin={message:i,action:s},n})})},r.prototype.$save=function(){var t=this,e=this.editable;return r.$log.debug("save = "+JSON.stringify(e,void 0,2)),r.$$resource.save(this.$absolutePath({asDraft:!0}),e).then(function(e){r.$log.debug("save = "+JSON.stringify(e,void 0,2)),t.$setUID(e.uid),t.$reload(),t.isNew=!1})},r.prototype.$send=function(){var t=this,e=angular.copy(this.editable);return r.$log.debug("send = "+JSON.stringify(e,void 0,2)),r.$$resource.post(this.$absolutePath({asDraft:!0}),"send",e).then(function(e){return"success"==e.status?(angular.isDefined(t.origin)&&(t.origin.action.startsWith("reply")?t.origin.message.isanswered=!0:"forward"==t.origin.action&&(t.origin.message.isforwarded=!0)),e):r.$q.reject(e.data)})},r.prototype.$unwrap=function(e){var t=this;return this.$loaded=r.STATUS.DELAYED_LOADING,r.$timeout(function(){t.$loaded!=r.STATUS.LOADED&&(t.$loaded=r.STATUS.LOADING)},r.STATUS.DELAYED_MS),this.$futureMessageData=e.then(function(e){return 0===t.isread&&(t.isread=!0,t.$mailbox.unseenCount--),r.$timeout(function(){return delete t.$parts,t.$loaded=r.STATUS.LOADED,t.init(e),t})}),this.$futureMessageData},r.prototype.$omit=function(e){var n={},s=e&&e.privateAttributes;return angular.forEach(this,function(e,t){("constructor"!=t&&"$"!=t[0]||s)&&(n[t]=e)}),n},r.prototype.download=function(){var e,t;return e={uids:[this.uid]},t={filename:this.subject+".zip"},r.$$resource.download(this.$mailbox.id,"saveMessages",e,t)},r.prototype.downloadAttachments=function(){var e;return e={filename:l("attachments")+"-"+this.uid+".zip"},r.$$resource.download(this.$absolutePath(),"archiveAttachments",null,e)}}(),function(){"use strict";function h(){this.show=!1,this.message=null,this.elements=[]}h.$factory=["$document","$timeout","$mdPanel","sgHotkeys",function(e,t,n,s){return angular.extend(h,{$document:e,$timeout:t,$mdPanel:n,sgHotkeys:s}),new h}],h.prototype.setMessage=function(e){this.message=e},h.prototype.registerImage=function(e){this.elements.push(e)},h.prototype.registerHotkeys=function(e){this.keys=[h.sgHotkeys.createHotkey({key:"left",description:l("View previous item"),callback:angular.bind(e,e.previousImage)}),h.sgHotkeys.createHotkey({key:"right",description:l("View next item"),callback:angular.bind(e,e.nextImage)})],_.forEach(this.keys,function(e){h.sgHotkeys.registerHotkey(e)})},h.prototype.showGallery=function(e,t){var n=this,s=h.$mdPanel,i=angular.element(this.message.$content()[t].content).find("img")[0].src,o=_.filter(this.message.attachmentAttrs,function(e){return 0===e.mimetype.indexOf("image/")}),a=_.findIndex(o,function(e){return 0<=e.url.indexOf(i)});angular.element(h.$document[0].body).addClass("sg-image-gallery-backdrop");var r=s.newPanelPosition().absolute(),c=s.newPanelAnimation().openFrom(e.target).duration(100).withAnimation(s.animation.FADE),u={attachTo:angular.element(document.body),locals:{lastIndex:o.length-1,images:o,selectedIndex:a,selectedImage:o[a]},bindToController:!0,controller:d,controllerAs:"$panelCtrl",position:r,animation:c,targetEvent:e,fullscreen:!0,hasBackdrop:!0,template:['','
',' '," arrow_back"," ",' image','
',' '," file_download"," ","
",'
',' '," navigate_before"," ",' ',' '," navigate_next"," ","
",'
','
',' ',"
","
","
"].join(""),trapFocus:!0,clickOutsideToClose:!0,escapeToClose:!0,focusOnOpen:!0,onOpenComplete:function(){n.show=!0,_.forEach(h.$document.find("sg-image-gallery")[0].getElementsByClassName("sg-image-thumbnail"),function(e){var t=e.children[0];angular.element(t).one("load",function(){t.naturalWidths.length?(i=_.difference(n,s),_.forEach(i,function(e){E.message.addTag(e)})):n.lengthn.$lastVisibleIndex&&(n.$topIndex=t-(n.$lastVisibleIndex-n.$topIndex))})):i.go("mail.account.mailbox").then(function(){s=null,delete n.selectedMessage})}catch(e){}}E.closePopup()})},this._showMailEditorInPopup=function(e){return!p.isPopup&&"popup"==v.defaults.SOGoMailComposeWindow&&(this.openInPopup(e),!0)},this.close=function(){var e=C.$virtualMode?"mail.account.virtualMailbox":"mail.account.mailbox";t.go(e).then(function(){E.message=null,delete h.selectedMessage})},this.reply=function(e){this._showMailEditorInPopup("reply")||O(e,this.message.$reply())},this.replyAll=function(e){this._showMailEditorInPopup("replyall")||O(e,this.message.$replyAll())},this.forward=function(e){this._showMailEditorInPopup("forward")||O(e,this.message.$forward())},this.edit=function(e){this._showMailEditorInPopup("edit")||this.message.$editableContent().then(function(){O(e,E.message)})},this.openInPopup=function(e){var t=[p.baseURL(),"UIxMailPopupView#!/Mail",this.message.accountId,m(m(this.message.$mailbox.path)),this.message.uid].join("/"),n=this.message.$absolutePath();e&&(t+="/"+e),s.open(t,n,["width=680","height=520","resizable=1","scrollbars=1","toolbar=0","location=0","directories=0","status=0","menubar=0","copyhistory=0"].join(","))},this.closePopup=function(){s.document.body.classList.contains("popup")&&s.close()},this.newMessage=function(t,e){"A"===t.target.tagName&&(t.stopPropagation(),t.preventDefault()),this.account.$newMessage({mailto:e}).then(function(e){O(t,e)})},this.toggleRawSource=function(e){this.showRawSource||this.message.$rawSource?this.showRawSource=!this.showRawSource:w.$$resource.post(this.message.id,"viewsource").then(function(e){E.message.$rawSource=e,E.showRawSource=!0})},this.print=function(e){s.print()},this.convertToEvent=function(e){return P(e,"appointment")},this.convertToTask=function(e){return P(e,"task")}}e.$inject=["$window","$scope","$q","$state","$mdMedia","$mdDialog","$mdPanel","sgConstant","stateAccounts","stateAccount","stateMailbox","stateMessage","sgHotkeys","encodeUriFilter","sgSettings","ImageGallery","sgFocus","Dialog","Preferences","Calendar","Component","Account","Mailbox","Message","AddressBook","Card"],angular.module("SOGo.MailerUI").controller("MessageController",e)}(),function(){"use strict";function e(e,s,t,n,i,o,a,r,c,u,d,h,g,f,m,p,$,b,v){var y=this;function M(){var e,t={};try{s.opener&&"$mailboxController"in s.opener&&"selectedFolder"in s.opener.$mailboxController&&("draft"==s.opener.$mailboxController.selectedFolder.type?(t.draftMailboxCtrl=s.opener.$mailboxController,"$messageController"in s.opener&&s.opener.$messageController.message.uid==d.uid&&(t.draftMessageCtrl=s.opener.$messageController)):d.origin&&(e=d.origin.message,s.opener.$mailboxController.selectedFolder.$id()==e.$mailbox.$id()&&(t.originMailboxCtrl=s.opener.$mailboxController)))}catch(e){}return t}function x(){y.uploader.url=y.message.$absolutePath({asDraft:!0,withResourcePath:!0})+"/save"}function C(){var e,t,n,s=y.message.editable.attachmentAttrs;if(s)for(e=0;e',' '," {{$ctrl.mailbox.$icon}}"," ",'

',' ',' ',"

",' ',' '," ",' more_vert'].join(""),controller:"sgMailboxListItemController",controllerAs:"$ctrl"}})}(),function(){function e(t,e,n){var s=this;this.$onInit=function(){var e=["uid","isread","isflagged","flags","subject"];"draft"==(this.MailboxService=n).selectedFolder.type&&e.push("subject"),t.$watch(function(){return s.message?[_.pick(s.message,e)]:null},function(e,t){s.message&&s.onUpdate()},!0)},this.onUpdate=function(){this.message.isread?e.removeClass("unread"):e.addClass("unread"),n.selectedFolder.isSelectedMessage(this.message.uid,this.message.$mailbox.path)?e.addClass("md-default-theme md-accent md-bg md-hue-2"):e.removeClass("md-default-theme md-accent md-bg md-hue-2")},this.setVisibility=function(e,t){t?e.classList.remove("ng-hide"):e.classList.add("ng-hide")}}e.$inject=["$scope","$element","Mailbox"],angular.module("SOGo.MailerUI").controller("sgMessageListItemController",e).directive("sgMessageListItem",function(){return{restrict:"C",scope:{},bindToController:{message:"=sgMessage"},controller:"sgMessageListItemController"}})}(),function(){function e(s,a,e,t,r,n,l,c,i){var u=this;this.$postLink=function(){var t,e,n,i,o;this.parentController=s.parentController,i=this.parentController.onUpdate,o=this.parentController.setVisibility,_.forEach(a.find("div"),function(e){e.classList.contains("sg-tile-content")?t=angular.element(e):e.classList.contains("sg-tile-icons")&&(n=angular.element(e))}),e=t.find("button")[0],this.threadButton=e,e=angular.element(e),this.threadIconElement=e.find("md-icon")[0],this.threadCountElement=e.find("span")[0],this.priorityIconElement=t.find("md-icon")[0],l.$virtualMode&&(this.mailboxNameElement=t.find("span")[0],this.mailboxNameElement.classList.remove("ng-hide")),this.senderElement=t.find("span")[1],_.forEach(t.find("div"),function(e){e.classList.contains("sg-tile-subject")?u.subjectElement=e:e.classList.contains("sg-tile-size")?u.sizeElement=e:e.classList.contains("sg-tile-date")&&(u.dateElement=e)}),_.forEach(n.find("md-icon"),function(e){"star"==e.textContent?u.flagIconElement=e:"reply"==e.textContent?u.answerIconElement=e:"forward"==e.textContent?u.forwardIconElement=e:"attach_file"==e.textContent&&(u.attachmentIconElement=e)}),this.parentController.onUpdate=function(){var e;u.message=u.parentController.message;var t=r.nodesToArray(a[0].querySelectorAll(".sg-category"));for(_.forEach(t,function(e){a[0].removeChild(e)}),e=0;e');s.css("left",3*e+"px"),s.css("background-color",u.service.$tags[n][1]),a.prepend(s)}}u.mailboxNameElement&&(u.mailboxNameElement.innerHTML=u.message.$mailbox.$displayName),"sent"==u.MailboxService.selectedFolder.type?u.senderElement.innerHTML=u.message.$shortAddress("to").encodeEntities():u.senderElement.innerHTML=u.message.$shortAddress("from").encodeEntities(),u.message.priority&&u.message.priority.level<3?(u.priorityIconElement.classList.remove("ng-hide"),u.message.priority.level<2?u.priorityIconElement.classList.add("md-warn"):u.priorityIconElement.classList.remove("md-warn")):u.priorityIconElement.classList.add("ng-hide"),u.message.first?(u.threadButton.classList.remove("ng-hide"),u.threadCountElement.innerHTML=u.message.threadCount,u.message.collapsed&&u.threadIconElement.classList.remove("md-rotate-180-ccw")):u.threadButton.classList.add("ng-hide"),u.subjectElement.innerHTML=u.message.subject.encodeEntities(),u.sizeElement.innerHTML=u.message.size,u.dateElement.innerHTML=u.message.relativedate,o(u.flagIconElement,u.message.isflagged),o(u.answerIconElement,u.message.isanswered),o(u.forwardIconElement,u.message.isforwarded),o(u.attachmentIconElement,u.message.hasattachment),angular.bind(u.parentController,i)()},this.service=c,this.MailboxService=l},this.toggleThread=function(){this.message.collapsed?this.threadIconElement.classList.add("md-rotate-180-ccw"):this.threadIconElement.classList.remove("md-rotate-180-ccw"),this.message.toggleThread()}}e.$inject=["$scope","$element","$parse","$state","$mdUtil","$mdToast","Mailbox","Message","encodeUriFilter"],angular.module("SOGo.MailerUI").controller("sgMessageListItemMainController",e).directive("sgMessageListItemMain",function(){return{restrict:"C",require:"^^sgMessageListItem",scope:{},template:['
','
',"
",' \x3c!-- mailbox --\x3e',' error'," \x3c!-- sender or recipient --\x3e","
",'
\x3c!-- date --\x3e
',"
",'
','
\x3c!-- subject --\x3e
','
\x3c!-- size --\x3e
',' ',' expand_more'," ","
","
",'
',' star',' reply',' forward',' attach_file',"
",'
',' \x3c!-- message loading progress --\x3e',"
"].join(""),link:function(e,t,n,s){e.parentController=s},controller:"sgMessageListItemMainController",controllerAs:"$ctrl"}})}(),function(){"use strict";function e(e,t){var n=this;this.$postLink=function(){t.registerImage(e),e.on("click",this.showImage)},this.showImage=function(e){"IMG"==e.target.tagName&&t.showGallery(e,n.partIndex)}}e.$inject=["$element","ImageGallery"],angular.module("SOGo.MailerUI").directive("sgZoomableImage",function(){return{restrict:"A",bindToController:{partIndex:"=sgZoomableImage"},controller:e}})}(); //# sourceMappingURL=Mailer.services.js.map