sogo/UI/WebServerResources/js/Mailer.services.js
2018-04-25 01:28:00 -04:00

2 lines
71 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,i,o,a,r,l){return angular.extend(e,{$q:t,$timeout:n,$log:s,$$resource:new o(i.activeUser("folderURL")+"Mail",i.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,i=function(e){_.forEach(e,function(e){e.$expanded=s.indexOf("/"+e.id)>=0,e.children&&e.children.length>0&&i(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&&i(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=[],i=function(e){_.forEach(e,function(e){n.push(e),(t&&t.all||e.$expanded)&&e.children&&e.children.length>0&&i(e.children)})};return!this.$$flattenMailboxes||t&&(t.reload||t.all)?(i(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.$certificate=function(){var t=this;return this.security&&this.security.hasCertificate?this.$$certificate?e.$q.when(this.$$certificate):e.$$resource.fetch(this.id.toString(),"certificate").then(function(e){return t.$$certificate=e,e}):e.$q.reject()},e.prototype.$removeCertificate=function(){var t=this;return e.$$resource.fetch(this.id.toString(),"removeCertificate").then(function(){t.security.hasCertificate=!1})},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(s){return e.$$resource.fetch(s.$absolutePath({asDraft:!0}),"edit").then(function(i){var o=e.$Preferences.defaults.AuxiliaryMailAccounts[n.id];return o.security&&(o.security.alwaysSign&&(i.sign=!0),o.security.alwaysEncrypt&&(i.encrypt=!0)),e.$log.debug("New message (edit): "+JSON.stringify(i,void 0,2)),angular.extend(s.editable,i),s.isNew=!0,t&&t.mailto&&(angular.isObject(t.mailto)?angular.extend(s.editable,t.mailto):s.$parseMailto(t.mailto)),s})})},e.prototype.$addDelegate=function(t){var n=this,s=e.$q.defer(),i={uid:t.uid};return!t.uid||_.indexOf(_.map(this.delegates,"uid"),t.uid)>-1?s.resolve():e.$$resource.fetch(this.id.toString(),"addDelegate",i).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,i,o,a,r,l,c){return angular.extend(e,{$q:t,$timeout:n,$log:s,$$resource:new o(i.activeUser("folderURL")+"Mail",i.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=[],i=function(n,s){for(var o=0;o<s.children.length;o++)s.children[o].level=n,s.children[o]=new e(t,s.children[o]),i(n+1,s.children[o])};return n.then(function(n){return e.$timeout(function(){return angular.forEach(n.mailboxes,function(n,o){n.level=0;var a=new e(t,n);i(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,i={};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(i,{sortingAttributes:e.$query}),angular.isDefined(n)&&(i.filters=_.reject(n,function(e){return!e.searchInput||0===e.searchInput.length}),_.forEach(i.filters,function(e){var t,n=e.searchBy.match(/(\w+)_or_(\w+)/);n&&(i.sortingAttributes.match="OR",e.searchBy=n[1],(t=angular.copy(e)).searchBy=n[2],i.filters.push(t))})),!e.$virtualMode){var o=e.$Preferences.defaults.SOGoRefreshViewCheck;if(o&&"manually"!=o){var a=angular.bind(this,e.prototype.$filter,null,n);e.$refreshTimeout=e.$timeout(a,1e3*o.timeInterval())}}var r=e.$$resource.post(this.id,"view",i);return this.$unwrap(r)},e.prototype.$loadMessage=function(t){var n,s,i,o,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(i=[];a<n&&a<r;a++)angular.isDefined(this.$messages[a].subject)||this.$messages[a].loading?n++:(i.push(this.$messages[a].uid),this.$messages[a].loading=!0);e.$log.debug("Loading UIDs "+i.join(" ")),o=e.$$resource.post(this.id,"headers",{uids:i}),this.$unwrapHeaders(o)}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,i,o=this;return this.name==this.$shadowData.name?e.$q.when():(n=(t=function(e,n){var s=null;return _.find(n,function(e){return e.path==o.path})?s=e:angular.forEach(n,function(e){!s&&e.children&&e.children.length>0&&(s=t(e,e.children))}),s})(null,this.$account.$mailboxes),s=null===n?this.$account.$mailboxes:n.children,i=_.indexOf(_.map(s,"id"),this.id),this.$save().then(function(e){var t,n=o.path;o.init(e),s.splice(i,1),t=_.find(s,function(e){return"folder"==e.type&&e.name.localeCompare(o.name)>0}),i=t?_.indexOf(_.map(s,"id"),t.id):s.length,s.splice(i,0,o);var a=new RegExp("^"+n),r=function(e){_.forEach(e.children,function(e){e.path=e.path.replace(a,o.path),e.id=e.$id(),r(e)})};r(o)}))},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 i={msgUIDs:_.map(t,"uid"),flags:n,operation:s};return e.$$resource.post(this.id,"addOrRemoveLabel",i).then(function(){return t})},e.prototype.saveSelectedMessages=function(){var t,n;return t=_.filter(this.$messages,function(e){return e.selected}),{uids:n=_.map(t,"uid")},{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,i=this.$messages.length;return n=_.filter(t,function(e,t){return!e.isread}),this.unseenCount-=n.length,_.forEachRight(this.$messages,function(t,n){var o=_.findIndex(e,function(e){return t.uid==e});o>-1?(e.splice(o,1),delete s.uidsMap[t.uid],t.uid==s.selectedMessage&&delete s.selectedMessage,s.$messages.splice(n,1),n<i&&(i=n)):s.uidsMap[t.uid]-=e.length}),i},e.prototype.$deleteMessages=function(t,n){var s,i,o=this;return i={uids:s=_.map(t,"uid")},n&&angular.extend(i,n),e.$$resource.post(this.id,"batchDelete",i).then(function(e){return e.quotas&&o.$account.updateQuota(e.quotas),o.$_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,i=_.map(t,"uid");return e.$$resource.post(this.id,"copyMessages",{uids:i,folder:n}).then(function(e){e.quotas&&s.$account.updateQuota(e.quotas)})},e.prototype.$moveMessages=function(t,n){var s,i=this;return s=_.map(t,"uid"),e.$$resource.post(this.id,"moveMessages",{uids:s,folder:n}).then(function(){return i.$_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 i=_.map(n.$selectedMessages(),"uid");e.$timeout(function(){var o,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&&(o=n.uids[0],n.uids.splice(0,1)),_.reduce(n.uids,function(t,s,a){var r,l;return r=n.threaded?_.zipObject(o,s):{uid:s.toString()},n.uidsMap[r.uid]=a,(l=new e.$Message(n.$account.id,n,r,!0)).selected=i.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,i,o,a,r){return angular.extend(e,{STATUS:o,$q:t,$timeout:n,$log:s,$$resource:new a(i.activeUser("folderURL")+"Mail",i.activeUser()),$Preferences:r,$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"),i=[];return _.forEach(_.keys(e.$tags),function(t){var o=e.$tags[t];-1!=o[0].search(s)&&(_.includes(n,t)||i.push({name:t,description:o[0],color:o[1]}))}),i},e.prototype.$absolutePath=function(t){var n=this,s=this.id;function i(){var e;return(e=_.map(n.$mailbox.path.split("/"),function(e){return"folder"+e.asCSSIdentifier()})).splice(0,0,n.accountId),e.join("/")}return(angular.isUndefined(this.id)||t&&t.nocache)&&(this.id=i()+"/"+this.uid,s=this.id),t&&t.asDraft&&this.draftId&&(s=i()+"/"+this.draftId),t&&t.withResourcePath&&(s=e.$$resource.path(s)),s},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,i=0;return _.forEach(["to","cc","bcc"],function(o){i+=t[o]?t[o].length:0,_.forEach(t[o],function(t,i){s<e&&n.push(t.shortname),s++})}),i>e&&n.push(l("and %{0} more...",i-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,delete this.$parts},e.prototype.$content=function(){var t=this,n=[],s=function(i){i.msgclass="msg-attachment-other","UIxMailPartAlternativeViewer"==i.type?s(_.find(i.content,function(e){return i.preferredPart==e.contentType})):angular.isArray(i.content)?("UIxMailPartSignedViewer"==i.type&&1===i["supports-smime"]?t.signed={valid:i.valid,certificate:i.certificates[i.certificates.length-1],message:i.message}:"UIxMailPartEncryptedViewer"==i.type&&(t.encrypted={valid:i.valid},i.valid?t.encrypted.message=l("This message is encrypted"):t.encrypted.message=l("This message can't be decrypted. Please make sure you have uploaded your S/MIME certificate from the mail preferences module.")),_.forEach(i.content,function(e){s(e)})):(angular.isUndefined(i.safeContent)&&(i.safeContent=i.content,t.$hasUnsafeContent|=i.safeContent.indexOf(" unsafe-")>-1),"UIxMailPartHTMLViewer"==i.type?(i.html=!0,t.$loadUnsafeContent||e.$displayRemoteInlineImages?(angular.isUndefined(i.unsafeContent)&&(i.unsafeContent=document.createElement("div"),i.unsafeContent.innerHTML=i.safeContent,angular.forEach(["src","data","classid","background","style"],function(e){var t,n,s,o=i.unsafeContent.querySelectorAll("[unsafe-"+e+"]");for(s=0;s<o.length;s++)n=(t=angular.element(o[s])).attr("unsafe-"+e),t.attr(e,n),t.removeAttr("unsafe-"+e)}),t.$hasUnsafeContent=!1),i.content=i.unsafeContent.innerHTML):i.content=i.safeContent,n.push(i)):"UIxMailPartICalViewer"==i.type||"UIxMailPartImageViewer"==i.type||"UIxMailPartLinkViewer"==i.type?("UIxMailPartImageViewer"==i.type?i.msgclass="msg-attachment-image":"UIxMailPartLinkViewer"==i.type&&(i.msgclass="msg-attachment-link"),i.compile=!0,n.push(i)):(i.html=!0,i.content=i.safeContent,n.push(i)))};return this.$parts?this.$parts:(this.parts&&s(this.parts),this.$parts=n,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)});s&&(n.from=s.full);var i=e.$Preferences.defaults.AuxiliaryMailAccounts[t.$mailbox.$account.id];return i.security&&(i.security.alwaysSign&&(n.sign=!0),i.security.alwaysEncrypt&&(n.encrypt=!0)),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 i=this;e.$$resource.post([this.$absolutePath(),t].join("/"),n,s).then(function(t){e.$timeout(function(){i.$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 i=new RegExp(t+"=([^&]+)");t="body"==t?"text":t,(s=i.exec(e))&&(n[t]=decodeURIComponent(s[1]))}),_.forEach(["cc","bcc"],function(t){var i=new RegExp(t+"=([^&]+)");(s=i.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 i,o;return e.$log.debug("New "+t+": "+JSON.stringify(s,void 0,2)),i=n.$mailbox.$account.$getMailboxByPath(s.mailboxPath),o=new e(s.accountId,i,s),e.$$resource.fetch(o.$absolutePath({asDraft:!0}),"edit").then(function(s){e.$log.debug("New "+t+": "+JSON.stringify(s,void 0,2)+" original UID: "+n.uid);var i=e.$Preferences.defaults.AuxiliaryMailAccounts[n.$mailbox.$account.id];return i.security&&(i.security.alwaysSign&&(s.sign=!0),i.security.alwaysEncrypt&&(s.encrypt=!0)),angular.extend(o.editable,s),o.origin={message:n,action:t},o})})},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 delete n.$parts,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,i){return angular.extend(e,{$document:t,$timeout:n,$mdPanel:s,sgHotkeys:i}),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){var s=this,i=e.$mdPanel,o=angular.element(this.message.$content()[n].content).find("img")[0].src,a=_.filter(this.message.attachmentAttrs,function(e){return 0===e.mimetype.indexOf("image/")}),r=_.findIndex(a,function(e){return e.url.indexOf(o)>=0});angular.element(e.$document[0].body).addClass("sg-image-gallery-backdrop");var c=i.newPanelPosition().absolute(),u=i.newPanelAnimation().openFrom(t.target).duration(100).withAnimation(i.animation.FADE),d={attachTo:angular.element(document.body),locals:{lastIndex:a.length-1,images:a,selectedIndex:r,selectedImage:a[r]},bindToController:!0,controller:h,controllerAs:"$panelCtrl",position:c,animation:u,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(){s.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"),s.show=!1,_.forEach(s.hotkeys,function(t){e.sgHotkeys.deregisterHotkey(t)})}};i.open(d).then(function(e){s.registerHotkeys(e.$ctrl)}),h.$inject=["mdPanelRef"];function h(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)}}},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,i,o,a,r,l){return angular.extend(e,{$q:t,$timeout:n,$log:s,$$resource:new o(i.activeUser("folderURL")+"Mail",i.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,i=e.$q.when();this.$isLoading=!0,_.forEach(this.$mailboxes,function(o){i=i.then(function(){if(s.$isLoading)return e.$log.debug("searching mailbox "+o.path),o.$filter({sort:"date",asc:!1,match:t},n)})}),i.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,i,o;if(angular.isDefined(this.$mailboxes)&&e>=0)for(t=0,n=0;n<this.$mailboxes.length;n++)for(i=this.$mailboxes[n],s=0;s<i.$messages.length;t++,s++)if(o=i.$messages[s],t==e&&i.$loadMessage(o.uid))return o;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 i={flags:n,operation:s},o=[],a=[];return _.forEach(t,function(t,n){if(t.length>0){var s=_.map(t,"uid");o.push(t);var r=e.$$resource.post(n,"addOrRemoveLabel",_.assign(i,{msgUIDs:s}));a.push(r)}}),e.$q.all(a).then(function(){return _.flatten(o)})},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 i=e[0].$mailbox.$copyMessages(e,n);s.push(i)}}),e.$q.all(s)},e.prototype.$moveMessages=function(t,n){var s=[];return _.forEach(t,function(e,t){if(e.length>0){var i=e[0].$mailbox.$moveMessages(e,n);s.push(i)}}),e.$q.all(s)}}(),function(){"use strict";e.$inject=["$window","$scope","$timeout","$q","$state","$mdDialog","$mdToast","stateAccounts","stateAccount","stateMailbox","sgHotkeys","encodeUriFilter","sgSettings","sgFocus","Dialog","Preferences","Account","Mailbox"];function e(e,t,n,s,i,o,a,r,c,u,d,h,g,f,m,p,$,b){var v=this,y=angular.element(e.document).find("title").attr("sg-default")||"SOGo",M=[];this.$onInit=function(){e.$mailboxController=v,this.service=b,this.accounts=r,this.account=c,this.selectedFolder=u,this.messageDialog=null,this.mode={search:!1,multiple:0},(n=M).push(d.createHotkey({key:l("hotkey_search"),description:l("Search"),callback:v.searchMode})),n.push(d.createHotkey({key:l("hotkey_compose"),description:l("Write a new message"),callback:function(e){null===v.messageDialog&&v.newMessage(e)}})),n.push(d.createHotkey({key:l("hotkey_junk"),description:l("Mark the selected messages as junk"),callback:v.markOrUnMarkMessagesAsJunk})),n.push(d.createHotkey({key:"space",description:l("Toggle item"),callback:v.toggleMessageSelection})),n.push(d.createHotkey({key:"shift+space",description:l("Toggle range of items"),callback:v.toggleMessageSelection})),n.push(d.createHotkey({key:"up",description:l("View next item"),callback:C,preventInClass:["sg-mail-part"]})),n.push(d.createHotkey({key:"down",description:l("View previous item"),callback:w,preventInClass:["sg-mail-part"]})),n.push(d.createHotkey({key:"shift+up",description:l("Add next item to selection"),callback:I,preventInClass:["sg-mail-part"]})),n.push(d.createHotkey({key:"shift+down",description:l("Add previous item to selection"),callback:E,preventInClass:["sg-mail-part"]})),_.forEach(["backspace","delete"],function(e){n.push(d.createHotkey({key:e,description:l("Delete selected message or folder"),callback:v.confirmDeleteSelectedMessages}))}),_.forEach(n,function(e){d.registerHotkey(e)});var n;angular.element(e).on("beforeunload",x),t.$on("$destroy",function(){angular.element(e).off("beforeunload",x),_.forEach(M,function(e){d.deregisterHotkey(e)})}),t.$watch(function(){return v.selectedFolder.unseenCount},function(t){var n=y+" - ";t&&(n+="("+t+") "),n+=v.selectedFolder.$displayName,e.document.title=n})};function x(e){return v.selectedFolder.$compact()}this.centerIsClose=function(e){return this.selectedFolder.hasSelectedMessage()&&!!e},this.sort=function(e){v.selectedFolder.$filter({sort:e})},this.sortedBy=function(e){return b.$query.sort==e},this.searchMode=function(){v.mode.search=!0,f("search")},this.cancelSearch=function(){v.mode.search=!1,v.selectedFolder.$filter().then(function(){v.selectedFolder.selectedMessage&&n(function(){v.selectedFolder.$topIndex=v.selectedFolder.uidsMap[v.selectedFolder.selectedMessage]})})},this.composeWindowEnabled=function(){return p.defaults.SOGoMailComposeWindowEnabled},this.newMessage=function(t,n){var s;null===v.messageDialog&&(n||"popup"==p.defaults.SOGoMailComposeWindow?function(){var t=[g.baseURL(),"UIxMailPopupView#!/Mail",v.account.id,h(h(v.selectedFolder.path)),"new"].join("/"),n=v.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=v.account.$newMessage(),v.messageDialog=o.show({parent:angular.element(document.body),targetEvent:t,clickOutsideToClose:!1,escapeToClose:!1,templateUrl:"UIxMailEditor",controller:"MessageEditorController",controllerAs:"editor",locals:{stateAccount:v.account,stateMessage:s}}).catch(_.noop).finally(function(){v.messageDialog=null})))};function C(e){var t=v.selectedFolder.$selectedMessageIndex();return angular.isDefined(t)?(t--,v.selectedFolder.$topIndex>0&&v.selectedFolder.$topIndex--):(t=v.selectedFolder.getLength()-1,v.selectedFolder.$topIndex=v.selectedFolder.getLength()),t>-1&&v.selectMessage(v.selectedFolder.$messages[t]),e.preventDefault(),t}function w(e){var t=v.selectedFolder.$selectedMessageIndex();return angular.isDefined(t)?(t++,v.selectedFolder.$topIndex<v.selectedFolder.getLength()&&v.selectedFolder.$topIndex++):t=0,t<v.selectedFolder.getLength()?v.selectMessage(v.selectedFolder.$messages[t]):t=-1,e.preventDefault(),t}function I(e){var t;v.selectedFolder.hasSelectedMessage()&&(t=C(e))>=0&&v.toggleMessageSelection(e,v.selectedFolder.$messages[t])}function E(e){var t;v.selectedFolder.hasSelectedMessage()&&(t=w(e))>=0&&v.toggleMessageSelection(e,v.selectedFolder.$messages[t])}this.selectMessage=function(e){b.$virtualMode?i.go("mail.account.virtualMailbox.message",{mailboxId:h(e.$mailbox.path),messageId:e.uid}):i.go("mail.account.mailbox.message",{messageId:e.uid})},this.toggleMessageSelection=function(e,t){var n,s,i,o=v.selectedFolder;if(t||(t=o.$selectedMessage()),!t)return!0;if(t.selected=!t.selected,v.mode.multiple+=t.selected?1:-1,e.shiftKey&&o.$selectedCount()>1){for(s=(n=o.uidsMap[t.uid])-2;s>=0&&!o.$messages[s].selected;)s--;if(s<0)for(s=n+2;s<o.getLength()&&!o.$messages[s].selected;)s++;if(s>=0&&s<o.getLength())for(i=Math.min(n,s);i<=Math.max(n,s);i++)o.$messages[i].selected=!0}e.preventDefault(),e.stopPropagation()};function S(){return b.$virtualMode?v.selectedFolder.$mailboxes:[v.selectedFolder]}function A(e,t){var s,o,a=t;v.mode.multiple=v.selectedFolder.$selectedCount(),e?(t>0&&(a-=1,s=v.selectedFolder.$messages[a]),t<v.selectedFolder.$messages.length&&(o=v.selectedFolder.$messages[t]),s?s.isread&&o&&!o.isread&&(a=t,s=o):o&&(a=t,s=o),s?(v.selectedFolder.$topIndex=a,i.go("mail.account.mailbox.message",{messageId:s.uid})):i.go("mail.account.mailbox")):n(function(){console.warn("go to mailbox"),i.go("mail.account.mailbox")})}this.confirmDeleteSelectedMessages=function(e){var t=v.selectedFolder.$selectedMessages();null===v.messageDialog&&_.size(t)>0&&(v.messageDialog=m.confirm(l("Confirmation"),l("Are you sure you want to delete the selected messages?"),{ok:l("Delete")}).then(function(){var e=v.selectedFolder.hasSelectedMessage();v.selectedFolder.$deleteMessages(t).then(function(t){b.$virtualMode?e&&i.go("mail.account.virtualMailbox"):A(e,t)},function(n){v.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(){v.selectedFolder.$deleteMessages(t,{withoutTrash:!0}).then(function(t){b.$virtualMode?e&&i.go("mail.account.virtualMailbox"):A(e,t)})})})}).finally(function(){v.messageDialog=null})),e.preventDefault()},this.markOrUnMarkMessagesAsJunk=function(){var e=v.selectedFolder.hasSelectedMessage(),t=v.selectedFolder.$selectedMessages();0===_.size(t)&&e&&(t=[v.selectedFolder.$selectedMessage()]),_.size(t)>0&&v.selectedFolder.$markOrUnMarkMessagesAsJunk(t).then(function(){var n="/"+v.account.id+"/folderINBOX";"junk"!=v.selectedFolder.type&&(n="/"+v.account.$getMailboxByType("junk").id),v.selectedFolder.$moveMessages(t,n).then(function(t){b.$virtualMode?e&&i.go("mail.account.virtualMailbox"):A(e,t)})})},this.copySelectedMessages=function(e){var t=v.selectedFolder.$selectedMessages();_.size(t)>0&&v.selectedFolder.$copyMessages(t,"/"+e).then(function(){a.show(a.simple().content(l("%{0} message(s) copied",v.selectedFolder.$selectedCount())).position("top right").hideDelay(2e3))})},this.moveSelectedMessages=function(e){var t=v.selectedFolder.hasSelectedMessage(),n=v.selectedFolder.$selectedMessages(),s=v.selectedFolder.$selectedCount();_.size(n)>0&&v.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&&i.go("mail.account.virtualMailbox"):A(t,e)})},this.selectAll=function(){var e=0;_.forEach(S(),function(t){for(var n=0,s=t.$messages.length;n<s;n++)t.$messages[n].selected=!0;e+=s}),v.mode.multiple=e},this.unselectMessages=function(){_.forEach(S(),function(e){_.forEach(e.$messages,function(e){e.selected=!1})}),v.mode.multiple=0},this.markSelectedMessagesAsFlagged=function(){var e=v.selectedFolder.$selectedMessages();_.size(e)>0&&v.selectedFolder.$flagMessages(e,"\\Flagged","add").then(function(e){_.forEach(e,function(e){e.isflagged=!0})})},this.markSelectedMessagesAsUnread=function(){var e=v.selectedFolder.$selectedMessages();_.size(e)>0&&v.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=v.selectedFolder.$selectedMessages();_.size(e)>0&&v.selectedFolder.$flagMessages(e,"seen","add").then(function(e){_.forEach(e,function(e){e.isread||e.$mailbox.unseenCount--,e.isread=!0})})}}angular.module("SOGo.MailerUI").controller("MailboxController",e),t.$inject=["$delegate"];function t(e){return e[0].controller.prototype.resetScroll=function(){"messagesList"==this.$element.parent().attr("id")?this.updateSize():this.scrollTo(0)},e}angular.module("material.components.virtualRepeat").decorator("mdVirtualRepeatContainerDirective",t)}(),function(){"use strict";e.$inject=["$scope","$state","$transitions","$timeout","$window","$mdDialog","$mdToast","sgFocus","encodeUriFilter","Dialog","sgSettings","sgHotkeys","Account","Mailbox","VirtualMailbox","User","Preferences","stateAccounts"];function e(e,t,n,s,i,o,a,r,c,u,d,h,g,f,m,p,$,b){var v,y,M=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(),t=x,_.forEach(["backspace","delete"],function(e){t.push(h.createHotkey({key:e,description:l("Delete selected message or folder"),callback:function(){f.selectedFolderController&&f.selectedFolder&&f.selectedFolder.$isEditable&&!f.selectedFolder.hasSelectedMessage()&&f.selectedFolderController.confirmDelete(f.selectedFolder)}}))}),_.forEach(t,function(e){h.registerHotkey(e)});var t;e.$on("$destroy",function(){_.forEach(x,function(e){h.deregisterHotkey(e)})})};this.hideAdvancedSearch=function(){M.service.$virtualPath=!1,M.service.$virtualMode=!1,v=M.accounts[0],y=M.searchPreviousMailbox,t.go("mail.account.mailbox",{accountId:v.id,mailboxId:c(y.path)})},this.toggleAdvancedSearch=function(){if(f.selectedFolder.$isLoading)M.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)})};M.virtualMailbox=new m(M.accounts[0]),f.$virtualMode||(M.searchPreviousMailbox=f.selectedFolder),f.selectedFolder=M.virtualMailbox,f.$virtualMode=!0,angular.isDefined(f.$virtualPath)?(e=M.accounts[0].$getMailboxByPath(f.$virtualPath),n.push(e),M.search.subfolders&&e.children.length&&s(e.children)):n=M.accounts[0].$flattenMailboxes(),M.virtualMailbox.setMailboxes(n),M.virtualMailbox.startSearch(M.search.match,M.search.params),"mail.account.virtualMailbox"!=t.$current.name&&t.go("mail.account.virtualMailbox",{accountId:M.accounts[0].id})}},this.addSearchParam=function(e){return M.currentSearchParam=e,r("advancedSearch"),!1},this.newSearchParam=function(e){if(e.length&&M.currentSearchParam.length){var t=0,n=M.currentSearchParam;return e.startsWith("!")&&(t=1,e=e.substring(1).trim()),M.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(i).triggerHandler("resize")},150)},this.subscribe=function(e){o.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"];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})}},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){o.show({templateUrl:e.id+"/delegation",controller:t,controllerAs:"delegate",clickOutsideToClose:!0,escapeToClose:!0,locals:{User:p,account:e}}),t.$inject=["$scope","$mdDialog","User","account"];function t(e,t,n,s){var i=this;i.users=s.delegates,i.account=s,i.userToAdd="",i.searchText="",i.userFilter=function(e){return n.$filter(e,s.delegates)},i.closeModal=function(){t.hide()},i.removeUser=function(e){s.$removeDelegate(e.uid).catch(function(e,t){u.alert(l("Warning"),l("An error occured please try again."))})},i.addUser=function(e){e&&s.$addDelegate(e).then(function(){i.userToAdd="",i.searchText=""},function(e){u.alert(l("Warning"),e)})}}},this.refreshUnseenCount=function(){var e,t=i.unseenCountFolders;_.forEach(M.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(M.accounts,function(t){_.forEach(t.$$flattenMailboxes,function(t){e[t.id]&&(t.unseenCount=e[t.id])})})}),(e=$.defaults.SOGoRefreshViewCheck)&&"manually"!=e&&s(M.refreshUnseenCount,1e3*e.timeInterval())},this.isDroppableFolder=function(e,t){return t.id!=e.id&&!t.isNoSelect()},this.dragSelectedMessages=function(e,n,s){var i,o,r,c,u,d;i="/"+n.id,0===(o=e.$selectedMessages()).length&&(o=[e.$selectedMessage()]),r=_.map(o,"uid"),c=e.selectedMessage&&r.indexOf(e.selectedMessage)>=0,"copy"==s?(u=e.$copyMessages(o,i),d=l("%{0} message(s) copied",o.length)):(u=e.$moveMessages(o,i),d=l("%{0} message(s) moved",o.length)),u.then(function(){c&&t.go("mail.account.mailbox"),a.show(a.simple().content(d).position("top right").hideDelay(2e3))})}}angular.module("SOGo.MailerUI").controller("MailboxesController",e)}(),function(){"use strict";e.$inject=["$window","$scope","$state","$mdMedia","$mdDialog","sgConstant","stateAccounts","stateAccount","stateMailbox","stateMessage","sgHotkeys","encodeUriFilter","sgSettings","ImageGallery","sgFocus","Dialog","Preferences","Calendar","Component","Account","Mailbox","Message"];function e(e,t,n,s,i,o,a,r,c,u,d,h,g,f,m,p,$,b,v,y,M,x){var C=this,w=[];this.$onInit=function(){e.$messageController=C,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,C.showRawSource=!1,(s=w).push(d.createHotkey({key:l("hotkey_reply"),description:l("Reply to the message"),callback:E(angular.bind(C,C.reply))})),s.push(d.createHotkey({key:l("hotkey_replyall"),description:l("Reply to sender and all recipients"),callback:E(angular.bind(C,C.replyAll))})),s.push(d.createHotkey({key:l("hotkey_forward"),description:l("Forward selected message"),callback:E(angular.bind(C,C.forward))})),s.push(d.createHotkey({key:l("hotkey_flag"),description:l("Flagged"),callback:E(angular.bind(u,u.toggleFlag))})),_.forEach(["backspace","delete"],function(e){s.push(d.createHotkey({key:e,callback:E(function(e){0===C.mailbox.$selectedCount()&&C.deleteMessage(),e.preventDefault()})}))}),_.forEach(s,function(e){d.registerHotkey(e)});var s;e.opener?(t.$watchCollection(function(){return C.message.flags},function(e,t){var n;(e||t)&&(n=S()).messageCtrl&&n.messageCtrl.service.$timeout(function(){n.messageCtrl.showFlags=!0,n.messageCtrl.message.flags=e})}),t.$watch(function(){return C.message.isflagged},function(e,t){var n=S();n.mailboxCtrl&&n.mailboxCtrl.service.$timeout(function(){_.find(n.mailboxCtrl.selectedFolder.$messages,{uid:C.message.uid}).isflagged=e})})):t.$watchCollection(function(){return C.message.flags},function(e,t){var n,s,i;(e||t)&&(n=e||[],s=t||[],_.forEach(n,function(e,t){angular.isObject(e)&&(n[t]=e.name)}),n.length>s.length?(i=_.difference(n,s),_.forEach(i,function(e){C.message.addTag(e)})):n.length<s.length&&(i=_.difference(s,n),_.forEach(i,function(e){C.message.removeTag(e)})))}),t.$on("$destroy",function(){_.forEach(w,function(e){d.deregisterHotkey(e)})})};function I(){return t.mailbox?(arguments.length>0&&(t.mailbox.messageDialog=arguments[0]),t.mailbox.messageDialog):null}function E(e){return function(){if(null===I())return e.apply(C,arguments)}}function S(){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}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,i,a,r,l=S();l.messageCtrl?(e=l.mailboxCtrl.selectedFolder,t=l.messageCtrl.message,i=l.messageCtrl.$state):(e=c,t=u,i=n),e.$deleteMessages([t]).then(function(n){var l=n;if(t=null,angular.isDefined(i)){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(o["gt-md"])?(i.go("mail.account.mailbox.message",{messageId:a.uid}),l<e.$topIndex?e.$topIndex=l:l>e.$lastVisibleIndex&&(e.$topIndex=l-(e.$lastVisibleIndex-e.$topIndex))):i.go("mail.account.mailbox").then(function(){t=null,delete e.selectedMessage})}catch(e){}}C.closePopup()})};function A(e,t){null===I()&&I(i.show({parent:angular.element(document.body),targetEvent:e,clickOutsideToClose:!1,escapeToClose:!1,templateUrl:"UIxMailEditor",controller:"MessageEditorController",controllerAs:"editor",locals:{stateAccount:C.account,stateMessage:t}}).catch(_.noop).finally(function(){I(null),C.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(){C.message=null,delete c.selectedMessage})},this.reply=function(e){this._showMailEditorInPopup("reply")||A(e,this.message.$reply())},this.replyAll=function(e){this._showMailEditorInPopup("replyall")||A(e,this.message.$replyAll())},this.forward=function(e){this._showMailEditorInPopup("forward")||A(e,this.message.$forward())},this.edit=function(e){this._showMailEditorInPopup("edit")||this.message.$editableContent().then(function(){A(e,C.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),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.document.body.classList.contains("popup")&&e.close()},this.newMessage=function(e,t){e.stopPropagation(),e.preventDefault(),this.account.$newMessage({mailto:t}).then(function(t){A(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){C.message.$rawSource=e,C.showRawSource=!0})},this.print=function(t){e.print()},this.convertToEvent=function(e){return F(e,"appointment")},this.convertToTask=function(e){return F(e,"task")};function F(e,t){C.message.$plainContent().then(function(n){var s={pid:b.$defaultCalendar(),type:t,summary:n.subject,comment:n.content},o=new v(s),a=[g.activeUser("folderURL"),"Calendar","UIx"+t.capitalize()+"EditorTemplate"].join("/");return i.show({parent:angular.element(document.body),targetEvent:e,clickOutsideToClose:!0,escapeToClose:!0,templateUrl:a,controller:"ComponentEditorController",controllerAs:"editor",locals:{stateComponent:o}})})}}angular.module("SOGo.MailerUI").controller("MessageController",e)}(),function(){"use strict";e.$inject=["$scope","$window","$stateParams","$mdConstant","$mdUtil","$mdDialog","$mdToast","FileUploader","stateAccount","stateMessage","encodeUriFilter","$timeout","Dialog","AddressBook","Card","Preferences"];function e(e,t,n,s,i,o,a,r,c,u,d,h,g,f,m,p){var $=this;this.$onInit=function(){$.addRecipient=S,$.autocomplete={to:{},cc:{},bcc:{}},$.autosave=null,$.autosaveDrafts=A,$.cancel=x,$.contactFilter=E,$.isFullscreen=!1,$.hideBcc=0===u.editable.bcc.length,$.hideCc=0===u.editable.cc.length,$.identities=_.uniq(_.map(c.identities,"full")),$.message=u,$.recipientSeparatorKeys=[s.KEY_CODE.ENTER,s.KEY_CODE.TAB,s.KEY_CODE.COMMA,s.KEY_CODE.SEMICOLON],$.removeAttachment=M,$.save=C,$.send=w,$.sendState=!1,$.toggleFullscreen=I,$.uploader=new r({url:$.message.$absolutePath({asDraft:!0,withResourcePath:!0})+"/save",autoUpload:!0,alias:"attachments",removeAfterUpload:!1,onSuccessItem:function(e,t,n,s){$.message.$setUID(t.uid),$.message.$reload({asDraft:!1}),e.inlineUrl=t.lastAttachmentAttrs[0].url},onCancelItem:function(e,t,n,s){$.message.$deleteAttachment(e.file.name),this.removeFromQueue(e)},onErrorItem:function(e,t,n,s){a.show(a.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)}}),p.defaults.SOGoMailAutoSave&&($.autosave=h($.autosaveDrafts,1e3*p.defaults.SOGoMailAutoSave*60)),$.localeCode=p.defaults.LocaleCode,e.$on("$destroy",function(){$.uploader.destroy()}),"reply"==n.actionName?u.$reply().then(function(e){$.message=e,$.hideCc=!e.editable.cc||0===e.editable.cc.length,$.hideBcc=!e.editable.bcc||0===e.editable.bcc.length,v()}):"replyall"==n.actionName?u.$replyAll().then(function(e){$.message=e,$.hideCc=!e.editable.cc||0===e.editable.cc.length,$.hideBcc=!e.editable.bcc||0===e.editable.bcc.length,v()}):"forward"==n.actionName?u.$forward().then(function(e){$.message=e,v(),y()}):angular.isDefined(u)&&($.message=u,v(),y())};function b(){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==u.uid&&(n.draftMessageCtrl=t.opener.$messageController)):u.origin&&(e=u.origin.message,t.opener.$mailboxController.selectedFolder.$id()==e.$mailbox.$id()&&(n.originMailboxCtrl=t.opener.$mailboxController)))}catch(e){}return n}function v(){$.uploader.url=$.message.$absolutePath({asDraft:!0,withResourcePath:!0})+"/save"}function y(){var e,t,n,s=$.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 r.FileItem($.uploader,t)).progress=100,n.isUploaded=!0,n.isSuccess=!0,n.inlineUrl=s[e].url,$.uploader.queue.push(n)}function M(e,n){e.isUploading?$.uploader.cancelItem(e):($.message.$deleteAttachment(e.file.name),e.remove());var s=t.document.getElementById(n);s&&angular.element(s).prop("value",null)}function x(){$.autosave&&h.cancel($.autosave),$.message.isNew&&$.message.attachmentAttrs&&$.message.$mailbox.$deleteMessages([$.message]),o.cancel()}function C(){var e=b();$.message.$save().then(function(t){$.message.$rawSource=null,e.draftMailboxCtrl&&e.draftMailboxCtrl.selectedFolder.$filter().then(function(){e.draftMessageCtrl&&e.draftMessageCtrl.$state.go("mail.account.mailbox.message",{messageId:$.message.uid})}),a.show(a.simple().content(l("Your email has been saved")).position("top right").hideDelay(3e3))})}function w(){$.sendState="sending",$.autosave&&h.cancel($.autosave),$.message.$send().then(function(e){var t=b();$.sendState="sent",t.draftMailboxCtrl&&t.draftMailboxCtrl.selectedFolder.$filter().then(function(){t.draftMessageCtrl&&t.draftMessageCtrl.close()}),t.originMailboxCtrl&&t.originMailboxCtrl.selectedFolder.$filter(),a.show(a.simple().content(l("Your email has been sent")).position("top right").hideDelay(3e3)),h(o.hide,1e3)},function(e){h(function(){$.sendState="error",$.errorMessage=e.data?e.data.message:e.statusText})})}function I(){$.isFullscreen=!$.isFullscreen}function E(e){return f.$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})})}function S(e,t){var n,s,i,o,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=$.message.editable[t],angular.isString(e)){for(a="",o=0;o<e.length;o++)9!=e.charCodeAt(o)&&32!=e.charCodeAt(o)&&44!=e.charCodeAt(o)&&59!=e.charCodeAt(o)||!r.test(a)?a+=e.charAt(o):(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())}):(i=m.$find(e.container,e.c_name)).$id().then(function(e){_.forEach(i.refs,function(e){e.email.length&&n.push(e.$shortFormat())})}):s=e.$shortFormat(),s||null}function A(){$.message.$save(),p.defaults.SOGoMailAutoSave&&($.autosave=h($.autosaveDrafts,1e3*p.defaults.SOGoMailAutoSave*60))}}t.$inject=["$scope","$mdToast"];function t(e,t){e.closeToast=function(){t.hide()}}angular.module("SOGo.MailerUI").controller("SendMessageToastController",t).controller("MessageEditorController",e)}(),function(){e.$inject=["$element","$transitions","$state","$mdMedia","$mdSidenav","sgConstant","Mailbox","encodeUriFilter"];function e(e,t,n,s,i,o,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(o["gt-md"])||i("left").close()}}angular.module("SOGo.MailerUI").controller("sgAccountController",e).directive("sgAccountSection",function(){return{restrict:"C",scope:{},controller:"sgAccountController"}})}(),function(){"use strict";e.$inject=["$scope","User"];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)}}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(){e.$inject=["$scope","$element","$state","$timeout","$mdToast","$mdPanel","$mdMedia","$mdSidenav","sgConstant","Dialog","Mailbox","encodeUriFilter"];function e(e,t,n,s,i,o,a,r,c,u,d,h){var g=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!==d.selectedFolder&&d.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==d.selectedFolder||this.mailbox.isNoSelect()||(d.$virtualPath=!1,d.$virtualMode=!1,this.accountController.selectFolder(this),e&&(n.go("mail.account.mailbox",{accountId:this.mailbox.$account.id,mailboxId:h(this.mailbox.path)}),e.stopPropagation(),e.preventDefault()))},this.unselectFolder=function(){t[0].classList.remove("md-bg")},this.editFolder=function(e){e.stopPropagation(),e.preventDefault(),this.editMode=!0,this.inputElement.value=this.mailbox.name,this.clickableElement.classList.add("ng-hide"),this.inputContainer.classList.remove("ng-hide"),"touchend"==e.srcEvent.type?s(function(){g.inputElement.select(),g.inputElement.focus()},200):(this.inputElement.select(),this.inputElement.focus()),this.panel&&this.panel.close()},this.saveFolder=function(e){this.inputElement.disabled||(this.mailbox.name=this.inputElement.value,this.inputElement.disabled=!0,this.mailbox.$rename().then(function(e){g.editMode=!1,g.inputContainer.classList.add("ng-hide"),g.clickableElement.classList.remove("ng-hide")}).finally(function(){g.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(){u.confirm(l("Warning"),l("Do you really want to move this folder into the trash ?"),{ok:l("Delete")}).then(function(){g.mailbox.$delete().then(function(){n.go("mail.account.inbox")},function(e){u.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(){g.mailbox.$delete({withoutTrash:!0}).then(function(){n.go("mail.account.inbox")},function(e){u.alert(l('An error occured while deleting the mailbox "%{0}".',g.mailbox.name),l(e.error))})})})})},this.showMenu=function(e){var t=o.newPanelPosition().relativeTo(this.moreOptionsButton).addPanelPosition(o.xPosition.ALIGN_START,o.yPosition.ALIGN_TOPS),n=o.newPanelAnimation().openFrom(this.moreOptionsButton).duration(100).withAnimation(o.animation.FADE),s={attachTo:angular.element(document.body),locals:{itemCtrl:this,folder:this.mailbox,editFolder:angular.bind(this,this.editFolder),confirmDelete:angular.bind(this,this.confirmDelete)},bindToController:!0,controller:h,controllerAs:"$menuCtrl",position:t,animation:n,targetEvent:e,templateUrl:"UIxMailFolderMenu",trapFocus:!0,clickOutsideToClose:!0,escapeToClose:!0,focusOnOpen:!0};o.open(s).then(function(e){g.panel=e,e.panelEl.one("click",function(){e.close()})}),h.$inject=["mdPanelRef","$state","$mdDialog","User"];function h(e,t,n,s){var o=this;this.markFolderRead=function(){this.folder.$markAsRead()},this.newFolder=function(){u.prompt(l("New Folder..."),l("Enter the new name of your folder")).then(function(e){o.folder.$newMailbox(o.folder.id,e).then(function(){},function(t,n){u.alert(l('An error occured while creating the mailbox "%{0}".',e),l(t.error))})})},this.compactFolder=function(){this.folder.$compact().then(function(){i.show(i.simple().content(l("Folder compacted")).position("top right").hideDelay(3e3))})},this.emptyTrashFolder=function(){this.folder.$emptyTrash().then(function(){i.show(i.simple().content(l("Trash emptied")).position("top right").hideDelay(3e3))})},this.showAdvancedSearch=function(){d.$virtualPath=this.folder.path,a(c["gt-md"])||r("left").close()},this.share=function(){this.folder.$acl.$users().then(function(){n.show({templateUrl:o.folder.id+"/UIxAclEditor",controller:"AclController",controllerAs:"acl",clickOutsideToClose:!0,escapeToClose:!0,locals:{usersWithACL:o.folder.$acl.users,User:s,folder:o.folder}})})},this.setFolderAs=function(e){this.folder.$setFolderAs(e).then(function(){o.folder.$account.$getMailboxes({reload:!0})})}}}}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(){e.$inject=["$scope","$element","Mailbox"];function e(e,t,n){var s=this;this.$onInit=function(){var t=["uid","isread","isflagged","flags","subject"];this.MailboxService=n,"draft"==n.selectedFolder.type&&t.push("subject"),e.$watch(function(){return s.message?[_.pick(s.message,t)]: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")}}angular.module("SOGo.MailerUI").controller("sgMessageListItemController",e).directive("sgMessageListItem",function(){return{restrict:"C",scope:{},bindToController:{message:"=sgMessage"},controller:"sgMessageListItemController"}})}(),function(){e.$inject=["$scope","$element","$parse","$state","$mdUtil","$mdToast","Mailbox","Message","encodeUriFilter"];function e(e,t,n,s,i,o,a,r,l){var c=this;this.$postLink=function(){var n,s,o,l;this.parentController=e.parentController,o=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=i.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,o)()},this.service=r,this.MailboxService=a}}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";e.$inject=["$element","ImageGallery"];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)}}angular.module("SOGo.MailerUI").directive("sgZoomableImage",function(){return{restrict:"A",bindToController:{partIndex:"=sgZoomableImage"},controller:e}})}();
//# sourceMappingURL=Mailer.services.js.map