sogo/UI/WebServerResources/js/Mailer.services.js
2017-11-27 01:27:38 -05:00

2 lines
69 KiB
JavaScript

!function(){"use strict";function e(t){"function"!=typeof t.then&&(angular.extend(this,t),_.forEach(this.identities,function(e){e.fullName?e.full=e.fullName+" <"+e.email+">":e.full="<"+e.email+">"}),e.$log.debug("Account: "+JSON.stringify(t,void 0,2)))}e.$factory=["$q","$timeout","$log","sgSettings","Resource","Preferences","Mailbox","Message",function(t,n,s,o,i,a,r,l){return angular.extend(e,{$q:t,$timeout:n,$log:s,$$resource:new i(o.activeUser("folderURL")+"Mail",o.activeUser()),$Preferences:a,$Mailbox:r,$Message:l}),e}];try{angular.module("SOGo.MailerUI")}catch(e){angular.module("SOGo.MailerUI",["SOGo.Common"])}angular.module("SOGo.MailerUI").factory("Account",e.$factory),e.$findAll=function(t){return t?e.$unwrapCollection(t):e.$$resource.fetch("","mailAccounts").then(function(t){return e.$unwrapCollection(t)})},e.$unwrapCollection=function(t){var n=[];return angular.forEach(t,function(t,s){t.id=s,n[s]=new e(t)}),e.$accounts=n,n},e.prototype.getLength=function(){return this.$flattenMailboxes().length},e.prototype.getItemAtIndex=function(e){var t;return t=this.$flattenMailboxes(),e>=0&&e<t.length?t[e]:null},e.prototype.$getMailboxes=function(t){var n=this;return!this.$mailboxes||t&&t.reload?e.$Mailbox.$find(this,t).then(function(t){n.$mailboxes=t,n.$expanded=!1;var s,o=function(e){_.forEach(e,function(e){e.$expanded=s.indexOf("/"+e.id)>=0,e.children&&e.children.length>0&&o(e.children)})};if(e.$Preferences.settings.Mail.ExpandedFolders){if(angular.isString(e.$Preferences.settings.Mail.ExpandedFolders))try{s=angular.fromJson(e.$Preferences.settings.Mail.ExpandedFolders)}catch(t){e.$log.warn("Can't parse list of expanded folders. String was: "+e.$Preferences.settings.Mail.ExpandedFolders),s=[]}else s=e.$Preferences.settings.Mail.ExpandedFolders;n.$expanded=s.indexOf("/"+n.id)>=0,s.length>0&&o(n.$mailboxes)}return e.$accounts&&(n.$expanded|=1==e.$accounts.length),n.$flattenMailboxes({reload:!0}),n.$mailboxes}):e.$q.when(this.$mailboxes)},e.prototype.$flattenMailboxes=function(t){var n=[],s=[],o=function(e){_.forEach(e,function(e){n.push(e),(t&&t.all||e.$expanded)&&e.children&&e.children.length>0&&o(e.children)})};return!this.$$flattenMailboxes||t&&(t.reload||t.all)?(o(this.$mailboxes),t&&t.all||(this.$$flattenMailboxes=n,t&&t.saveState&&(_.forEach(e.$accounts,function(e){e.$expanded&&s.push("/"+e.id),_.reduce(e.$$flattenMailboxes,function(e,t){return t.$expanded&&e.push("/"+t.id),e},s)}),e.$$resource.post(null,"saveFoldersState",s)))):n=this.$$flattenMailboxes,n},e.prototype.$getMailboxByType=function(e){var t=function(n){var s=_.find(n,function(t){return t.type==e});return s||angular.forEach(n,function(e){!s&&e.children&&e.children.length>0&&(s=t(e.children))}),s};return t(this.$mailboxes)},e.prototype.$getMailboxByPath=function(e){var t=function(n){var s=_.find(n,function(t){return t.path==e});return s||angular.forEach(n,function(e){!s&&e.children&&e.children.length>0&&(s=t(e.children))}),s};return t(this.$mailboxes)},e.prototype.$newMailbox=function(t,n){var s=this;return e.$$resource.post(t.toString(),"createFolder",{name:n}).then(function(){s.$getMailboxes({reload:!0})})},e.prototype.updateQuota=function(e){var t,n;t=Math.round(1e4*e.usedSpace/e.maxQuota)/100,n=l("quotasFormat").formatted(t,Math.round(e.maxQuota/10.24)/100),this.$quota={percent:t,description:n}},e.prototype.$newMessage=function(t){var n=this;return e.$$resource.fetch(this.id.toString(),"compose").then(function(t){e.$log.debug("New message (compose): "+JSON.stringify(t,void 0,2));return new e.$Message(t.accountId,n.$getMailboxByPath(t.mailboxPath),t)}).then(function(n){return e.$$resource.fetch(n.$absolutePath({asDraft:!0}),"edit").then(function(s){return e.$log.debug("New message (edit): "+JSON.stringify(s,void 0,2)),angular.extend(n.editable,s),n.isNew=!0,t&&t.mailto&&(angular.isObject(t.mailto)?angular.extend(n.editable,t.mailto):n.$parseMailto(t.mailto)),n})})},e.prototype.$addDelegate=function(t){var n=this,s=e.$q.defer(),o={uid:t.uid};return!t.uid||_.indexOf(_.map(this.delegates,"uid"),t.uid)>-1?s.resolve():e.$$resource.fetch(this.id.toString(),"addDelegate",o).then(function(){n.delegates.push(t),s.resolve(n.users)},function(e,t){s.reject(l("An error occured please try again."))}),s.promise},e.prototype.$removeDelegate=function(t){var n=this,s={uid:t};return e.$$resource.fetch(this.id.toString(),"removeDelegate",s).then(function(){var e=_.indexOf(_.map(n.delegates,"uid"),t);e>=0&&n.delegates.splice(e,1)})}}(),function(){"use strict";function e(t,n){if(this.$account=t,"function"!=typeof n.then){if(this.init(n),this.name&&!this.path){var s=e.$$resource.create("createFolder",this.name);this.$unwrap(s)}}else this.$unwrap(n)}e.$factory=["$q","$timeout","$log","sgSettings","Resource","Message","Acl","Preferences","sgMailbox_PRELOAD",function(t,n,s,o,i,a,r,l,c){return angular.extend(e,{$q:t,$timeout:n,$log:s,$$resource:new i(o.activeUser("folderURL")+"Mail",o.activeUser()),$Message:a,$$Acl:r,$Preferences:l,$query:{sort:"arrival",asc:0},selectedFolder:null,$refreshTimeout:null,$virtualMode:!1,$virtualPath:!1,PRELOAD:c}),l.settings.Mail.SortingState&&(e.$query.sort=l.settings.Mail.SortingState[0],e.$query.asc=parseInt(l.settings.Mail.SortingState[1])),e}];try{angular.module("SOGo.MailerUI")}catch(e){angular.module("SOGo.MailerUI",["SOGo.Common"])}angular.module("SOGo.MailerUI").constant("sgMailbox_PRELOAD",{LOOKAHEAD:50,SIZE:100}).factory("Mailbox",e.$factory),e.$find=function(t,n){var s;return s=n&&n.all?this.$$resource.fetch(t.id.toString(),"viewAll"):this.$$resource.fetch(t.id.toString(),"view"),e.$unwrapCollection(t,s)},e.$unwrapCollection=function(t,n){var s=[],o=function(n,s){for(var i=0;i<s.children.length;i++)s.children[i].level=n,s.children[i]=new e(t,s.children[i]),o(n+1,s.children[i])};return n.then(function(n){return e.$timeout(function(){return angular.forEach(n.mailboxes,function(n,i){n.level=0;var a=new e(t,n);o(1,a),s.push(a)}),n.quotas&&t.updateQuota(n.quotas),s})})},e.$absolutePath=function(e,t){var n=[];return t&&(n=_.map(t.split("/"),function(e){return"folder"+e.asCSSIdentifier()})),n.splice(0,0,e),n.join("/")},e.prototype.init=function(t){(angular.isUndefined(this.uidsMap)||t.headers)&&(this.$isLoading=!0,this.$messages=[],this.uidsMap={}),angular.extend(this,t),this.path&&(this.id=this.$id(),this.$acl=new e.$$Acl("Mail/"+this.id)),this.$displayName=this.name,this.type&&(this.$isEditable=this.isEditable(),this.$isSpecial=!0,"inbox"==this.type?(this.$displayName=l("InboxFolderName"),this.$icon="inbox"):"draft"==this.type?(this.$displayName=l("DraftsFolderName"),this.$icon="drafts"):"sent"==this.type?(this.$displayName=l("SentFolderName"),this.$icon="send"):"trash"==this.type?(this.$displayName=l("TrashFolderName"),this.$icon="delete"):"junk"==this.type?(this.$displayName=l("JunkFolderName"),this.$icon="thumb_down"):"additional"==this.type?this.$icon="folder_shared":(this.$isSpecial=!1,this.$icon="folder_open")),this.$isNoInferiors=this.isNoInferiors(),angular.isUndefined(this.$shadowData)&&(this.$shadowData=this.$omit())},e.prototype.selectFolder=function(){e.$virtualMode||(e.selectedFolder=this)},e.prototype.getLength=function(){return this.$messages.length},e.prototype.getItemAtIndex=function(e){var t;return e>=0&&e<this.$messages.length&&(t=this.$messages[e],this.$lastVisibleIndex=Math.max(0,e-3),this.$loadMessage(t.uid))?t:null},e.prototype.$id=function(){return e.$absolutePath(this.$account.id,this.path)},e.prototype.$selectedMessages=function(){return _.filter(this.$messages,function(e){return e.selected})},e.prototype.$selectedCount=function(){return this.$selectedMessages().length},e.prototype.isSelectedMessage=function(e){return this.selectedMessage==e},e.prototype.$selectedMessage=function(){var e=this;return _.find(this.$messages,function(t){return t.uid==e.selectedMessage})},e.prototype.$selectedMessageIndex=function(){return this.uidsMap[this.selectedMessage]},e.prototype.hasSelectedMessage=function(){return angular.isDefined(this.selectedMessage)},e.prototype.$filter=function(t,n){var s=this,o={};if(angular.isDefined(this.unseenCount)||(this.unseenCount=0),e.$timeout(function(){s.$isLoading=!0}),e.$refreshTimeout&&e.$timeout.cancel(e.$refreshTimeout),t&&angular.extend(e.$query,t),angular.extend(o,{sortingAttributes:e.$query}),angular.isDefined(n)&&(o.filters=_.reject(n,function(e){return!e.searchInput||0===e.searchInput.length}),_.forEach(o.filters,function(e){var t,n=e.searchBy.match(/(\w+)_or_(\w+)/);n&&(o.sortingAttributes.match="OR",e.searchBy=n[1],(t=angular.copy(e)).searchBy=n[2],o.filters.push(t))})),!e.$virtualMode){var i=e.$Preferences.defaults.SOGoRefreshViewCheck;if(i&&"manually"!=i){var a=angular.bind(this,e.prototype.$filter,null,n);e.$refreshTimeout=e.$timeout(a,1e3*i.timeInterval())}}var r=e.$$resource.post(this.id,"view",o);return this.$unwrap(r)},e.prototype.$loadMessage=function(t){var n,s,o,i,a=this.uidsMap[t],r=this.$messages.length,l=!1;if(angular.isDefined(this.uidsMap[t])&&a<this.$messages.length&&(angular.isDefined(this.$messages[a].subject)&&(l=!0),n=Math.min(a+e.PRELOAD.LOOKAHEAD,r-1),angular.isDefined(this.$messages[n].subject)||angular.isDefined(this.$messages[n].loading)?(s=Math.max(a-e.PRELOAD.LOOKAHEAD,0),angular.isDefined(this.$messages[s].subject)||angular.isDefined(this.$messages[s].loading)||(n=a,a=Math.max(a-e.PRELOAD.SIZE,0))):n=Math.min(a+e.PRELOAD.SIZE,r-1),!angular.isDefined(this.$messages[a].subject)&&!angular.isDefined(this.$messages[a].loading)||!angular.isDefined(this.$messages[n].subject)&&!angular.isDefined(this.$messages[n].loading))){for(o=[];a<n&&a<r;a++)angular.isDefined(this.$messages[a].subject)||this.$messages[a].loading?n++:(o.push(this.$messages[a].uid),this.$messages[a].loading=!0);e.$log.debug("Loading UIDs "+o.join(" ")),i=e.$$resource.post(this.id,"headers",{uids:o}),this.$unwrapHeaders(i)}return l},e.prototype.isEditable=function(){return"folder"==this.type},e.prototype.isNoInferiors=function(){return this.flags.indexOf("noinferiors")>=0},e.prototype.isNoSelect=function(){return this.flags.indexOf("noselect")>=0},e.prototype.getClassName=function(e){return!1},e.prototype.$rename=function(){var t,n,s,o,i=this;return this.name==this.$shadowData.name?e.$q.when():(t=function(e,n){var s=null;return _.find(n,function(e){return e.path==i.path})?s=e:angular.forEach(n,function(e){!s&&e.children&&e.children.length>0&&(s=t(e,e.children))}),s},n=t(null,this.$account.$mailboxes),s=null===n?this.$account.$mailboxes:n.children,o=_.indexOf(_.map(s,"id"),this.id),this.$save().then(function(t){var n,a=i.path;i.init(t),s.splice(o,1),n=_.find(s,function(t){return e.$log.debug(t.name+" ? "+i.name),"folder"==t.type&&t.name.localeCompare(i.name)>0}),o=n?_.indexOf(_.map(s,"id"),n.id):s.length,s.splice(o,0,i);var r=new RegExp("^"+a),l=function(e){_.forEach(e.children,function(e){e.path=e.path.replace(r,i.path),e.id=e.$id(),l(e)})};l(i)}))},e.prototype.$compact=function(){var t=this;return e.$$resource.post(this.id,"expunge").then(function(e){e.quotas&&t.$account.updateQuota(e.quotas)})},e.prototype.$canFolderAs=function(){return"folder"==this.type&&0===this.level},e.prototype.$setFolderAs=function(t){return e.$$resource.post(this.id,"setAs"+t+"Folder")},e.prototype.$emptyTrash=function(){var t=this;return e.$$resource.post(this.id,"emptyTrash").then(function(e){t.$messages=[],t.uidsMap={},t.unseenCount=0,angular.isDefined(t.children)&&t.children.length&&t.$account.$getMailboxes({reload:!0}),e.quotas&&t.$account.updateQuota(e.quotas)})},e.prototype.$markAsRead=function(){var t=this;return e.$$resource.post(this.id,"markRead").then(function(){t.unseenCount=0,_.forEach(t.$messages,function(e){e.isread=!0})})},e.prototype.$flagMessages=function(t,n,s){var o={msgUIDs:_.map(t,"uid"),flags:n,operation:s};return e.$$resource.post(this.id,"addOrRemoveLabel",o).then(function(){return t})},e.prototype.saveSelectedMessages=function(){var t,n;return t=_.filter(this.$messages,function(e){return e.selected}),n=_.map(t,"uid"),{uids:n},{filename:l("Saved Messages.zip")},e.$$resource.download(this.id,"saveMessages",{uids:n})},e.prototype.exportFolder=function(){var t;return t={filename:this.name+".zip"},e.$$resource.download(this.id,"exportFolder",null,t)},e.prototype.$delete=function(t){var n=this;return e.$$resource.post(this.id,"delete",t).then(function(){return n.$account.$getMailboxes({reload:!0}),!0})},e.prototype.$_deleteMessages=function(e,t){var n,s=this,o=this.$messages.length;return n=_.filter(t,function(e,t){return!e.isread}),this.unseenCount-=n.length,_.forEachRight(this.$messages,function(t,n){var i=_.findIndex(e,function(e){return t.uid==e});i>-1?(e.splice(i,1),delete s.uidsMap[t.uid],t.uid==s.selectedMessage&&delete s.selectedMessage,s.$messages.splice(n,1),n<o&&(o=n)):s.uidsMap[t.uid]-=e.length}),o},e.prototype.$deleteMessages=function(t,n){var s,o,i=this;return s=_.map(t,"uid"),o={uids:s},n&&angular.extend(o,n),e.$$resource.post(this.id,"batchDelete",o).then(function(e){return e.quotas&&i.$account.updateQuota(e.quotas),i.$_deleteMessages(s,t)})},e.prototype.$markOrUnMarkMessagesAsJunk=function(t){var n=_.map(t,"uid"),s="junk"==this.type?"markMessagesAsNotJunk":"markMessagesAsJunk";return e.$$resource.post(this.id,s,{uids:n})},e.prototype.$copyMessages=function(t,n){var s=this,o=_.map(t,"uid");return e.$$resource.post(this.id,"copyMessages",{uids:o,folder:n}).then(function(e){e.quotas&&s.$account.updateQuota(e.quotas)})},e.prototype.$moveMessages=function(t,n){var s,o=this;return s=_.map(t,"uid"),e.$$resource.post(this.id,"moveMessages",{uids:s,folder:n}).then(function(){return o.$_deleteMessages(s,t)})},e.prototype.$reset=function(){var e=this;angular.forEach(this.$shadowData,function(t,n){delete e[n]}),angular.extend(this,this.$shadowData),this.$shadowData=this.$omit()},e.prototype.$save=function(){var t=this;return e.$$resource.save(this.id,this.$omit()).then(function(n){return t.$shadowData=t.$omit(),e.$log.debug(JSON.stringify(n,void 0,2)),n},function(n){return e.$log.error(JSON.stringify(n.data,void 0,2)),t.$reset(),n.data})},e.prototype.$newMailbox=function(e,t){return this.$account.$newMailbox(e,t)},e.prototype.$omit=function(){var e={};return angular.forEach(this,function(t,n){"constructor"!=n&&"children"!=n&&"headers"!=n&&"uids"!=n&&"uidsMap"!=n&&"$"!=n[0]&&(e[n]=t)}),e},e.prototype.$unwrap=function(t){var n=this,s=e.$q.defer();return this.$futureMailboxData=t,this.$futureMailboxData.then(function(t){var o=_.map(n.$selectedMessages(),"uid");e.$timeout(function(){var i,a;(!t.uids||n.$topIndex>t.uids.length-1)&&(n.$topIndex=0),n.init(t),n.uids&&(e.$log.debug("unwrapping "+n.uids.length+" messages"),a=_.invokeMap(n.headers[0],"toLowerCase"),n.headers.splice(0,1),n.threaded&&(i=n.uids[0],n.uids.splice(0,1)),_.reduce(n.uids,function(t,s,a){var r,l;return r=n.threaded?_.zipObject(i,s):{uid:s.toString()},n.uidsMap[r.uid]=a,l=new e.$Message(n.$account.id,n,r,!0),l.selected=o.indexOf(l.uid)>-1,t.push(l),t},n.$messages),_.forEach(n.headers,function(e){var t=_.zipObject(a,e),s=n.uidsMap[t.uid.toString()];_.extend(n.$messages[s],t)})),e.$log.debug("mailbox "+n.id+" ready"),n.$isLoading=!1,s.resolve(n.$messages)})},function(e){angular.extend(n,e),n.isError=!0,n.$isLoading=!1,s.reject()}),s.promise},e.prototype.$unwrapHeaders=function(t){var n=this;t.then(function(t){e.$timeout(function(){var e,s;t.length>0&&(e=_.invokeMap(t[0],"toLowerCase"),t.splice(0,1),_.forEach(t,function(t){t=_.zipObject(e,t),s=n.uidsMap[t.uid.toString()],angular.isDefined(s)&&_.extend(n.$messages[s],t)}))})})},e.prototype.$updateSubscribe=function(){var t=this.subscribed?"subscribe":"unsubscribe";e.$$resource.post(this.id,t)}}(),function(){"use strict";function e(e,t,n,s){this.accountId=e,this.$mailbox=t,this.$hasUnsafeContent=!1,this.$loadUnsafeContent=!1,this.editable={to:[],cc:[],bcc:[]},this.selected=!1,"function"!=typeof n.then?(!angular.isUndefined(s)&&s||(angular.extend(this,n),this.$formatFullAddresses()),this.uid=parseInt(n.uid)):this.$unwrap(n)}e.$factory=["$q","$timeout","$log","sgSettings","sgMessage_STATUS","Resource","Preferences",function(t,n,s,o,i,a,r){return angular.extend(e,{STATUS:i,$q:t,$timeout:n,$log:s,$$resource:new a(o.activeUser("folderURL")+"Mail",o.activeUser()),$avatar:angular.bind(r,r.avatar)}),r.defaults.SOGoMailLabelsColors&&(e.$tags=r.defaults.SOGoMailLabelsColors),r.defaults.SOGoMailDisplayRemoteInlineImages&&"always"==r.defaults.SOGoMailDisplayRemoteInlineImages&&(e.$displayRemoteInlineImages=!0),e}];try{angular.module("SOGo.MailerUI")}catch(e){angular.module("SOGo.MailerUI",["SOGo.Common"])}angular.module("SOGo.MailerUI").constant("sgMessage_STATUS",{NOT_LOADED:0,DELAYED_LOADING:1,LOADING:2,LOADED:3,DELAYED_MS:300}).factory("Message",e.$factory),e.filterTags=function(t,n){var s=new RegExp(t,"i"),o=[];return _.forEach(_.keys(e.$tags),function(t){var i=e.$tags[t];-1!=i[0].search(s)&&(_.includes(n,t)||o.push({name:t,description:i[0],color:i[1]}))}),o},e.prototype.$absolutePath=function(t){function n(){var e;return(e=_.map(s.$mailbox.path.split("/"),function(e){return"folder"+e.asCSSIdentifier()})).splice(0,0,s.accountId),e.join("/")}var s=this,o=this.id;return(angular.isUndefined(this.id)||t&&t.nocache)&&(this.id=n()+"/"+this.uid,o=this.id),t&&t.asDraft&&this.draftId&&(o=n()+"/"+this.draftId),t&&t.withResourcePath&&(o=e.$$resource.path(o)),o},e.prototype.$setUID=function(e){var t,n=this.uid||-1,s=this;n!=parseInt(e)&&(this.uid=parseInt(e),this.$absolutePath({nocache:!0}),n>-1?(n=n.toString(),angular.isDefined(this.$mailbox.uidsMap[n])&&(t=this.$mailbox.uidsMap[n],this.$mailbox.uidsMap[e]=t,delete this.$mailbox.uidsMap[n],_.forEach(["from","to","subject"],function(e){s.$mailbox.$messages[t][e]=s[e]}))):this.$mailbox.constructor.selectedFolder&&"draft"==this.$mailbox.constructor.selectedFolder.type&&this.$mailbox.constructor.selectedFolder.$filter())},e.prototype.$formatFullAddresses=function(){var t=this,n=_.map(t.$mailbox.$account.identities,"email");_.forEach(["from","to","cc","bcc","reply-to"],function(s){_.forEach(t[s],function(t){t.name&&t.name!=t.email?(t.full=t.name+" <"+t.email+">",t.name.length<10?t.shortname=t.name:t.name.split(" ").length&&(t.shortname=_.first(_.last(t.name.split(/, */)).split(/ +/)).replace("'",""))):t.email&&(t.full="<"+t.email+">",t.shortname=t.email.split("@")[0]),t.image=e.$avatar(t.email,32),_.indexOf(n,t.email)>=0&&(t.shortname=l("me"))})})},e.prototype.$shortRecipients=function(e){var t=this,n=[],s=0,o=0;return _.forEach(["to","cc","bcc"],function(i){o+=t[i]?t[i].length:0,_.forEach(t[i],function(t,o){s<e&&n.push(t.shortname),s++})}),o>e&&n.push(l("and %{0} more...",o-e)),n.join(", ")},e.prototype.$shortAddress=function(e){var t="";return this[e]&&this[e].length>0&&(t=this[e][0].name||this[e][0].email||""),t},e.prototype.allowReplyAll=function(){var e=0;return e=_.reduce(["to","cc"],_.bind(function(e,t){return this[t]?e+this[t].length:e},this),e),!this.isDraft&&e>1},e.prototype.loadUnsafeContent=function(){this.$loadUnsafeContent=!0},e.prototype.$content=function(){var t=this,n=[],s=function(o){if(o.msgclass="msg-attachment-other","UIxMailPartAlternativeViewer"==o.type)s(_.find(o.content,function(e){return o.preferredPart==e.contentType}));else if(angular.isArray(o.content)){if("UIxMailPartSignedViewer"==o.type&&1===o["supports-smime"]){var i="<p>"+o.error.replace(/\n/,'</p><p class="md-caption">');i=i.replace(/\n/g,'</p><p class="md-caption">')+"</p>",t.$smime={validSignature:o.valid,message:i}}_.forEach(o.content,function(e){s(e)})}else angular.isUndefined(o.safeContent)&&(o.safeContent=o.content,t.$hasUnsafeContent|=o.safeContent.indexOf(" unsafe-")>-1),"UIxMailPartHTMLViewer"==o.type?(o.html=!0,t.$loadUnsafeContent||e.$displayRemoteInlineImages?(angular.isUndefined(o.unsafeContent)&&(o.unsafeContent=document.createElement("div"),o.unsafeContent.innerHTML=o.safeContent,angular.forEach(["src","data","classid","background","style"],function(e){var t,n,s,i=o.unsafeContent.querySelectorAll("[unsafe-"+e+"]");for(s=0;s<i.length;s++)n=(t=angular.element(i[s])).attr("unsafe-"+e),t.attr(e,n),t.removeAttr("unsafe-"+e)}),t.$hasUnsafeContent=!1),o.content=o.unsafeContent.innerHTML):o.content=o.safeContent,n.push(o)):"UIxMailPartICalViewer"==o.type||"UIxMailPartImageViewer"==o.type||"UIxMailPartLinkViewer"==o.type?("UIxMailPartImageViewer"==o.type?o.msgclass="msg-attachment-image":"UIxMailPartLinkViewer"==o.type&&(o.msgclass="msg-attachment-link"),o.compile=!0,n.push(o)):(o.html=!0,o.content=o.safeContent,n.push(o))};return this.parts&&s(this.parts),n},e.prototype.$editableContent=function(){var t=this;return e.$$resource.fetch(this.$absolutePath(),"edit").then(function(n){return angular.extend(t,n),e.$$resource.fetch(t.$absolutePath({asDraft:!0}),"edit").then(function(n){var s=_.find(t.$mailbox.$account.identities,function(e){return-1!==n.from.toLowerCase().indexOf(e.email)});return s&&(n.from=s.full),e.$log.debug("editable = "+JSON.stringify(n,void 0,2)),angular.extend(t.editable,n),n.text})})},e.prototype.$plainContent=function(){return e.$$resource.fetch(this.$absolutePath(),"viewplain")},e.prototype.addTag=function(e){return this.$addOrRemoveTag("add",e)},e.prototype.removeTag=function(e){return this.$addOrRemoveTag("remove",e)},e.prototype.$addOrRemoveTag=function(t,n){var s={operation:t,msgUIDs:[this.uid],flags:n};if(n)return e.$$resource.post(this.$mailbox.$id(),"addOrRemoveLabel",s)},e.prototype.$imipAction=function(t,n,s){var o=this;e.$$resource.post([this.$absolutePath(),t].join("/"),n,s).then(function(t){e.$timeout(function(){o.$reload()})})},e.prototype.$sendMDN=function(){return this.shouldAskReceipt=0,e.$$resource.post(this.$absolutePath(),"sendMDN")},e.prototype.$deleteAttachment=function(t){var n={filename:t},s=this;e.$$resource.fetch(this.$absolutePath({asDraft:!0}),"deleteAttachment",n).then(function(n){e.$timeout(function(){s.editable.attachmentAttrs=_.filter(s.editable.attachmentAttrs,function(e){return e.filename!=t})})})},e.prototype.toggleFlag=function(){var t=this,n="markMessageFlagged";return this.isflagged&&(n="markMessageUnflagged"),e.$$resource.post(this.$absolutePath(),n).then(function(n){e.$timeout(function(){t.isflagged=!t.isflagged})})},e.prototype.$isLoading=function(){return this.$loaded==e.STATUS.LOADING},e.prototype.$reload=function(t){var n,s=this;return t&&t.useCache&&this.$futureMessageData?(this.isread||e.$$resource.fetch(this.$absolutePath(),"markMessageRead").then(function(){e.$timeout(function(){s.isread=!0,s.$mailbox.unseenCount--})}),this):(n=e.$$resource.fetch(this.$absolutePath(t),"view"),this.$unwrap(n))},e.prototype.$parseMailto=function(e){var t,n,s=/^mailto:([^\?]+)/.exec(e);s&&(t=_.map(decodeURIComponent(s[1]).split(","),function(e){return"<"+e.trim()+">"}),n={to:t},_.forEach(["subject","body"],function(t){var o=new RegExp(t+"=([^&]+)");t="body"==t?"text":t,(s=o.exec(e))&&(n[t]=decodeURIComponent(s[1]))}),_.forEach(["cc","bcc"],function(t){var o=new RegExp(t+"=([^&]+)");(s=o.exec(e))&&(n[t]=_.map(decodeURIComponent(s[1]).split(","),function(e){return"<"+e.trim()+">"}))}),angular.extend(this.editable,n))},e.prototype.$reply=function(){return this.$newDraft("reply")},e.prototype.$replyAll=function(){return this.$newDraft("replyall")},e.prototype.$forward=function(){return this.$newDraft("forward")},e.prototype.$newDraft=function(t){var n=this;return e.$$resource.fetch(this.$absolutePath(),t).then(function(s){var o,i;return e.$log.debug("New "+t+": "+JSON.stringify(s,void 0,2)),o=n.$mailbox.$account.$getMailboxByPath(s.mailboxPath),i=new e(s.accountId,o,s),e.$$resource.fetch(i.$absolutePath({asDraft:!0}),"edit").then(function(s){return e.$log.debug("New "+t+": "+JSON.stringify(s,void 0,2)+" original UID: "+n.uid),angular.extend(i.editable,s),i.origin={message:n,action:t},i})})},e.prototype.$save=function(){var t=this,n=this.editable;return e.$log.debug("save = "+JSON.stringify(n,void 0,2)),e.$$resource.save(this.$absolutePath({asDraft:!0}),n).then(function(n){e.$log.debug("save = "+JSON.stringify(n,void 0,2)),t.$setUID(n.uid),t.$reload(),t.isNew=!1})},e.prototype.$send=function(){var t=this,n=angular.copy(this.editable);return e.$log.debug("send = "+JSON.stringify(n,void 0,2)),e.$$resource.post(this.$absolutePath({asDraft:!0}),"send",n).then(function(n){return"success"==n.status?(angular.isDefined(t.origin)&&(t.origin.action.startsWith("reply")?t.origin.message.isanswered=!0:"forward"==t.origin.action&&(t.origin.message.isforwarded=!0)),n):e.$q.reject(n.data)})},e.prototype.$unwrap=function(t){var n=this;return this.$loaded=e.STATUS.DELAYED_LOADING,e.$timeout(function(){n.$loaded!=e.STATUS.LOADED&&(n.$loaded=e.STATUS.LOADING)},e.STATUS.DELAYED_MS),this.$futureMessageData=t.then(function(t){return 0===n.isread&&(n.isread=!0,n.$mailbox.unseenCount--),e.$timeout(function(){return angular.extend(n,t),n.$formatFullAddresses(),n.$loadUnsafeContent=!1,n.$loaded=e.STATUS.LOADED,n})}),this.$futureMessageData},e.prototype.$omit=function(e){var t={},n=e&&e.privateAttributes;return angular.forEach(this,function(e,s){("constructor"!=s&&"$"!=s[0]||n)&&(t[s]=e)}),t},e.prototype.download=function(){var t,n;return t={uids:[this.uid]},n={filename:this.subject+".zip"},e.$$resource.download(this.$mailbox.id,"saveMessages",t,n)},e.prototype.downloadAttachments=function(){var t;return t={filename:l("attachments")+"-"+this.uid+".zip"},e.$$resource.download(this.$absolutePath(),"archiveAttachments",null,t)}}(),function(){"use strict";function e(){this.show=!1,this.message=null,this.elements=[]}e.$factory=["$document","$timeout","$mdPanel","sgHotkeys",function(t,n,s,o){return angular.extend(e,{$document:t,$timeout:n,$mdPanel:s,sgHotkeys:o}),new e}],e.prototype.setMessage=function(e){this.message=e},e.prototype.registerImage=function(e){this.elements.push(e)},e.prototype.registerHotkeys=function(t){this.keys=[e.sgHotkeys.createHotkey({key:"left",description:l("View previous item"),callback:angular.bind(t,t.previousImage)}),e.sgHotkeys.createHotkey({key:"right",description:l("View next item"),callback:angular.bind(t,t.nextImage)})],_.forEach(this.keys,function(t){e.sgHotkeys.registerHotkey(t)})},e.prototype.showGallery=function(t,n){function s(e){e.$ctrl=this,this.close=function(){e.close()},this.selectImage=function(e){this.selectedIndex=e,this.selectedImage=this.images[e]},this.nextImage=function(){this.selectedIndex!=this.lastIndex&&this.selectImage(this.selectedIndex+1)},this.previousImage=function(){this.selectedIndex>0&&this.selectImage(this.selectedIndex-1)}}var o=this,i=e.$mdPanel,a=angular.element(this.message.parts.content[n].content).find("img")[0].src,r=_.filter(this.message.attachmentAttrs,function(e){return 0===e.mimetype.indexOf("image/")}),c=_.findIndex(r,function(e){return e.url.indexOf(a)>=0});angular.element(e.$document[0].body).addClass("sg-image-gallery-backdrop");var u=i.newPanelPosition().absolute(),d=i.newPanelAnimation().openFrom(t.target).duration(100).withAnimation(i.animation.FADE),h={attachTo:angular.element(document.body),locals:{lastIndex:r.length-1,images:r,selectedIndex:c,selectedImage:r[c]},bindToController:!0,controller:s,controllerAs:"$panelCtrl",position:u,animation:d,targetEvent:t,fullscreen:!0,hasBackdrop:!0,template:['<sg-image-gallery layout="column">',' <div class="md-toolbar-tools" layout="row" layout-align="space-between center">',' <md-button class="md-icon-button"',' aria-label="'+l("Close")+'"',' ng-click="$panelCtrl.close()">'," <md-icon>arrow_back</md-icon>"," </md-button>",' <md-icon class="md-primary">image</md-icon>',' <div md-truncate class="md-flex" ng-bind="$panelCtrl.selectedImage.filename"></div>',' <md-button class="md-icon-button"',' aria-label="'+l("Save Attachment")+'"',' ng-href="{{$panelCtrl.selectedImage.urlAsAttachment}}">'," <md-icon>file_download</md-icon>"," </md-button>"," </div>",' <div class="md-flex" layout="row" layout-align="space-between center">',' <md-button class="md-icon-button" ng-click="$panelCtrl.previousImage()"',' ng-disabled="$panelCtrl.selectedIndex == 0">'," <md-icon>navigate_before</md-icon>"," </md-button>",' <img class="sg-image" ng-src="{{$panelCtrl.selectedImage.url}}">',' <md-button class="md-icon-button" ng-click="$panelCtrl.nextImage()"',' ng-disabled="$panelCtrl.selectedIndex == $panelCtrl.lastIndex">'," <md-icon>navigate_next</md-icon>"," </md-button>"," </div>",' <div class="sg-image-thumbnails">',' <div class="sg-image-thumbnail" ng-repeat="image in ::$panelCtrl.images">',' <img class="sg-hide" ng-src="{{::image.url}}" ng-click="$panelCtrl.selectImage($index)">'," </div>"," </div>","</sg-image-gallery>"].join(""),trapFocus:!0,clickOutsideToClose:!0,escapeToClose:!0,focusOnOpen:!0,onOpenComplete:function(){o.show=!0,_.forEach(e.$document.find("sg-image-gallery")[0].getElementsByClassName("sg-image-thumbnail"),function(t){var n=t.children[0];angular.element(n).one("load",function(){n.naturalWidth<n.naturalHeight&&n.classList.add("portrait")}),e.$timeout(function(){n.classList.remove("sg-hide")},1e3)})},onDomRemoved:function(){angular.element(e.$document[0].body).removeClass("sg-image-gallery-backdrop"),o.show=!1,_.forEach(o.hotkeys,function(t){e.sgHotkeys.deregisterHotkey(t)})}};i.open(h).then(function(e){o.registerHotkeys(e.$ctrl)}),s.$inject=["mdPanelRef"]},angular.module("SOGo.MailerUI").factory("ImageGallery",e.$factory)}(),function(){"use strict";function e(e){this.$account=e}e.$factory=["$q","$timeout","$log","sgSettings","Resource","Message","Mailbox","sgMailbox_PRELOAD",function(t,n,s,o,i,a,r,l){return angular.extend(e,{$q:t,$timeout:n,$log:s,$$resource:new i(o.activeUser("folderURL")+"Mail",o.activeUser()),$Message:r,selectedFolder:null,PRELOAD:l}),e}];try{angular.module("SOGo.MailerUI")}catch(e){angular.module("SOGo.MailerUI",["SOGo.Common"])}angular.module("SOGo.MailerUI").constant("sgMailbox_PRELOAD",{LOOKAHEAD:50,SIZE:100}).factory("VirtualMailbox",e.$factory),e.$absolutePath=function(e){return[e,"virtual"].join("/")},e.prototype.init=function(e){this.$isLoading=!1,this.$mailboxes=[],this.uidsMap={},angular.extend(this,e),this.id=this.$id()},e.prototype.setMailboxes=function(e){this.$mailboxes=e,_.forEach(this.$mailboxes,function(e){e.$messages=[],e.uidsMap={}})},e.prototype.startSearch=function(t,n){var s=this,o=e.$q.when();this.$isLoading=!0,_.forEach(this.$mailboxes,function(i){o=o.then(function(){if(s.$isLoading)return e.$log.debug("searching mailbox "+i.path),i.$filter({sort:"date",asc:!1,match:t},n)})}),o.finally(function(){s.$isLoading=!1})},e.prototype.stopSearch=function(){e.$log.debug("stopping search..."),this.$isLoading=!1},e.prototype.selectFolder=function(){},e.prototype.resetSelectedMessage=function(){_.forEach(this.$mailboxes,function(e){delete e.selectedMessage})},e.prototype.hasSelectedMessage=function(){return angular.isDefined(_.find(this.$mailboxes,function(e){return angular.isDefined(e.selectedMessage)}))},e.prototype.isSelectedMessage=function(e,t){return angular.isDefined(_.find(this.$mailboxes,function(n){return n.path==t&&n.selectedMessage==e}))},e.prototype.getLength=function(){var e=0;return angular.isDefined(this.$mailboxes)?(_.forEach(this.$mailboxes,function(t){e+=t.$messages.length}),e):e},e.prototype.getItemAtIndex=function(e){var t,n,s,o,i;if(angular.isDefined(this.$mailboxes)&&e>=0)for(t=0,n=0;n<this.$mailboxes.length;n++)for(o=this.$mailboxes[n],s=0;s<o.$messages.length;t++,s++)if(i=o.$messages[s],t==e&&o.$loadMessage(i.uid))return i;return null},e.prototype.$id=function(){return e.$absolutePath(this.$account.id)},e.prototype.$selectedMessages=function(){return _.transform(this.$mailboxes,function(e,t){e[t.id]=t.$selectedMessages()},{})},e.prototype.$selectedCount=function(){return _.sum(_.invokeMap(this.$mailboxes,"$selectedCount"))},e.prototype.$flagMessages=function(t,n,s){var o={flags:n,operation:s},i=[],a=[];return _.forEach(t,function(t,n){if(t.length>0){var s=_.map(t,"uid");i.push(t);var r=e.$$resource.post(n,"addOrRemoveLabel",_.assign(o,{msgUIDs:s}));a.push(r)}}),e.$q.all(a).then(function(){return _.flatten(i)})},e.prototype.$deleteMessages=function(t){var n=[];return _.forEach(t,function(e,t){if(e.length>0){var s=e[0].$mailbox.$deleteMessages(e);n.push(s)}}),e.$q.all(n)},e.prototype.$markOrUnMarkMessagesAsJunk=function(t){var n=[];return _.forEach(t,function(e,t){if(e.length>0){var s=e[0].$mailbox.$markOrUnMarkMessagesAsJunk(e);n.push(s)}}),e.$q.all(n)},e.prototype.$copyMessages=function(t,n){var s=[];return _.forEach(t,function(e,t){if(e.length>0){var o=e[0].$mailbox.$copyMessages(e,n);s.push(o)}}),e.$q.all(s)},e.prototype.$moveMessages=function(t,n){var s=[];return _.forEach(t,function(e,t){if(e.length>0){var o=e[0].$mailbox.$moveMessages(e,n);s.push(o)}}),e.$q.all(s)}}(),function(){"use strict";function e(e,t,n,s,o,i,a,r,c,u,d,h,g,f,m,p,$,b){function v(e){return E.selectedFolder.$compact()}function M(e){var t=E.selectedFolder.$selectedMessageIndex();return angular.isDefined(t)?(t--,E.selectedFolder.$topIndex>0&&E.selectedFolder.$topIndex--):(t=E.selectedFolder.getLength()-1,E.selectedFolder.$topIndex=E.selectedFolder.getLength()),t>-1&&E.selectMessage(E.selectedFolder.$messages[t]),e.preventDefault(),t}function y(e){var t=E.selectedFolder.$selectedMessageIndex();return angular.isDefined(t)?(t++,E.selectedFolder.$topIndex<E.selectedFolder.getLength()&&E.selectedFolder.$topIndex++):t=0,t<E.selectedFolder.getLength()?E.selectMessage(E.selectedFolder.$messages[t]):t=-1,e.preventDefault(),t}function x(e){var t;E.selectedFolder.hasSelectedMessage()&&(t=M(e))>=0&&E.toggleMessageSelection(e,E.selectedFolder.$messages[t])}function C(e){var t;E.selectedFolder.hasSelectedMessage()&&(t=y(e))>=0&&E.toggleMessageSelection(e,E.selectedFolder.$messages[t])}function w(){return b.$virtualMode?E.selectedFolder.$mailboxes:[E.selectedFolder]}function I(e,t){var s,i,a=t;E.mode.multiple=E.selectedFolder.$selectedCount(),e?(t>0&&(a-=1,s=E.selectedFolder.$messages[a]),t<E.selectedFolder.$messages.length&&(i=E.selectedFolder.$messages[t]),s?s.isread&&i&&!i.isread&&(a=t,s=i):i&&(a=t,s=i),s?(E.selectedFolder.$topIndex=a,o.go("mail.account.mailbox.message",{messageId:s.uid})):o.go("mail.account.mailbox")):n(function(){console.warn("go to mailbox"),o.go("mail.account.mailbox")})}var E=this,S=angular.element(e.document).find("title").attr("sg-default")||"SOGo",F=[];this.$onInit=function(){e.$mailboxController=E,this.service=b,this.accounts=r,this.account=c,this.selectedFolder=u,this.messageDialog=null,this.mode={search:!1,multiple:0},function(e){e.push(d.createHotkey({key:l("hotkey_search"),description:l("Search"),callback:E.searchMode})),e.push(d.createHotkey({key:l("hotkey_compose"),description:l("Write a new message"),callback:function(e){null===E.messageDialog&&E.newMessage(e)}})),e.push(d.createHotkey({key:l("hotkey_junk"),description:l("Mark the selected messages as junk"),callback:E.markOrUnMarkMessagesAsJunk})),e.push(d.createHotkey({key:"space",description:l("Toggle item"),callback:E.toggleMessageSelection})),e.push(d.createHotkey({key:"shift+space",description:l("Toggle range of items"),callback:E.toggleMessageSelection})),e.push(d.createHotkey({key:"up",description:l("View next item"),callback:M,preventInClass:["sg-mail-part"]})),e.push(d.createHotkey({key:"down",description:l("View previous item"),callback:y,preventInClass:["sg-mail-part"]})),e.push(d.createHotkey({key:"shift+up",description:l("Add next item to selection"),callback:x,preventInClass:["sg-mail-part"]})),e.push(d.createHotkey({key:"shift+down",description:l("Add previous item to selection"),callback:C,preventInClass:["sg-mail-part"]})),_.forEach(["backspace","delete"],function(t){e.push(d.createHotkey({key:t,description:l("Delete selected message or folder"),callback:E.confirmDeleteSelectedMessages}))}),_.forEach(e,function(e){d.registerHotkey(e)})}(F),angular.element(e).on("beforeunload",v),t.$on("$destroy",function(){angular.element(e).off("beforeunload",v),_.forEach(F,function(e){d.deregisterHotkey(e)})}),t.$watch(function(){return E.selectedFolder.unseenCount},function(t){var n=S+" - ";t&&(n+="("+t+") "),n+=E.selectedFolder.$displayName,e.document.title=n})},this.centerIsClose=function(e){return this.selectedFolder.hasSelectedMessage()&&!!e},this.sort=function(e){E.selectedFolder.$filter({sort:e})},this.sortedBy=function(e){return b.$query.sort==e},this.searchMode=function(){E.mode.search=!0,f("search")},this.cancelSearch=function(){E.mode.search=!1,E.selectedFolder.$filter().then(function(){E.selectedFolder.selectedMessage&&n(function(){E.selectedFolder.$topIndex=E.selectedFolder.uidsMap[E.selectedFolder.selectedMessage]})})},this.composeWindowEnabled=function(){return p.defaults.SOGoMailComposeWindowEnabled},this.newMessage=function(t,n){var s;null===E.messageDialog&&(n||"popup"==p.defaults.SOGoMailComposeWindow?function(){var t=[g.baseURL(),"UIxMailPopupView#!/Mail",E.account.id,h(h(E.selectedFolder.path)),"new"].join("/"),n=E.selectedFolder.$id()+"/"+Math.random(0,1e3);console.debug(t),e.open(t,n,["width=680","height=520","resizable=1","scrollbars=1","toolbar=0","location=0","directories=0","status=0","menubar=0","copyhistory=0"].join(","))}():(s=E.account.$newMessage(),E.messageDialog=i.show({parent:angular.element(document.body),targetEvent:t,clickOutsideToClose:!1,escapeToClose:!1,templateUrl:"UIxMailEditor",controller:"MessageEditorController",controllerAs:"editor",locals:{stateAccount:E.account,stateMessage:s}}).finally(function(){E.messageDialog=null})))},this.selectMessage=function(e){b.$virtualMode?o.go("mail.account.virtualMailbox.message",{mailboxId:h(e.$mailbox.path),messageId:e.uid}):o.go("mail.account.mailbox.message",{messageId:e.uid})},this.toggleMessageSelection=function(e,t){var n,s,o,i=E.selectedFolder;if(t||(t=i.$selectedMessage()),!t)return!0;if(t.selected=!t.selected,E.mode.multiple+=t.selected?1:-1,e.shiftKey&&i.$selectedCount()>1){for(s=(n=i.uidsMap[t.uid])-2;s>=0&&!i.$messages[s].selected;)s--;if(s<0)for(s=n+2;s<i.getLength()&&!i.$messages[s].selected;)s++;if(s>=0&&s<i.getLength())for(o=Math.min(n,s);o<=Math.max(n,s);o++)i.$messages[o].selected=!0}e.preventDefault(),e.stopPropagation()},this.confirmDeleteSelectedMessages=function(e){var t=E.selectedFolder.$selectedMessages();null===E.messageDialog&&_.size(t)>0&&(E.messageDialog=m.confirm(l("Confirmation"),l("Are you sure you want to delete the selected messages?"),{ok:l("Delete")}).then(function(){var e=E.selectedFolder.hasSelectedMessage();E.selectedFolder.$deleteMessages(t).then(function(t){b.$virtualMode?e&&o.go("mail.account.virtualMailbox"):I(e,t)},function(n){E.messageDialog=m.confirm(l("Warning"),l("The messages could not be moved to the trash folder. Would you like to delete them immediately?"),{ok:l("Delete")}).then(function(){E.selectedFolder.$deleteMessages(t,{withoutTrash:!0}).then(function(t){b.$virtualMode?e&&o.go("mail.account.virtualMailbox"):I(e,t)})})})}).finally(function(){E.messageDialog=null})),e.preventDefault()},this.markOrUnMarkMessagesAsJunk=function(){var e=E.selectedFolder.hasSelectedMessage(),t=E.selectedFolder.$selectedMessages();0===_.size(t)&&e&&(t=[E.selectedFolder.$selectedMessage()]),_.size(t)>0&&E.selectedFolder.$markOrUnMarkMessagesAsJunk(t).then(function(){var n="/"+E.account.id+"/folderINBOX";"junk"!=E.selectedFolder.type&&(n="/"+E.account.$getMailboxByType("junk").id),E.selectedFolder.$moveMessages(t,n).then(function(t){b.$virtualMode?e&&o.go("mail.account.virtualMailbox"):I(e,t)})})},this.copySelectedMessages=function(e){var t=E.selectedFolder.$selectedMessages();_.size(t)>0&&E.selectedFolder.$copyMessages(t,"/"+e).then(function(){a.show(a.simple().content(l("%{0} message(s) copied",E.selectedFolder.$selectedCount())).position("top right").hideDelay(2e3))})},this.moveSelectedMessages=function(e){var t=E.selectedFolder.hasSelectedMessage(),n=E.selectedFolder.$selectedMessages(),s=E.selectedFolder.$selectedCount();_.size(n)>0&&E.selectedFolder.$moveMessages(n,"/"+e).then(function(e){a.show(a.simple().content(l("%{0} message(s) moved",s)).position("top right").hideDelay(2e3)),b.$virtualMode?t&&o.go("mail.account.virtualMailbox"):I(t,e)})},this.selectAll=function(){var e=0;_.forEach(w(),function(t){for(var n=0,s=t.$messages.length;n<s;n++)t.$messages[n].selected=!0;e+=s}),E.mode.multiple=e},this.unselectMessages=function(){_.forEach(w(),function(e){_.forEach(e.$messages,function(e){e.selected=!1})}),E.mode.multiple=0},this.markSelectedMessagesAsFlagged=function(){var e=E.selectedFolder.$selectedMessages();_.size(e)>0&&E.selectedFolder.$flagMessages(e,"\\Flagged","add").then(function(e){_.forEach(e,function(e){e.isflagged=!0})})},this.markSelectedMessagesAsUnread=function(){var e=E.selectedFolder.$selectedMessages();_.size(e)>0&&E.selectedFolder.$flagMessages(e,"seen","remove").then(function(e){_.forEach(e,function(e){e.isread&&e.$mailbox.unseenCount++,e.isread=!1})})},this.markSelectedMessagesAsRead=function(){var e=E.selectedFolder.$selectedMessages();_.size(e)>0&&E.selectedFolder.$flagMessages(e,"seen","add").then(function(e){_.forEach(e,function(e){e.isread||e.$mailbox.unseenCount--,e.isread=!0})})}}function t(e){return e[0].controller.prototype.resetScroll=function(){"messagesList"==this.$element.parent().attr("id")?this.updateSize():this.scrollTo(0)},e}e.$inject=["$window","$scope","$timeout","$q","$state","$mdDialog","$mdToast","stateAccounts","stateAccount","stateMailbox","sgHotkeys","encodeUriFilter","sgSettings","sgFocus","Dialog","Preferences","Account","Mailbox"],angular.module("SOGo.MailerUI").controller("MailboxController",e),t.$inject=["$delegate"],angular.module("material.components.virtualRepeat").decorator("mdVirtualRepeatContainerDirective",t)}(),function(){"use strict";function e(e,t,n,s,o,i,a,r,c,u,d,h,g,f,m,p,$,b){var v,M,y=this,x=[];this.$onInit=function(){this.service=f,this.accounts=b,this.currentSearchParam="",this.search={options:{"":"",subject:l("Enter Subject"),from:l("Enter From"),to:l("Enter To"),cc:l("Enter Cc"),body:l("Enter Body")},subfolders:1,match:"AND",params:[]},this.showSubscribedOnly=$.defaults.SOGoMailShowSubscribedFoldersOnly,this.refreshUnseenCount(),function(e){_.forEach(["backspace","delete"],function(t){e.push(h.createHotkey({key:t,description:l("Delete selected message or folder"),callback:function(){f.selectedFolderController&&f.selectedFolder&&!f.selectedFolder.hasSelectedMessage()&&f.selectedFolderController.confirmDelete(f.selectedFolder)}}))}),_.forEach(e,function(e){h.registerHotkey(e)})}(x),e.$on("$destroy",function(){_.forEach(x,function(e){h.deregisterHotkey(e)})})},this.hideAdvancedSearch=function(){y.service.$virtualPath=!1,y.service.$virtualMode=!1,v=y.accounts[0],M=y.searchPreviousMailbox,t.go("mail.account.mailbox",{accountId:v.id,mailboxId:c(M.path)})},this.toggleAdvancedSearch=function(){if(f.selectedFolder.$isLoading)y.virtualMailbox.stopSearch();else{var e,n=[],s=function(e){_.forEach(e,function(e){n.push(e),e.children&&e.children.length>0&&s(e.children)})};y.virtualMailbox=new m(y.accounts[0]),f.$virtualMode||(y.searchPreviousMailbox=f.selectedFolder),f.selectedFolder=y.virtualMailbox,f.$virtualMode=!0,angular.isDefined(f.$virtualPath)?(e=y.accounts[0].$getMailboxByPath(f.$virtualPath),n.push(e),y.search.subfolders&&e.children.length&&s(e.children)):n=y.accounts[0].$flattenMailboxes(),y.virtualMailbox.setMailboxes(n),y.virtualMailbox.startSearch(y.search.match,y.search.params),"mail.account.virtualMailbox"!=t.$current.name&&t.go("mail.account.virtualMailbox",{accountId:y.accounts[0].id})}},this.addSearchParam=function(e){return y.currentSearchParam=e,r("advancedSearch"),!1},this.newSearchParam=function(e){if(e.length&&y.currentSearchParam.length){var t=0,n=y.currentSearchParam;return e.startsWith("!")&&(t=1,e=e.substring(1).trim()),y.currentSearchParam="",{searchBy:n,searchInput:e,negative:t}}},this.toggleAccountState=function(e){e.$expanded=!e.$expanded,e.$flattenMailboxes({reload:!0,saveState:!0}),s(function(){angular.element(o).triggerHandler("resize")},150)},this.subscribe=function(e){function t(e,t,n){var s=this;s.loading=!0,s.filter={name:""},s.account=new g({id:n.id,name:n.name}),s.close=function(){t.hide()},s.account.$getMailboxes({reload:!0,all:!0}).then(function(){s.loading=!1})}i.show({templateUrl:e.id+"/subscribe",controller:t,controllerAs:"subscriptions",clickOutsideToClose:!0,escapeToClose:!0,locals:{srcAccount:e}}).finally(function(){e.$getMailboxes({reload:!0})}),t.$inject=["$scope","$mdDialog","srcAccount"]},this.newFolder=function(e){u.prompt(l("New Folder..."),l("Enter the new name of your folder")).then(function(t){e.$newMailbox(e.id,t).then(function(){},function(e,n){u.alert(l('An error occured while creating the mailbox "%{0}".',t),l(e.error))})})},this.delegate=function(e){function t(e,t,n,s){var o=this;o.users=s.delegates,o.account=s,o.userToAdd="",o.searchText="",o.userFilter=function(e){return n.$filter(e,s.delegates)},o.closeModal=function(){t.hide()},o.removeUser=function(e){s.$removeDelegate(e.uid).catch(function(e,t){u.alert(l("Warning"),l("An error occured please try again."))})},o.addUser=function(e){e&&s.$addDelegate(e).then(function(){o.userToAdd="",o.searchText=""},function(e){u.alert(l("Warning"),e)})}}i.show({templateUrl:e.id+"/delegation",controller:t,controllerAs:"delegate",clickOutsideToClose:!0,escapeToClose:!0,locals:{User:p,account:e}}),t.$inject=["$scope","$mdDialog","User","account"]},this.refreshUnseenCount=function(){var e,t=o.unseenCountFolders;_.forEach(y.accounts,function(e){_.includes(t,e.id+"/folderINBOX")||t.push(e.id+"/folderINBOX"),_.forEach(e.$$flattenMailboxes,function(e){angular.isDefined(e.unseenCount)&&!_.includes(t,e.id)&&t.push(e.id)})}),g.$$resource.post("","unseenCount",{mailboxes:t}).then(function(e){_.forEach(y.accounts,function(t){_.forEach(t.$$flattenMailboxes,function(t){e[t.id]&&(t.unseenCount=e[t.id])})})}),(e=$.defaults.SOGoRefreshViewCheck)&&"manually"!=e&&s(y.refreshUnseenCount,1e3*e.timeInterval())},this.isDroppableFolder=function(e,t){return t.id!=e.id&&!t.isNoSelect()},this.dragSelectedMessages=function(e,n,s){var o,i,r,c,u,d;o="/"+n.id,0===(i=e.$selectedMessages()).length&&(i=[e.$selectedMessage()]),r=_.map(i,"uid"),c=e.selectedMessage&&r.indexOf(e.selectedMessage)>=0,"copy"==s?(u=e.$copyMessages(i,o),d=l("%{0} message(s) copied",i.length)):(u=e.$moveMessages(i,o),d=l("%{0} message(s) moved",i.length)),u.then(function(){c&&t.go("mail.account.mailbox"),a.show(a.simple().content(d).position("top right").hideDelay(2e3))})}}e.$inject=["$scope","$state","$transitions","$timeout","$window","$mdDialog","$mdToast","sgFocus","encodeUriFilter","Dialog","sgSettings","sgHotkeys","Account","Mailbox","VirtualMailbox","User","Preferences","stateAccounts"],angular.module("SOGo.MailerUI").controller("MailboxesController",e)}(),function(){"use strict";function e(e,t,n,s,o,i,a,r,c,u,d,h,g,f,m,p,$,b,v,M,y,x){function C(){return t.mailbox?(arguments.length>0&&(t.mailbox.messageDialog=arguments[0]),t.mailbox.messageDialog):null}function w(e){return function(){if(null===C())return e.apply(F,arguments)}}function I(){var t,n,s={};return e.opener&&e.opener.$mailboxController&&e.opener.$mailboxController.selectedFolder.$id()==c.$id()&&(n=e.opener.$mailboxController,s.mailboxCtrl=n,e.opener.$messageController&&e.opener.$messageController.message.uid==u.uid&&(t=e.opener.$messageController,s.messageCtrl=t)),s}function E(e,t){null===C()&&C(o.show({parent:angular.element(document.body),targetEvent:e,clickOutsideToClose:!1,escapeToClose:!1,templateUrl:"UIxMailEditor",controller:"MessageEditorController",controllerAs:"editor",locals:{stateAccount:F.account,stateMessage:t}}).finally(function(){C(null),F.closePopup()}))}function S(e,t){F.message.$plainContent().then(function(n){var s={pid:b.$defaultCalendar(),type:t,summary:n.subject,comment:n.content},i=new v(s),a=[g.activeUser("folderURL"),"Calendar","UIx"+t.capitalize()+"EditorTemplate"].join("/");return o.show({parent:angular.element(document.body),targetEvent:e,clickOutsideToClose:!0,escapeToClose:!0,templateUrl:a,controller:"ComponentEditorController",controllerAs:"editor",locals:{stateComponent:i}})})}var F=this,A=null,k=[];this.$onInit=function(){e.$messageController=F,f.setMessage(u),this.$state=n,this.accounts=a,this.account=r,this.mailbox=c,this.message=u,this.service=x,this.tags={searchText:"",selected:""},this.showFlags=u.flags&&u.flags.length>0,this.$showDetailedRecipients=!1,F.showRawSource=!1,function(e){e.push(d.createHotkey({key:l("hotkey_reply"),description:l("Reply to the message"),callback:w(angular.bind(F,F.reply))})),e.push(d.createHotkey({key:l("hotkey_replyall"),description:l("Reply to sender and all recipients"),callback:w(angular.bind(F,F.replyAll))})),e.push(d.createHotkey({key:l("hotkey_forward"),description:l("Forward selected message"),callback:w(angular.bind(F,F.forward))})),e.push(d.createHotkey({key:l("hotkey_flag"),description:l("Flagged"),callback:w(angular.bind(u,u.toggleFlag))})),_.forEach(["backspace","delete"],function(t){e.push(d.createHotkey({key:t,callback:w(function(e){0===F.mailbox.$selectedCount()&&F.deleteMessage(),e.preventDefault()})}))}),_.forEach(e,function(e){d.registerHotkey(e)})}(k),e.opener?(t.$watchCollection(function(){return F.message.flags},function(e,t){var n;(e||t)&&(n=I()).messageCtrl&&n.messageCtrl.service.$timeout(function(){n.messageCtrl.showFlags=!0,n.messageCtrl.message.flags=e})}),t.$watch(function(){return F.message.isflagged},function(e,t){var n=I();n.mailboxCtrl&&n.mailboxCtrl.service.$timeout(function(){_.find(n.mailboxCtrl.selectedFolder.$messages,{uid:F.message.uid}).isflagged=e})})):t.$watchCollection(function(){return F.message.flags},function(e,t){var n,s,o;(e||t)&&(n=e||[],s=t||[],_.forEach(n,function(e,t){angular.isObject(e)&&(n[t]=e.name)}),n.length>s.length?(o=_.difference(n,s),_.forEach(o,function(e){F.message.addTag(e)})):n.length<s.length&&(o=_.difference(s,n),_.forEach(o,function(e){F.message.removeTag(e)})))}),t.$on("$destroy",function(){_.forEach(k,function(e){d.deregisterHotkey(e)})})},this.addFlags=function(e){this.showFlags=!0,m("flags")},this.toggleDetailedRecipients=function(e){this.$showDetailedRecipients=!this.$showDetailedRecipients,e.stopPropagation(),e.preventDefault()},this.filterMailtoLinks=function(e){var t;"A"==e.target.tagName&&"href"in e.target.attributes&&(t=e.target.attributes.href.value,/^mailto:([^\?]+)/.exec(t)&&(delete e.target.attributes.target,this.newMessage(e,t)))},this.deleteMessage=function(){var e,t,o,a,r,l=I();l.messageCtrl?(e=l.mailboxCtrl.selectedFolder,t=l.messageCtrl.message,o=l.messageCtrl.$state):(e=c,t=u,o=n),e.$deleteMessages([t]).then(function(n){var l=n;if(t=null,angular.isDefined(o)){n>0&&(l-=1,a=e.$messages[l]),n<e.$messages.length&&(r=e.$messages[n]),a?a.isread&&r&&!r.isread&&(l=n,a=r):r&&(l=n,a=r);try{a&&s(i["gt-md"])?(o.go("mail.account.mailbox.message",{messageId:a.uid}),l<e.$topIndex?e.$topIndex=l:l>e.$lastVisibleIndex&&(e.$topIndex=l-(e.$lastVisibleIndex-e.$topIndex))):o.go("mail.account.mailbox").then(function(){t=null,delete e.selectedMessage})}catch(e){}}F.closePopup()})},this._showMailEditorInPopup=function(e){return!g.isPopup&&"popup"==$.defaults.SOGoMailComposeWindow&&(this.openInPopup(e),!0)},this.close=function(){n.go("mail.account.mailbox").then(function(){F.message=null,delete c.selectedMessage})},this.reply=function(e){this._showMailEditorInPopup("reply")||E(e,this.message.$reply())},this.replyAll=function(e){this._showMailEditorInPopup("replyall")||E(e,this.message.$replyAll())},this.forward=function(e){this._showMailEditorInPopup("forward")||E(e,this.message.$forward())},this.edit=function(e){this._showMailEditorInPopup("edit")||this.message.$editableContent().then(function(){E(e,F.message)})},this.openInPopup=function(t){var n=[g.baseURL(),"UIxMailPopupView#!/Mail",this.message.accountId,h(h(this.message.$mailbox.path)),this.message.uid].join("/"),s=this.message.$absolutePath();t&&(n+="/"+t),A=e.open(n,s,["width=680","height=520","resizable=1","scrollbars=1","toolbar=0","location=0","directories=0","status=0","menubar=0","copyhistory=0"].join(","))},this.closePopup=function(){e.opener&&e.close()},this.newMessage=function(e,t){e.stopPropagation(),e.preventDefault(),this.account.$newMessage({mailto:t}).then(function(t){E(e,t)})},this.toggleRawSource=function(e){this.showRawSource||this.message.$rawSource?this.showRawSource=!this.showRawSource:x.$$resource.post(this.message.id,"viewsource").then(function(e){F.message.$rawSource=e,F.showRawSource=!0})},this.print=function(t){e.print()},this.convertToEvent=function(e){return S(e,"appointment")},this.convertToTask=function(e){return S(e,"task")}}e.$inject=["$window","$scope","$state","$mdMedia","$mdDialog","sgConstant","stateAccounts","stateAccount","stateMailbox","stateMessage","sgHotkeys","encodeUriFilter","sgSettings","ImageGallery","sgFocus","Dialog","Preferences","Calendar","Component","Account","Mailbox","Message"],angular.module("SOGo.MailerUI").controller("MessageController",e)}(),function(){"use strict";function e(e,t,n,s,o,i,a,r,c,u,d,h,g,f,m){function p(){var e,n={};try{t.opener&&"$mailboxController"in t.opener&&"selectedFolder"in t.opener.$mailboxController&&("draft"==t.opener.$mailboxController.selectedFolder.type?(n.draftMailboxCtrl=t.opener.$mailboxController,"$messageController"in t.opener&&t.opener.$messageController.message.uid==c.uid&&(n.draftMessageCtrl=t.opener.$messageController)):c.origin&&(e=c.origin.message,t.opener.$mailboxController.selectedFolder.$id()==e.$mailbox.$id()&&(n.originMailboxCtrl=t.opener.$mailboxController)))}catch(e){}return n}function $(){var e,t,n,s=b.message.editable.attachmentAttrs;if(s)for(e=0;e<s.length;e++)t={name:s[e].filename,type:s[e].mimetype,size:parseInt(s[e].size)},(n=new a.FileItem(b.uploader,t)).progress=100,n.isUploaded=!0,n.isSuccess=!0,n.inlineUrl=s[e].url,b.uploader.queue.push(n)}var b=this;b.addRecipient=function(e,t){var n,s,o,i,a,r=/([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)/i;if(n=b.message.editable[t],angular.isString(e)){for(a="",i=0;i<e.length;i++)9!=e.charCodeAt(i)&&32!=e.charCodeAt(i)&&44!=e.charCodeAt(i)&&59!=e.charCodeAt(i)||!r.test(a)?a+=e.charAt(i):(n.push(a),a="");return a&&n.push(a),null}return e.$isList({expandable:!0})?angular.isDefined(e.refs)&&e.refs.length?_.forEach(e.refs,function(e){e.email.length&&n.push(e.$shortFormat())}):(o=f.$find(e.container,e.c_name)).$id().then(function(e){_.forEach(o.refs,function(e){e.email.length&&n.push(e.$shortFormat())})}):s=e.$shortFormat(),s||null},b.autocomplete={to:{},cc:{},bcc:{}},b.autosave=null,b.autosaveDrafts=function(){b.message.$save(),m.defaults.SOGoMailAutoSave&&(b.autosave=d(b.autosaveDrafts,1e3*m.defaults.SOGoMailAutoSave*60))},b.cancel=function(){b.autosave&&d.cancel(b.autosave),b.message.isNew&&b.message.attachmentAttrs&&b.message.$mailbox.$deleteMessages([b.message]),o.cancel()},b.contactFilter=function(e){return g.$filterAll(e).then(function(e){var t=[];return _.forEach(_.invokeMap(e,"explode"),function(e){_.forEach(e,function(e){t.push(e)})}),_.uniqBy(t,function(e){return e.$$fullname+" "+e.$$email})})},b.isFullscreen=!1,b.hideBcc=0===c.editable.bcc.length,b.hideCc=0===c.editable.cc.length,b.identities=_.map(r.identities,"full"),b.message=c,b.recipientSeparatorKeys=[s.KEY_CODE.ENTER,s.KEY_CODE.TAB,s.KEY_CODE.COMMA,s.KEY_CODE.SEMICOLON],b.removeAttachment=function(e,n){e.isUploading?b.uploader.cancelItem(e):(b.message.$deleteAttachment(e.file.name),e.remove());var s=t.document.getElementById(n);s&&angular.element(s).prop("value",null)},b.save=function(){var e=p();b.message.$save().then(function(t){b.message.$rawSource=null,e.draftMailboxCtrl&&e.draftMailboxCtrl.selectedFolder.$filter().then(function(){e.draftMessageCtrl&&e.draftMessageCtrl.$state.go("mail.account.mailbox.message",{messageId:b.message.uid})}),i.show(i.simple().content(l("Your email has been saved")).position("top right").hideDelay(3e3))})},b.send=function(){b.sendState="sending",b.autosave&&d.cancel(b.autosave),b.message.$send().then(function(e){var t=p();b.sendState="sent",t.draftMailboxCtrl&&t.draftMailboxCtrl.selectedFolder.$filter().then(function(){t.draftMessageCtrl&&t.draftMessageCtrl.close()}),t.originMailboxCtrl&&t.originMailboxCtrl.selectedFolder.$filter(),i.show(i.simple().content(l("Your email has been sent")).position("top right").hideDelay(3e3)),d(o.hide,1e3)},function(e){d(function(){b.sendState="error",b.errorMessage=e.data?e.data.message:e.statusText})})},b.sendState=!1,b.toggleFullscreen=function(){b.isFullscreen=!b.isFullscreen},b.uploader=new a({url:c.$absolutePath({asDraft:!0,withResourcePath:!0})+"/save",autoUpload:!0,alias:"attachments",removeAfterUpload:!1,onSuccessItem:function(e,t,n,s){c.$setUID(t.uid),c.$reload({asDraft:!1}),e.inlineUrl=t.lastAttachmentAttrs[0].url},onCancelItem:function(e,t,n,s){c.$deleteAttachment(e.file.name),this.removeFromQueue(e)},onErrorItem:function(e,t,n,s){i.show(i.simple().content(l('Error while uploading the file "%{0}":',e.file.name)+" "+(t.message?l(t.message):"")).position("top right").action(l("OK")).hideDelay(!1)),this.removeFromQueue(e)}}),m.defaults.SOGoMailAutoSave&&(b.autosave=d(b.autosaveDrafts,1e3*m.defaults.SOGoMailAutoSave*60)),b.localeCode=m.defaults.LocaleCode,e.$on("$destroy",function(){b.uploader.destroy()}),"reply"==n.actionName?c.$reply().then(function(e){b.message=e,b.hideCc=!e.editable.cc||0===e.editable.cc.length,b.hideBcc=!e.editable.bcc||0===e.editable.bcc.length}):"replyall"==n.actionName?c.$replyAll().then(function(e){b.message=e,b.hideCc=!e.editable.cc||0===e.editable.cc.length,b.hideBcc=!e.editable.bcc||0===e.editable.bcc.length}):"forward"==n.actionName?c.$forward().then(function(e){b.message=e,$()}):angular.isDefined(c)&&(b.message=c,$())}function t(e,t){e.closeToast=function(){t.hide()}}e.$inject=["$scope","$window","$stateParams","$mdConstant","$mdDialog","$mdToast","FileUploader","stateAccount","stateMessage","encodeUriFilter","$timeout","Dialog","AddressBook","Card","Preferences"],t.$inject=["$scope","$mdToast"],angular.module("SOGo.MailerUI").controller("SendMessageToastController",t).controller("MessageEditorController",e)}(),function(){function e(e,t,n,s,o,i,a,r){var l=[];this.$postLink=function(){this.quotaElement=_.find(e.find("div"),function(e){return e.classList.contains("sg-quota")})},this.addMailboxController=function(e){l.push(e)},this.selectFolder=function(e){if(a.selectedFolderController=e,null!==a.selectedFolder){var t=_.find(l,function(e){return e.mailbox.id==a.selectedFolder.id});t&&t.unselectFolder()}s(i["gt-md"])||o("left").close()}}e.$inject=["$element","$transitions","$state","$mdMedia","$mdSidenav","sgConstant","Mailbox","encodeUriFilter"],angular.module("SOGo.MailerUI").controller("sgAccountController",e).directive("sgAccountSection",function(){return{restrict:"C",scope:{},controller:"sgAccountController"}})}(),function(){"use strict";function e(e,t){var n=this;e.delegateInvitation=!1,e.delegatedTo="",e.searchText="",e.userFilter=function(e){return t.$filter(e)},e.iCalendarAction=function(t){var s;"delegate"==t&&(s={receiveUpdates:!1,delegatedTo:e.delegatedTo.c_email}),e.viewer.message.$imipAction(n.pathToAttachment,t,s)}}e.$inject=["$scope","User"],angular.module("SOGo.MailerUI").controller("sgImipController",e).directive("sgImip",function(){return{restrict:"A",link:function(e,t,n,s){s.pathToAttachment=n.sgImipPath},controller:"sgImipController"}})}(),function(){function e(e,t,n,s,o,i,a,r,c,u,d){var h=this;this.$onInit=function(){this.$element=t,this.editMode=!1,this.accountController.addMailboxController(this)},this.$postLink=function(){this.selectableElement=t.find("div")[0],this.clickableElement=t.find("p")[0],this.inputContainer=t.find("md-input-container")[0],this.inputElement=t.find("input")[0],this.moreOptionsButton=_.last(t.find("md-icon")),null!==u.selectedFolder&&u.selectedFolder.id==this.mailbox.id&&this.accountController.selectFolder(this)},this.childLevel=function(){return"sg-child-level-"+this.mailbox.level},this.selectFolder=function(e){this.editMode||this.mailbox==u.selectedFolder||this.mailbox.isNoSelect()||(u.$virtualPath=!1,u.$virtualMode=!1,this.accountController.selectFolder(this),e&&(n.go("mail.account.mailbox",{accountId:this.mailbox.$account.id,mailboxId:d(this.mailbox.path)}),e.stopPropagation(),e.preventDefault()))},this.unselectFolder=function(){t[0].classList.remove("md-bg")},this.editFolder=function(e){this.editMode=!0,this.inputElement.value=this.mailbox.name,this.clickableElement.classList.add("ng-hide"),this.inputContainer.classList.remove("ng-hide"),this.inputElement.focus(),this.inputElement.select(),e&&(e.stopPropagation(),e.preventDefault())},this.saveFolder=function(e){this.inputElement.disabled||(this.mailbox.name=this.inputElement.value,this.inputElement.disabled=!0,this.mailbox.$rename().then(function(e){h.editMode=!1,h.inputContainer.classList.add("ng-hide"),h.clickableElement.classList.remove("ng-hide")}).finally(function(){h.inputElement.disabled=!1}))},this.revertEditing=function(){this.editMode=!1,this.clickableElement.classList.remove("ng-hide"),this.inputContainer.classList.add("ng-hide"),this.inputElement.value=this.mailbox.name},this.confirmDelete=function(){c.confirm(l("Warning"),l("Do you really want to move this folder into the trash ?"),{ok:l("Delete")}).then(function(){h.mailbox.$delete().then(function(){n.go("mail.account.inbox")},function(e){c.confirm(l("Warning"),l("The mailbox could not be moved to the trash folder. Would you like to delete it immediately?"),{ok:l("Delete")}).then(function(){h.mailbox.$delete({withoutTrash:!0}).then(function(){n.go("mail.account.inbox")},function(e){c.alert(l('An error occured while deleting the mailbox "%{0}".',h.mailbox.name),l(e.error))})})})})},this.showMenu=function(e){function t(e,t,n,o){var d=this;this.markFolderRead=function(){this.folder.$markAsRead()},this.newFolder=function(){c.prompt(l("New Folder..."),l("Enter the new name of your folder")).then(function(e){d.folder.$newMailbox(d.folder.id,e).then(function(){},function(t,n){c.alert(l('An error occured while creating the mailbox "%{0}".',e),l(t.error))})})},this.editFolder=function(){this.itemCtrl.editFolder()},this.compactFolder=function(){this.folder.$compact().then(function(){s.show(s.simple().content(l("Folder compacted")).position("top right").hideDelay(3e3))})},this.emptyTrashFolder=function(){this.folder.$emptyTrash().then(function(){s.show(s.simple().content(l("Trash emptied")).position("top right").hideDelay(3e3))})},this.showAdvancedSearch=function(){u.$virtualPath=this.folder.path,i(r["gt-md"])||a("left").close()},this.share=function(){this.folder.$acl.$users().then(function(){n.show({templateUrl:d.folder.id+"/UIxAclEditor",controller:"AclController",controllerAs:"acl",clickOutsideToClose:!0,escapeToClose:!0,locals:{usersWithACL:d.folder.$acl.users,User:o,folder:d.folder}})})},this.setFolderAs=function(e){this.folder.$setFolderAs(e).then(function(){d.folder.$account.$getMailboxes({reload:!0})})}}var n=o.newPanelPosition().relativeTo(this.moreOptionsButton).addPanelPosition(o.xPosition.ALIGN_START,o.yPosition.ALIGN_TOPS),d=o.newPanelAnimation().openFrom(this.moreOptionsButton).duration(100).withAnimation(o.animation.FADE),h={attachTo:angular.element(document.body),locals:{itemCtrl:this,folder:this.mailbox,confirmDelete:this.confirmDelete},bindToController:!0,controller:t,controllerAs:"$menuCtrl",position:n,animation:d,targetEvent:e,templateUrl:"UIxMailFolderMenu",trapFocus:!0,clickOutsideToClose:!0,escapeToClose:!0,focusOnOpen:!0};o.open(h).then(function(e){e.panelEl.one("click",function(){e.close()})}),t.$inject=["mdPanelRef","$state","$mdDialog","User"]}}e.$inject=["$scope","$element","$state","$mdToast","$mdPanel","$mdMedia","$mdSidenav","sgConstant","Dialog","Mailbox","encodeUriFilter"],angular.module("SOGo.MailerUI").controller("sgMailboxListItemController",e).directive("sgMailboxListItem",function(){return{restrict:"C",require:{accountController:"^^sgAccountSection"},scope:{},bindToController:{mailbox:"=sgMailbox"},template:[' <div class="sg-child-level-0"',' ng-class="$ctrl.childLevel()">',' <md-checkbox class="sg-folder"',' ng-class="$ctrl.mailbox.$icon"',' aria-label="'+l("Expanded")+'"',' ng-model="$ctrl.mailbox.$expanded"',' ng-disabled="$ctrl.mailbox.children.length == 0"',' ng-change="$ctrl.mailbox.$account.$flattenMailboxes({ reload: true, saveState: true })">'," <md-icon>{{$ctrl.mailbox.$icon}}</md-icon></md-checkbox>"," </div>",' <p class="sg-item-name"',' ng-click="$ctrl.selectFolder($event)"',' ng-dblclick="$ctrl.editFolder($event)">',' <span ng-bind="$ctrl.mailbox.$displayName"></span>',' <span class="sg-counter-badge ng-hide"',' ng-show="$ctrl.mailbox.unseenCount"',' ng-bind="$ctrl.mailbox.unseenCount"></span>'," </p>",' <md-input-container class="md-flex ng-hide">',' <input class="sg-item-name" type="text"',' aria-label="'+l("Enter the new name of your folder")+'"',' ng-blur="$ctrl.saveFolder($event)"',' sg-enter="$ctrl.saveFolder($event)"',' sg-escape="$ctrl.revertEditing()" />'," </md-input-container>",' <md-icon class="md-menu" ng-click="$ctrl.showMenu($event)" aria-label="'+l("Options")+'">more_vert</md-icon>'].join(""),controller:"sgMailboxListItemController",controllerAs:"$ctrl"}})}(),function(){function e(e,t,n){var s=this;this.$onInit=function(){this.MailboxService=n,e.$watch(function(){return s.message?[_.pick(s.message,["uid","isread","isflagged"])]:null},function(e,t){s.message&&s.onUpdate()},!0)},this.onUpdate=function(){this.message.isread?t.removeClass("unread"):t.addClass("unread"),n.selectedFolder.isSelectedMessage(this.message.uid,this.message.$mailbox.path)?t.addClass("md-default-theme md-accent md-bg md-hue-2"):t.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(e,t,n,s,o,i,a,r,l){var c=this;this.$postLink=function(){var n,s,i,l;this.parentController=e.parentController,i=this.parentController.onUpdate,l=this.parentController.setVisibility,_.forEach(t.find("div"),function(e){e.classList.contains("sg-tile-content")?n=angular.element(e):e.classList.contains("sg-tile-icons")&&(s=angular.element(e))}),this.priorityIconElement=n.find("md-icon")[0],a.$virtualMode&&(this.mailboxNameElement=n.find("span")[0],this.mailboxNameElement.classList.remove("ng-hide")),this.senderElement=n.find("span")[1],_.forEach(n.find("div"),function(e){e.classList.contains("sg-tile-subject")?c.subjectElement=e:e.classList.contains("sg-tile-size")?c.sizeElement=e:e.classList.contains("sg-tile-date")&&(c.dateElement=e)}),_.forEach(s.find("md-icon"),function(e){"star"==e.textContent?c.flagIconElement=e:"reply"==e.textContent?c.answerIconElement=e:"forward"==e.textContent?c.forwardIconElement=e:"attach_file"==e.textContent&&(c.attachmentIconElement=e)}),this.parentController.onUpdate=function(){var e;c.message=c.parentController.message;var n=o.nodesToArray(t[0].querySelectorAll(".sg-category"));for(_.forEach(n,function(e){t[0].removeChild(e)}),e=0;e<c.message.flags.length&&e<5;e++){var s=c.message.flags[e];if(c.service.$tags[s]){var a=angular.element('<div class="sg-category"></div>');a.css("left",3*e+"px"),a.css("background-color",c.service.$tags[s][1]),t.prepend(a)}}c.mailboxNameElement&&(c.mailboxNameElement.innerHTML=c.message.$mailbox.$displayName),"sent"==c.MailboxService.selectedFolder.type?c.senderElement.innerHTML=c.message.$shortAddress("to").encodeEntities():c.senderElement.innerHTML=c.message.$shortAddress("from").encodeEntities(),c.message.priority&&c.message.priority.level<3?(c.priorityIconElement.classList.remove("ng-hide"),c.message.priority.level<2?c.priorityIconElement.classList.add("md-warn"):c.priorityIconElement.classList.remove("md-warn")):c.priorityIconElement.classList.add("ng-hide"),c.subjectElement.innerHTML=c.message.subject.encodeEntities(),c.sizeElement.innerHTML=c.message.size,c.dateElement.innerHTML=c.message.relativedate,l(c.flagIconElement,c.message.isflagged),l(c.answerIconElement,c.message.isanswered),l(c.forwardIconElement,c.message.isforwarded),l(c.attachmentIconElement,c.message.hasattachment),angular.bind(c.parentController,i)()},this.service=r,this.MailboxService=a}}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:['<div class="sg-tile-content">',' <div class="sg-md-subhead">'," <div>",' <span class="sg-label-outline ng-hide">\x3c!-- mailbox --\x3e</span>',' <md-icon class="ng-hide">error</md-icon>'," <span>\x3c!-- sender or recipient --\x3e</span>"," </div>",' <div class="sg-tile-date">\x3c!-- date --\x3e</div>'," </div>",' <div class="sg-md-body">',' <div class="sg-tile-subject">\x3c!-- subject --\x3e</div>',' <div class="sg-tile-size">\x3c!-- size --\x3e</div>'," </div>","</div>",'<div class="sg-tile-icons">',' <md-icon class="ng-hide">star</md-icon>',' <md-icon class="ng-hide">reply</md-icon>',' <md-icon class="ng-hide">forward</md-icon>',' <md-icon class="ng-hide">attach_file</md-icon>',"</div>",'<div class="sg-progress-linear-bottom">',' <md-progress-linear class="md-accent"',' md-mode="indeterminate"',' ng-disabled="!$ctrl.message.$isLoading()">\x3c!-- message loading progress --\x3e</md-progress-linear>',"</div>"].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