sogo/UI/WebServerResources/js/Mailer.services.js
2017-05-13 01:24:30 -04:00

2 lines
54 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,o,a,s,i,r,l){return angular.extend(e,{$q:t,$timeout:n,$log:o,$$resource:new s(a.activeUser("folderURL")+"Mail",a.activeUser()),$Preferences:i,$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,o){t.id=o,n[o]=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){return n.$mailboxes=t,n.$expanded=!1,e.$Preferences.ready().then(function(){var t,o=function(e){_.forEach(e,function(e){e.$expanded=t.indexOf("/"+e.id)>=0,e.children&&e.children.length>0&&o(e.children)})};e.$Preferences.settings.Mail.ExpandedFolders&&(t=angular.isString(e.$Preferences.settings.Mail.ExpandedFolders)?angular.fromJson(e.$Preferences.settings.Mail.ExpandedFolders):e.$Preferences.settings.Mail.ExpandedFolders,n.$expanded=t.indexOf("/"+n.id)>=0,t.length>0&&o(n.$mailboxes)),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=this,o=[],a=[],s=function(e){_.forEach(e,function(e){o.push(e),(t&&t.all||e.$expanded)&&e.children&&e.children.length>0&&s(e.children)})};return!this.$$flattenMailboxes||t&&(t.reload||t.all)?(s(this.$mailboxes),t&&t.all||(n.$$flattenMailboxes=o,t&&t.saveState&&(_.forEach(e.$accounts,function(e){e.$expanded&&a.push("/"+e.id),_.reduce(e.$$flattenMailboxes,function(e,t){return t.$expanded&&e.push("/"+t.id),e},a)}),e.$$resource.post(null,"saveFoldersState",a)))):o=this.$$flattenMailboxes,o},e.prototype.$getMailboxByType=function(e){var t=function(n){var o=_.find(n,function(t){return t.type==e});return o||angular.forEach(n,function(e){!o&&e.children&&e.children.length>0&&(o=t(e.children))}),o};return t(this.$mailboxes)},e.prototype.$getMailboxByPath=function(e){var t=function(n){var o=_.find(n,function(t){return t.path==e});return o||angular.forEach(n,function(e){!o&&e.children&&e.children.length>0&&(o=t(e.children))}),o};return t(this.$mailboxes)},e.prototype.$newMailbox=function(t,n){var o=this;return e.$$resource.post(t.toString(),"createFolder",{name:n}).then(function(){o.$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(){var t=this;return e.$$resource.fetch(this.id.toString(),"compose").then(function(n){return e.$log.debug("New message (compose): "+JSON.stringify(n,void 0,2)),new e.$Message(n.accountId,t.$getMailboxByPath(n.mailboxPath),n)}).then(function(t){return e.$$resource.fetch(t.$absolutePath({asDraft:!0}),"edit").then(function(n){return e.$log.debug("New message (edit): "+JSON.stringify(n,void 0,2)),angular.extend(t.editable,n),t.isNew=!0,t})})},e.prototype.$addDelegate=function(t){var n=this,o=e.$q.defer(),a={uid:t.uid};return!t.uid||_.indexOf(_.map(this.delegates,"uid"),t.uid)>-1?o.resolve():e.$$resource.fetch(this.id.toString(),"addDelegate",a).then(function(){n.delegates.push(t),o.resolve(n.users)},function(e,t){o.reject(l("An error occured please try again."))}),o.promise},e.prototype.$removeDelegate=function(t){var n=this,o={uid:t};return e.$$resource.fetch(this.id.toString(),"removeDelegate",o).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 o=e.$$resource.create("createFolder",this.name);this.$unwrap(o)}}else this.$unwrap(n)}e.$factory=["$q","$timeout","$log","sgSettings","Resource","Message","Acl","Preferences","sgMailbox_PRELOAD",function(t,n,o,a,s,i,r,l,c){return angular.extend(e,{$q:t,$timeout:n,$log:o,$$resource:new s(a.activeUser("folderURL")+"Mail",a.activeUser()),$Message:i,$$Acl:r,$Preferences:l,$query:{sort:"arrival",asc:0},selectedFolder:null,$refreshTimeout:null,$virtualMode:!1,PRELOAD:c}),l.ready().then(function(){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 o;return o=n&&n.all?this.$$resource.fetch(t.id.toString(),"viewAll"):this.$$resource.fetch(t.id.toString(),"view"),e.$unwrapCollection(t,o)},e.$unwrapCollection=function(t,n){var o=[],a=function(n,o){for(var s=0;s<o.children.length;s++)o.children[s].level=n,o.children[s]=new e(t,o.children[s]),a(n+1,o.children[s])};return n.then(function(n){return e.$timeout(function(){return angular.forEach(n.mailboxes,function(n,s){n.level=0;var i=new e(t,n);a(1,i),o.push(i)}),n.quotas&&t.updateQuota(n.quotas),o})})},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 o=this,a={};return angular.isDefined(this.unseenCount)||(this.unseenCount=0),e.$timeout(function(){o.$isLoading=!0}),e.$Preferences.ready().then(function(){if(e.$refreshTimeout&&e.$timeout.cancel(e.$refreshTimeout),t&&angular.extend(e.$query,t),angular.extend(a,{sortingAttributes:e.$query}),angular.isDefined(n)&&(a.filters=_.reject(n,function(e){return!e.searchInput||0===e.searchInput.length}),_.forEach(a.filters,function(e){var t,n=e.searchBy.match(/(\w+)_or_(\w+)/);n&&(a.sortingAttributes.match="OR",e.searchBy=n[1],(t=angular.copy(e)).searchBy=n[2],a.filters.push(t))})),!e.$virtualMode){var s=e.$Preferences.defaults.SOGoRefreshViewCheck;if(s&&"manually"!=s){var i=angular.bind(o,e.prototype.$filter,null,n);e.$refreshTimeout=e.$timeout(i,1e3*s.timeInterval())}}var r=e.$$resource.post(o.id,"view",a);return o.$unwrap(r)})},e.prototype.$loadMessage=function(t){var n,o,a,s,i=this.uidsMap[t],r=this.$messages.length,l=!1;if(angular.isDefined(this.uidsMap[t])&&i<this.$messages.length&&(angular.isDefined(this.$messages[i].subject)&&(l=!0),n=Math.min(i+e.PRELOAD.LOOKAHEAD,r-1),angular.isDefined(this.$messages[n].subject)||angular.isDefined(this.$messages[n].loading)?(o=Math.max(i-e.PRELOAD.LOOKAHEAD,0),angular.isDefined(this.$messages[o].subject)||angular.isDefined(this.$messages[o].loading)||(n=i,i=Math.max(i-e.PRELOAD.SIZE,0))):n=Math.min(i+e.PRELOAD.SIZE,r-1),!angular.isDefined(this.$messages[i].subject)&&!angular.isDefined(this.$messages[i].loading)||!angular.isDefined(this.$messages[n].subject)&&!angular.isDefined(this.$messages[n].loading))){for(a=[];i<n&&i<r;i++)angular.isDefined(this.$messages[i].subject)||this.$messages[i].loading?n++:(a.push(this.$messages[i].uid),this.$messages[i].loading=!0);e.$log.debug("Loading UIDs "+a.join(" ")),s=e.$$resource.post(this.id,"headers",{uids:a}),this.$unwrapHeaders(s)}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.$rename=function(){var t,n,o,a,s=this;return this.name==this.$shadowData.name?e.$q.when():(t=function(e,n){var o=null;return _.find(n,function(e){return e.path==s.path})?o=e:angular.forEach(n,function(e){!o&&e.children&&e.children.length>0&&(o=t(e,e.children))}),o},n=t(null,this.$account.$mailboxes),o=null===n?this.$account.$mailboxes:n.children,a=_.indexOf(_.map(o,"id"),this.id),this.$save().then(function(t){var n,i=s.path;s.init(t),o.splice(a,1),n=_.find(o,function(t){return e.$log.debug(t.name+" ? "+s.name),"folder"==t.type&&t.name.localeCompare(s.name)>0}),a=n?_.indexOf(_.map(o,"id"),n.id):o.length,o.splice(a,0,s);var r=new RegExp("^"+i),l=function(e){_.forEach(e.children,function(e){e.path=e.path.replace(r,s.path),e.id=e.$id(),l(e)})};l(s)}))},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(){return e.$$resource.post(this.id,"markRead")},e.prototype.$flagMessages=function(t,n,o){var a={msgUIDs:_.map(t,"uid"),flags:n,operation:o};return e.$$resource.post(this.id,"addOrRemoveLabel",a).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,o=this,a=this.$messages.length;return n=_.filter(t,function(e,t){return!e.isread}),this.unseenCount-=n.length,_.forEachRight(this.$messages,function(t,n){var s=_.findIndex(e,function(e){return t.uid==e});s>-1?(e.splice(s,1),delete o.uidsMap[t.uid],t.uid==o.selectedMessage&&delete o.selectedMessage,o.$messages.splice(n,1),n<a&&(a=n)):o.uidsMap[t.uid]-=e.length}),a},e.prototype.$deleteMessages=function(t,n){var o,a,s=this;return o=_.map(t,"uid"),a={uids:o},n&&angular.extend(a,n),e.$$resource.post(this.id,"batchDelete",a).then(function(e){return e.quotas&&s.$account.updateQuota(e.quotas),s.$_deleteMessages(o,t)})},e.prototype.$markOrUnMarkMessagesAsJunk=function(t){var n=_.map(t,"uid"),o="junk"==this.type?"markMessagesAsNotJunk":"markMessagesAsJunk";return e.$$resource.post(this.id,o,{uids:n})},e.prototype.$copyMessages=function(t,n){var o=this,a=_.map(t,"uid");return e.$$resource.post(this.id,"copyMessages",{uids:a,folder:n}).then(function(e){e.quotas&&o.$account.updateQuota(e.quotas)})},e.prototype.$moveMessages=function(t,n){var o,a=this;return o=_.map(t,"uid"),e.$$resource.post(this.id,"moveMessages",{uids:o,folder:n}).then(function(){return a.$_deleteMessages(o,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,o=e.$q.defer();return this.$futureMailboxData=t,this.$futureMailboxData.then(function(t){e.$timeout(function(){var a,s;(!t.uids||n.$topIndex>t.uids.length-1)&&(n.$topIndex=0),n.init(t),n.uids&&(e.$log.debug("unwrapping "+n.uids.length+" messages"),s=_.invokeMap(n.headers[0],"toLowerCase"),n.headers.splice(0,1),n.threaded&&(a=n.uids[0],n.uids.splice(0,1)),_.reduce(n.uids,function(t,o,s){var i;return i=n.threaded?_.zipObject(a,o):{uid:o.toString()},n.uidsMap[i.uid]=s,t.push(new e.$Message(n.$account.id,n,i,!0)),t},n.$messages),_.forEach(n.headers,function(e){var t=_.zipObject(s,e),o=n.uidsMap[t.uid.toString()];_.extend(n.$messages[o],t)})),e.$log.debug("mailbox "+n.id+" ready"),n.$isLoading=!1,o.resolve(n.$messages)})},function(e){angular.extend(n,e),n.isError=!0,o.reject()}),o.promise},e.prototype.$unwrapHeaders=function(t){var n=this;t.then(function(t){e.$timeout(function(){var e,o;t.length>0&&(e=_.invokeMap(t[0],"toLowerCase"),t.splice(0,1),_.forEach(t,function(t){t=_.zipObject(e,t),o=n.uidsMap[t.uid.toString()],angular.isDefined(o)&&_.extend(n.$messages[o],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,o){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(o)&&o||(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,o,a,s,i,r){return angular.extend(e,{STATUS:s,$q:t,$timeout:n,$log:o,$$resource:new i(a.activeUser("folderURL")+"Mail",a.activeUser()),$avatar:angular.bind(r,r.avatar)}),r.ready().then(function(){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 o=new RegExp(t,"i"),a=[];return _.forEach(_.keys(e.$tags),function(t){var s=e.$tags[t];-1!=s[0].search(o)&&(_.includes(n,t)||a.push({name:t,description:s[0],color:s[1]}))}),a},e.prototype.$absolutePath=function(t){function n(){var e;return(e=_.map(o.$mailbox.path.split("/"),function(e){return"folder"+e.asCSSIdentifier()})).splice(0,0,o.accountId),e.join("/")}var o=this,a=this.id;return(angular.isUndefined(this.id)||t&&t.nocache)&&(this.id=n()+"/"+this.uid,a=this.id),t&&t.asDraft&&this.draftId&&(a=n()+"/"+this.draftId),t&&t.withResourcePath&&(a=e.$$resource.path(a)),a},e.prototype.$setUID=function(e){var t,n=this.uid||-1,o=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){o.$mailbox.$messages[t][e]=o[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(o){_.forEach(t[o],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=[],o=0,a=0;return _.forEach(["to","cc","bcc"],function(s){a+=t[s]?t[s].length:0,_.forEach(t[s],function(t,a){o<e&&n.push(t.shortname),o++})}),a>e&&n.push(l("and %{0} more...",a-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=[],o=function(a){if(a.msgclass="msg-attachment-other","UIxMailPartAlternativeViewer"==a.type)o(_.find(a.content,function(e){return a.preferredPart==e.contentType}));else if(angular.isArray(a.content)){if("UIxMailPartSignedViewer"==a.type&&1===a["supports-smime"]){var s="<p>"+a.error.replace(/\n/,'</p><p class="md-caption">');s=s.replace(/\n/g,'</p><p class="md-caption">')+"</p>",t.$smime={validSignature:a.valid,message:s}}_.forEach(a.content,function(e){o(e)})}else angular.isUndefined(a.safeContent)&&(a.safeContent=a.content,t.$hasUnsafeContent|=a.safeContent.indexOf(" unsafe-")>-1),"UIxMailPartHTMLViewer"==a.type?(a.html=!0,t.$loadUnsafeContent||e.$displayRemoteInlineImages?(angular.isUndefined(a.unsafeContent)&&(a.unsafeContent=document.createElement("div"),a.unsafeContent.innerHTML=a.safeContent,angular.forEach(["src","data","classid","background","style"],function(e){var t,n,o,s=a.unsafeContent.querySelectorAll("[unsafe-"+e+"]");for(o=0;o<s.length;o++)n=(t=angular.element(s[o])).attr("unsafe-"+e),t.attr(e,n),t.removeAttr("unsafe-"+e)}),t.$hasUnsafeContent=!1),a.content=a.unsafeContent.innerHTML):a.content=a.safeContent,n.push(a)):"UIxMailPartICalViewer"==a.type||"UIxMailPartImageViewer"==a.type||"UIxMailPartLinkViewer"==a.type?("UIxMailPartImageViewer"==a.type?a.msgclass="msg-attachment-image":"UIxMailPartLinkViewer"==a.type&&(a.msgclass="msg-attachment-link"),a.compile=!0,n.push(a)):(a.html=!0,a.content=a.safeContent,n.push(a))};return this.parts&&o(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 o=_.find(t.$mailbox.$account.identities,function(e){return-1!==n.from.toLowerCase().indexOf(e.email)});return o&&(n.from=o.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 o={operation:t,msgUIDs:[this.uid],flags:n};if(n)return e.$$resource.post(this.$mailbox.$id(),"addOrRemoveLabel",o)},e.prototype.$imipAction=function(t,n,o){var a=this;e.$$resource.post([this.$absolutePath(),t].join("/"),n,o).then(function(t){e.$timeout(function(){a.$reload()})})},e.prototype.$sendMDN=function(){return this.shouldAskReceipt=0,e.$$resource.post(this.$absolutePath(),"sendMDN")},e.prototype.$deleteAttachment=function(t){var n={filename:t},o=this;e.$$resource.fetch(this.$absolutePath({asDraft:!0}),"deleteAttachment",n).then(function(n){e.$timeout(function(){o.editable.attachmentAttrs=_.filter(o.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,o=this;return t&&t.useCache&&this.$futureMessageData?(this.isread||e.$$resource.fetch(this.$absolutePath(),"markMessageRead").then(function(){e.$timeout(function(){o.isread=!0,o.$mailbox.unseenCount--})}),this):(n=e.$$resource.fetch(this.$absolutePath(t),"view"),this.$unwrap(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(o){var a,s;return e.$log.debug("New "+t+": "+JSON.stringify(o,void 0,2)),a=n.$mailbox.$account.$getMailboxByPath(o.mailboxPath),s=new e(o.accountId,a,o),e.$$resource.fetch(s.$absolutePath({asDraft:!0}),"edit").then(function(o){return e.$log.debug("New "+t+": "+JSON.stringify(o,void 0,2)+" original UID: "+n.uid),angular.extend(s.editable,o),s.origin={message:n,action:t},s})})},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,o){("constructor"!=o&&"$"!=o[0]||n)&&(t[o]=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(e){this.$account=e}e.$factory=["$q","$timeout","$log","sgSettings","Resource","Message","Mailbox","sgMailbox_PRELOAD",function(t,n,o,a,s,i,r,l){return angular.extend(e,{$q:t,$timeout:n,$log:o,$$resource:new s(a.activeUser("folderURL")+"Mail",a.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 o=this,a=e.$q.when();this.$isLoading=!0,_.forEach(this.$mailboxes,function(s){a=a.then(function(){if(o.$isLoading)return e.$log.debug("searching mailbox "+s.path),s.$filter({sort:"date",asc:!1,match:t},n)})}),a.finally(function(){o.$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,o,a,s;if(angular.isDefined(this.$mailboxes)&&e>=0)for(t=0,n=0;n<this.$mailboxes.length;n++)for(a=this.$mailboxes[n],o=0;o<a.$messages.length;t++,o++)if(s=a.$messages[o],t==e&&a.$loadMessage(s.uid))return s;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,o){var a={flags:n,operation:o},s=[],i=[];return _.forEach(t,function(t,n){if(t.length>0){var o=_.map(t,"uid");s.push(t);var r=e.$$resource.post(n,"addOrRemoveLabel",_.assign(a,{msgUIDs:o}));i.push(r)}}),e.$q.all(i).then(function(){return _.flatten(s)})},e.prototype.$deleteMessages=function(t){var n=[];return _.forEach(t,function(e,t){if(e.length>0){var o=e[0].$mailbox.$deleteMessages(e);n.push(o)}}),e.$q.all(n)},e.prototype.$markOrUnMarkMessagesAsJunk=function(t){var n=[];return _.forEach(t,function(e,t){if(e.length>0){var o=e[0].$mailbox.$markOrUnMarkMessagesAsJunk(e);n.push(o)}}),e.$q.all(n)},e.prototype.$copyMessages=function(t,n){var o=[];return _.forEach(t,function(e,t){if(e.length>0){var a=e[0].$mailbox.$copyMessages(e,n);o.push(a)}}),e.$q.all(o)},e.prototype.$moveMessages=function(t,n){var o=[];return _.forEach(t,function(e,t){if(e.length>0){var a=e[0].$mailbox.$moveMessages(e,n);o.push(a)}}),e.$q.all(o)}}(),function(){"use strict";function e(e,t,n,o,a,s,i,r,c,u,d,f,h,g,$,p,m){function b(e){return H.selectedFolder.$compact()}function v(e){H.selectedFolder.$filter({sort:e})}function M(e){return m.$query.sort==e}function y(){H.mode.search=!0,g("search")}function x(){H.mode.search=!1,H.selectedFolder.$filter().then(function(){H.selectedFolder.selectedMessage&&n(function(){H.selectedFolder.$topIndex=H.selectedFolder.uidsMap[H.selectedFolder.selectedMessage]})})}function w(e,t){var n;null===H.messageDialog&&(t?S():(n=H.account.$newMessage(),H.messageDialog=s.show({parent:angular.element(document.body),targetEvent:e,clickOutsideToClose:!1,escapeToClose:!1,templateUrl:"UIxMailEditor",controller:"MessageEditorController",controllerAs:"editor",locals:{stateAccount:H.account,stateMessage:n}}).finally(function(){H.messageDialog=null})))}function S(){var t=[h.baseURL(),"UIxMailPopupView#!/Mail",H.account.id,f(f(H.selectedFolder.path)),"new"].join("/"),n=H.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(","))}function C(e){var t=H.selectedFolder.$selectedMessageIndex();return angular.isDefined(t)?(t--,H.selectedFolder.$topIndex>0&&H.selectedFolder.$topIndex--):(t=H.selectedFolder.getLength()-1,H.selectedFolder.$topIndex=H.selectedFolder.getLength()),t>-1&&I(H.selectedFolder.$messages[t]),e.preventDefault(),t}function D(e){var t=H.selectedFolder.$selectedMessageIndex();return angular.isDefined(t)?(t++,H.selectedFolder.$topIndex<H.selectedFolder.getLength()&&H.selectedFolder.$topIndex++):t=0,t<H.selectedFolder.getLength()?I(H.selectedFolder.$messages[t]):t=-1,e.preventDefault(),t}function A(e){var t;H.selectedFolder.hasSelectedMessage()&&(t=C(e))>=0&&E(e,H.selectedFolder.$messages[t])}function F(e){var t;H.selectedFolder.hasSelectedMessage()&&(t=D(e))>=0&&E(e,H.selectedFolder.$messages[t])}function I(e){m.$virtualMode?a.go("mail.account.virtualMailbox.message",{mailboxId:f(e.$mailbox.path),messageId:e.uid}):a.go("mail.account.mailbox.message",{messageId:e.uid})}function E(e,t){var n,o,a,s=H.selectedFolder;if(t||(t=s.$selectedMessage()),t.selected=!t.selected,H.mode.multiple+=t.selected?1:-1,e.shiftKey&&s.$selectedCount()>1){for(o=(n=s.uidsMap[t.uid])-2;o>=0&&!s.$messages[o].selected;)o--;if(o<0)for(o=n+2;o<s.getLength()&&!s.$messages[o].selected;)o++;if(o>=0&&o<s.getLength())for(a=Math.min(n,o);a<=Math.max(n,o);a++)s.$messages[a].selected=!0}e.preventDefault(),e.stopPropagation()}function k(){return m.$virtualMode?H.selectedFolder.$mailboxes:[H.selectedFolder]}function O(e,t){var o,s,i=t;H.mode.multiple=H.selectedFolder.$selectedCount(),e?(t>0&&(i-=1,o=H.selectedFolder.$messages[i]),t<H.selectedFolder.$messages.length&&(s=H.selectedFolder.$messages[t]),o?o.isread&&s&&!s.isread&&(i=t,o=s):s&&(i=t,o=s),o?(H.selectedFolder.$topIndex=i,a.go("mail.account.mailbox.message",{messageId:o.uid})):a.go("mail.account.mailbox")):n(function(){console.warn("go to mailbox"),a.go("mail.account.mailbox")})}function U(e){var t=H.selectedFolder.$selectedMessages();null===H.messageDialog&&_.size(t)>0&&(H.messageDialog=$.confirm(l("Confirmation"),l("Are you sure you want to delete the selected messages?"),{ok:l("Delete")}).then(function(){var e=H.selectedFolder.hasSelectedMessage();H.selectedFolder.$deleteMessages(t).then(function(t){m.$virtualMode?e&&a.go("mail.account.virtualMailbox"):O(e,t)},function(n){H.messageDialog=$.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(){H.selectedFolder.$deleteMessages(t,{withoutTrash:!0}).then(function(t){m.$virtualMode?e&&a.go("mail.account.virtualMailbox"):O(e,t)})})})}).finally(function(){H.messageDialog=null})),e.preventDefault()}function T(){var e=H.selectedFolder.hasSelectedMessage(),t=H.selectedFolder.$selectedMessages();0===_.size(t)&&e&&(t=[H.selectedFolder.$selectedMessage()]),_.size(t)>0&&H.selectedFolder.$markOrUnMarkMessagesAsJunk(t).then(function(){var n="/"+H.account.id+"/folderINBOX";"junk"!=H.selectedFolder.type&&(n="/"+H.account.$getMailboxByType("junk").id),H.selectedFolder.$moveMessages(t,n).then(function(t){m.$virtualMode?e&&a.go("mail.account.virtualMailbox"):O(e,t)})})}function P(e){var t=H.selectedFolder.$selectedMessages();_.size(t)>0&&H.selectedFolder.$copyMessages(t,"/"+e).then(function(){i.show(i.simple().content(l("%{0} message(s) copied",H.selectedFolder.$selectedCount())).position("top right").hideDelay(2e3))})}function L(e){var t=H.selectedFolder.hasSelectedMessage(),n=H.selectedFolder.$selectedMessages(),o=H.selectedFolder.$selectedCount();_.size(n)>0&&H.selectedFolder.$moveMessages(n,"/"+e).then(function(e){i.show(i.simple().content(l("%{0} message(s) moved",o)).position("top right").hideDelay(2e3)),m.$virtualMode?t&&a.go("mail.account.virtualMailbox"):O(t,e)})}function R(){var e=0;_.forEach(k(),function(t){for(var n=0,o=t.$messages.length;n<o;n++)t.$messages[n].selected=!0;e+=o}),H.mode.multiple=e}function N(){_.forEach(k(),function(e){_.forEach(e.$messages,function(e){e.selected=!1})}),H.mode.multiple=0}function j(){var e=H.selectedFolder.$selectedMessages();_.size(e)>0&&H.selectedFolder.$flagMessages(e,"\\Flagged","add").then(function(e){_.forEach(e,function(e){e.isflagged=!0})})}function q(){var e=H.selectedFolder.$selectedMessages();_.size(e)>0&&H.selectedFolder.$flagMessages(e,"seen","remove").then(function(e){_.forEach(e,function(e){e.isread&&e.$mailbox.unseenCount++,e.isread=!1})})}function G(){var e=H.selectedFolder.$selectedMessages();_.size(e)>0&&H.selectedFolder.$flagMessages(e,"seen","add").then(function(e){_.forEach(e,function(e){e.isread||e.$mailbox.unseenCount--,e.isread=!0})})}var H=this,z=angular.element(e.document).find("title").attr("sg-default")||"SOGo",B=[];e.$mailboxController=H,H.service=m,H.accounts=r,H.account=c,H.selectedFolder=u,H.selectMessage=I,H.messageDialog=null,H.toggleMessageSelection=E,H.sort=v,H.sortedBy=M,H.searchMode=y,H.cancelSearch=x,H.newMessage=w,H.mode={search:!1,multiple:0},H.confirmDeleteSelectedMessages=U,H.markOrUnMarkMessagesAsJunk=T,H.copySelectedMessages=P,H.moveSelectedMessages=L,H.markSelectedMessagesAsFlagged=j,H.markSelectedMessagesAsUnread=q,H.markSelectedMessagesAsRead=G,H.selectAll=R,H.unselectMessages=N,u.selectFolder(),function(e){e.push(d.createHotkey({key:l("hotkey_search"),description:l("Search"),callback:y})),e.push(d.createHotkey({key:l("hotkey_compose"),description:l("Write a new message"),callback:function(e){null===H.messageDialog&&w(e)}})),e.push(d.createHotkey({key:l("hotkey_junk"),description:l("Mark the selected messages as junk"),callback:T})),e.push(d.createHotkey({key:"space",description:l("Toggle item"),callback:E})),e.push(d.createHotkey({key:"shift+space",description:l("Toggle range of items"),callback:E})),e.push(d.createHotkey({key:"up",description:l("View next item"),callback:C,preventInClass:["sg-mail-part"]})),e.push(d.createHotkey({key:"down",description:l("View previous item"),callback:D,preventInClass:["sg-mail-part"]})),e.push(d.createHotkey({key:"shift+up",description:l("Add next item to selection"),callback:A,preventInClass:["sg-mail-part"]})),e.push(d.createHotkey({key:"shift+down",description:l("Add previous item to selection"),callback:F,preventInClass:["sg-mail-part"]})),e.push(d.createHotkey({key:"backspace",description:l("Delete selected message or folder"),callback:U})),_.forEach(e,function(e){d.registerHotkey(e)})}(B),angular.element(e).on("beforeunload",b),t.$on("$destroy",function(){angular.element(e).off("beforeunload",b),_.forEach(B,function(e){d.deregisterHotkey(e)})}),t.$watch(function(){return H.selectedFolder.unseenCount},function(t){var n=z+" - ";t&&(n+="("+t+") "),n+=H.selectedFolder.$displayName,e.document.title=n})}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","Account","Mailbox"],angular.module("material.components.virtualRepeat").decorator("mdVirtualRepeatContainerDirective",t),t.$inject=["$delegate"],angular.module("SOGo.MailerUI").controller("MailboxController",e)}(),function(){"use strict";function e(e,t,n,o,a,s,i,r,c,u,d,f,h,g,$,p,m,b,v,M){function y(e){J.showingAdvancedSearch=!0,J.search.mailbox=e,i(c["gt-md"])||r("left").close()}function x(){J.showingAdvancedSearch=!1,J.service.$virtualMode=!1,z=J.accounts[0],B=J.searchPreviousMailbox,t.go("mail.account.mailbox",{accountId:z.id,mailboxId:d(B.path)})}function w(){if(p.selectedFolder.$isLoading)J.virtualMailbox.stopSearch();else{var e,n=[],o=function(e){_.forEach(e,function(e){n.push(e),e.children&&e.children.length>0&&o(e.children)})};J.virtualMailbox=new m(J.accounts[0]),p.$virtualMode||(J.searchPreviousMailbox=p.selectedFolder),p.selectedFolder=J.virtualMailbox,p.$virtualMode=!0,angular.isDefined(J.search.mailbox)?(e=J.accounts[0].$getMailboxByPath(J.search.mailbox),n.push(e),J.search.subfolders&&e.children.length&&o(e.children)):n=J.accounts[0].$flattenMailboxes(),J.virtualMailbox.setMailboxes(n),J.virtualMailbox.startSearch(J.search.match,J.search.params),t.go("mail.account.virtualMailbox",{accountId:J.accounts[0].id})}}function S(e){return J.currentSearchParam=e,u("advancedSearch"),!1}function C(e){if(e.length&&J.currentSearchParam.length){var t=0,n=J.currentSearchParam;return e.startsWith("!")&&(t=1,e=e.substring(1).trim()),J.currentSearchParam="",{searchBy:n,searchInput:e,negative:t}}}function D(e){e.$expanded=!e.$expanded,e.$flattenMailboxes({reload:!0,saveState:!0}),n(function(){angular.element(o).triggerHandler("resize")},150)}function A(e){function t(e,t,n){function o(){t.cancel()}var a=this;a.loading=!0,a.filter={name:""},a.account=new $({id:n.id,name:n.name}),a.close=o,a.account.$getMailboxes({reload:!0,all:!0}).then(function(){a.loading=!1})}a.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 F(e){f.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){f.alert(l('An error occured while creating the mailbox "%{0}".',t),l(e.error))})})}function I(e){function t(e,t,n,o){function a(e){return n.$filter(e,o.delegates)}function s(){t.hide()}function i(e){o.$removeDelegate(e.uid).catch(function(e,t){f.alert(l("Warning"),l("An error occured please try again."))})}function r(e){e&&o.$addDelegate(e).then(function(){c.userToAdd="",c.searchText=""},function(e){f.alert(l("Warning"),e)})}var c=this;c.users=o.delegates,c.account=o,c.userToAdd="",c.searchText="",c.userFilter=a,c.closeModal=s,c.removeUser=i,c.addUser=r}a.show({templateUrl:e.id+"/delegation",controller:t,controllerAs:"delegate",clickOutsideToClose:!0,escapeToClose:!0,locals:{User:b,account:e}}),t.$inject=["$scope","$mdDialog","User","account"]}function E(e){J.editMode=e.path,u("mailboxName_"+e.path)}function k(e){e.$reset(),J.editMode=!1}function O(e,n,o){J.editMode!=o.path&&(J.editMode=!1,J.showingAdvancedSearch=!1,J.service.$virtualMode=!1,i(c["gt-md"])||r("left").close(),t.go("mail.account.mailbox",{accountId:n.id,mailboxId:d(o.path)}),e.stopPropagation(),e.preventDefault())}function U(e){e.$rename().then(function(e){J.editMode=!1})}function T(e){e.$compact().then(function(){s.show(s.simple().content(l("Folder compacted")).position("top right").hideDelay(3e3))})}function P(e){e.$emptyTrash().then(function(){s.show(s.simple().content(l("Trash emptied")).position("top right").hideDelay(3e3))})}function L(e){f.confirm(l("Warning"),l("Do you really want to move this folder into the trash ?"),{ok:l("Delete")}).then(function(){e.$delete().then(function(){t.go("mail.account.inbox")},function(n){f.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(){e.$delete({withoutTrash:!0}).then(function(){t.go("mail.account.inbox")},function(t){f.alert(l('An error occured while deleting the mailbox "%{0}".',e.name),l(t.error))})})})})}function R(e){e.$markAsRead()}function N(e){e.$acl.$users().then(function(){a.show({templateUrl:e.id+"/UIxAclEditor",controller:"AclController",controllerAs:"acl",clickOutsideToClose:!0,escapeToClose:!0,locals:{usersWithACL:e.$acl.users,User:b,folder:e}})})}function j(e,t){e.$setFolderAs(t).then(function(){e.$account.$getMailboxes({reload:!0})})}function q(){var e=o.unseenCountFolders;_.forEach(J.accounts,function(t){_.includes(e,t.id+"/folderINBOX")||e.push(t.id+"/folderINBOX"),_.forEach(t.$$flattenMailboxes,function(t){angular.isDefined(t.unseenCount)&&!_.includes(e,t.id)&&e.push(t.id)})}),$.$$resource.post("","unseenCount",{mailboxes:e}).then(function(e){_.forEach(J.accounts,function(t){_.forEach(t.$$flattenMailboxes,function(t){e[t.id]&&(t.unseenCount=e[t.id])})})}),v.ready().then(function(){var e=v.defaults.SOGoRefreshViewCheck;e&&"manually"!=e&&n(J.refreshUnseenCount,1e3*e.timeInterval())})}function G(e,t){return t.id!=e.id&&!t.isNoSelect()}function H(e,n,o){var a,i,r,c,u,d;a="/"+n.id,0===(i=e.$selectedMessages()).length&&(i=[e.$selectedMessage()]),r=_.map(i,"uid"),c=e.selectedMessage&&r.indexOf(e.selectedMessage)>=0,"copy"==o?(u=e.$copyMessages(i,a),d=l("%{0} message(s) copied",i.length)):(u=e.$moveMessages(i,a),d=l("%{0} message(s) moved",i.length)),u.then(function(){c&&t.go("mail.account.mailbox"),s.show(s.simple().content(d).position("top right").hideDelay(2e3))})}var z,B,J=this,V=[];J.service=p,J.accounts=M,J.toggleAccountState=D,J.subscribe=A,J.newFolder=F,J.delegate=I,J.editFolder=E,J.revertEditing=k,J.selectFolder=O,J.saveFolder=U,J.compactFolder=T,J.emptyTrashFolder=P,J.confirmDelete=L,J.markFolderRead=R,J.share=N,J.setFolderAs=j,J.refreshUnseenCount=q,J.isDroppableFolder=G,J.dragSelectedMessages=H,J.showingAdvancedSearch=!1,J.currentSearchParam="",J.addSearchParam=S,J.newSearchParam=C,J.showAdvancedSearch=y,J.hideAdvancedSearch=x,J.toggleAdvancedSearch=w,J.search={options:{"":"",subject:l("Enter Subject"),from:l("Enter From"),to:l("Enter To"),cc:l("Enter Cc"),body:l("Enter Body")},mailbox:"INBOX",subfolders:1,match:"AND",params:[]},v.ready().then(function(){J.showSubscribedOnly=v.defaults.SOGoMailShowSubscribedFoldersOnly}),J.refreshUnseenCount(),function(e){e.push(g.createHotkey({key:"backspace",description:l("Delete selected message or folder"),callback:function(){p.selectedFolder&&!p.selectedFolder.hasSelectedMessage()&&L(p.selectedFolder)}})),_.forEach(e,function(e){g.registerHotkey(e)})}(V),e.$on("$destroy",function(){_.forEach(V,function(e){g.deregisterHotkey(e)})})}e.$inject=["$scope","$state","$timeout","$window","$mdDialog","$mdToast","$mdMedia","$mdSidenav","sgConstant","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,o,a,s,i,r,c,u,d,f,h,g,$,p,m,b,v,M){function y(){return t.mailbox?(arguments.length>0&&(t.mailbox.messageDialog=arguments[0]),t.mailbox.messageDialog):null}function x(e){return function(){if(null===y())return e.apply(G,arguments)}}function w(){var t,n,o={};return e.opener&&e.opener.$mailboxController&&e.opener.$mailboxController.selectedFolder.$id()==c.$id()&&(n=e.opener.$mailboxController,o.mailboxCtrl=n,e.opener.$messageController&&e.opener.$messageController.message.uid==u.uid&&(t=e.opener.$messageController,o.messageCtrl=t)),o}function S(e){G.$showDetailedRecipients=!G.$showDetailedRecipients,e.stopPropagation(),e.preventDefault()}function C(e){var t,n,o,a;"A"==e.target.tagName&&"href"in e.target.attributes&&(t=e.target.attributes.href.value,(n=/^mailto:([^\?]+)/.exec(t))&&(o=_.map(decodeURIComponent(n[1]).split(","),function(e){return"<"+e+">"}),a={to:o},_.forEach(["subject","body"],function(e){var o=new RegExp(e+"=([^&]+)");e="body"==e?"text":e,(n=o.exec(t))&&(a[e]=[decodeURIComponent(n[1])])}),_.forEach(["cc","bcc"],function(e){var o=new RegExp(e+"=([^&]+)");(n=o.exec(t))&&(a[e]=[decodeURIComponent(n[1])])}),P(e,a)))}function D(){var e,t,a,i,r,l=w();l.messageCtrl?(e=l.mailboxCtrl.selectedFolder,t=l.messageCtrl.message,a=l.messageCtrl.$state):(e=c,t=u,a=n),e.$deleteMessages([t]).then(function(n){var l=n;if(t=null,angular.isDefined(a)){n>0&&(l-=1,i=e.$messages[l]),n<e.$messages.length&&(r=e.$messages[n]),i?i.isread&&r&&!r.isread&&(l=n,i=r):r&&(l=n,i=r);try{i&&o(s["gt-md"])?(a.go("mail.account.mailbox.message",{messageId:i.uid}),l<e.$topIndex?e.$topIndex=l:l>e.$lastVisibleIndex&&(e.$topIndex=l-(e.$lastVisibleIndex-e.$topIndex))):a.go("mail.account.mailbox").then(function(){t=null,delete e.selectedMessage})}catch(e){}}T()})}function A(e,t){null===y()&&y(a.show({parent:angular.element(document.body),targetEvent:e,clickOutsideToClose:!1,escapeToClose:!1,templateUrl:"UIxMailEditor",controller:"MessageEditorController",controllerAs:"editor",locals:{stateAccount:G.account,stateMessage:t}}).finally(function(){y(null),T()}))}function F(){n.go("mail.account.mailbox").then(function(){G.message=null,delete c.selectedMessage})}function I(e){A(e,G.message.$reply())}function E(e){A(e,G.message.$replyAll())}function k(e){A(e,G.message.$forward())}function O(e){G.message.$editableContent().then(function(){A(e,G.message)})}function U(){var t=[h.baseURL(),"UIxMailPopupView#!/Mail",G.message.accountId,f(f(G.message.$mailbox.path)),G.message.uid].join("/"),n=G.message.$absolutePath();H=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(","))}function T(){e.opener&&e.close()}function P(e,t){G.account.$newMessage().then(function(n){angular.extend(n.editable,t),A(e,n)}),e.stopPropagation(),e.preventDefault()}function L(e){G.showRawSource||G.message.$rawSource?G.showRawSource=!G.showRawSource:M.$$resource.post(G.message.id,"viewsource").then(function(e){G.message.$rawSource=e,G.showRawSource=!0})}function R(t){e.print()}function N(e){return q(e,"appointment")}function j(e){return q(e,"task")}function q(e,t){G.message.$plainContent().then(function(n){var o={pid:p.$defaultCalendar(),type:t,summary:n.subject,comment:n.content},s=new m(o),i=[h.activeUser("folderURL"),"Calendar","UIx"+t.capitalize()+"EditorTemplate"].join("/");return a.show({parent:angular.element(document.body),targetEvent:e,clickOutsideToClose:!0,escapeToClose:!0,templateUrl:i,controller:"ComponentEditorController",controllerAs:"editor",locals:{stateComponent:s}})})}var G=this,H=null,z=[];e.$messageController=G,G.$state=n,G.accounts=i,G.account=r,G.mailbox=c,G.message=u,G.service=M,G.tags={searchText:"",selected:""},G.showFlags=u.flags&&u.flags.length>0,G.$showDetailedRecipients=!1,G.toggleDetailedRecipients=S,G.filterMailtoLinks=C,G.deleteMessage=D,G.close=F,G.reply=I,G.replyAll=E,G.forward=k,G.edit=O,G.openPopup=U,G.closePopup=T,G.newMessage=P,G.toggleRawSource=L,G.showRawSource=!1,G.print=R,G.convertToEvent=N,G.convertToTask=j,function(e){e.push(d.createHotkey({key:l("hotkey_reply"),description:l("Reply to the message"),callback:x(I)})),e.push(d.createHotkey({key:l("hotkey_replyall"),description:l("Reply to sender and all recipients"),callback:x(E)})),e.push(d.createHotkey({key:l("hotkey_forward"),description:l("Forward selected message"),callback:x(k)})),e.push(d.createHotkey({key:l("hotkey_flag"),description:l("Flagged"),callback:x(angular.bind(u,u.toggleFlag))})),e.push(d.createHotkey({key:"backspace",callback:x(function(e){0===G.mailbox.$selectedCount()&&D(),e.preventDefault()})})),_.forEach(e,function(e){d.registerHotkey(e)})}(z),e.opener?(t.$watchCollection(function(){return G.message.flags},function(e,t){var n;(e||t)&&(n=w()).messageCtrl&&n.messageCtrl.service.$timeout(function(){n.messageCtrl.showFlags=!0,n.messageCtrl.message.flags=e})}),t.$watch(function(){return G.message.isflagged},function(e,t){var n=w();n.mailboxCtrl&&n.mailboxCtrl.service.$timeout(function(){_.find(n.mailboxCtrl.selectedFolder.$messages,{uid:G.message.uid}).isflagged=e})})):t.$watchCollection(function(){return G.message.flags},function(e,t){var n,o,a;(e||t)&&(n=e||[],o=t||[],_.forEach(n,function(e,t){angular.isObject(e)&&(n[t]=e.name)}),n.length>o.length?(a=_.difference(n,o),_.forEach(a,function(e){G.message.addTag(e)})):n.length<o.length&&(a=_.difference(o,n),_.forEach(a,function(e){G.message.removeTag(e)})))}),t.$on("$destroy",function(){_.forEach(z,function(e){d.deregisterHotkey(e)})})}e.$inject=["$window","$scope","$state","$mdMedia","$mdDialog","sgConstant","stateAccounts","stateAccount","stateMailbox","stateMessage","sgHotkeys","encodeUriFilter","sgSettings","sgFocus","Dialog","Calendar","Component","Account","Mailbox","Message"],angular.module("SOGo.MailerUI").controller("MessageController",e)}(),function(){"use strict";function e(e,t,n,o,a,s,i,r,c,u,d,f,h,g,$){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 m(){var e,t,n,o=D.message.editable.attachmentAttrs;if(o)for(e=0;e<o.length;e++)t={name:o[e].filename,type:o[e].mimetype,size:parseInt(o[e].size)},(n=new i.FileItem(D.uploader,t)).progress=100,n.isUploaded=!0,n.isSuccess=!0,n.inlineUrl=o[e].url,D.uploader.queue.push(n)}function b(e,n){e.isUploading?D.uploader.cancelItem(e):(D.message.$deleteAttachment(e.file.name),e.remove());var o=t.document.getElementById(n);o&&angular.element(o).prop("value",null)}function v(){D.autosave&&d.cancel(D.autosave),D.message.isNew&&D.message.attachmentAttrs&&D.message.$mailbox.$deleteMessages([D.message]),a.cancel()}function M(){var e=p();D.message.$save().then(function(t){D.message.$rawSource=null,e.draftMailboxCtrl&&e.draftMailboxCtrl.selectedFolder.$filter().then(function(){e.draftMessageCtrl&&e.draftMessageCtrl.$state.go("mail.account.mailbox.message",{messageId:D.message.uid})}),s.show(s.simple().content(l("Your email has been saved")).position("top right").hideDelay(3e3))})}function y(){var e=p();D.sendState="sending",D.autosave&&d.cancel(D.autosave),D.message.$send().then(function(t){D.sendState="sent",e.draftMailboxCtrl&&e.draftMailboxCtrl.selectedFolder.$filter().then(function(){e.draftMessageCtrl&&e.draftMessageCtrl.close()}),e.originMailboxCtrl&&e.originMailboxCtrl.selectedFolder.$filter(),s.show(s.simple().content(l("Your email has been sent")).position("top right").hideDelay(3e3)),d(a.hide,1e3)},function(e){D.sendState="error",D.errorMessage=e.data?e.data.message:e.statusText})}function x(){D.isFullscreen=!D.isFullscreen}function w(e){return h.$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,o,a;return n=D.message.editable[t],angular.isString(e)?(_.forEach(e.split(/[,;]/),function(e){n.push(e)}),null):(e.$isList({expandable:!0})?angular.isDefined(e.refs)&&e.refs.length?_.forEach(e.refs,function(e){e.email.length&&n.push(e.$shortFormat())}):(a=g.$find(e.container,e.c_name)).$id().then(function(e){_.forEach(a.refs,function(e){e.email.length&&n.push(e.$shortFormat())})}):o=e.$shortFormat(),o||null)}function C(){D.message.$save(),$.defaults.SOGoMailAutoSave&&(D.autosave=d(D.autosaveDrafts,1e3*$.defaults.SOGoMailAutoSave*60))}var D=this;D.addRecipient=S,D.autocomplete={to:{},cc:{},bcc:{}},D.autosave=null,D.autosaveDrafts=C,D.cancel=v,D.contactFilter=w,D.isFullscreen=!1,D.hideBcc=0===c.editable.bcc.length,D.hideCc=0===c.editable.cc.length,D.identities=_.map(r.identities,"full"),D.message=c,D.recipientSeparatorKeys=[o.KEY_CODE.ENTER,o.KEY_CODE.TAB,o.KEY_CODE.COMMA,o.KEY_CODE.SEMICOLON],D.removeAttachment=b,D.save=M,D.send=y,D.sendState=!1,D.toggleFullscreen=x,D.uploader=new i({url:c.$absolutePath({asDraft:!0,withResourcePath:!0})+"/save",autoUpload:!0,alias:"attachments",removeAfterUpload:!1,onSuccessItem:function(e,t,n,o){c.$setUID(t.uid),c.$reload({asDraft:!1}),e.inlineUrl=t.lastAttachmentAttrs[0].url},onCancelItem:function(e,t,n,o){c.$deleteAttachment(e.file.name),this.removeFromQueue(e)},onErrorItem:function(e,t,n,o){s.show(s.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)}}),e.$on("$destroy",function(){D.uploader.destroy()}),"reply"==n.actionName?c.$reply().then(function(e){D.message=e,D.hideCc=!e.editable.cc||0===e.editable.cc.length,D.hideBcc=!e.editable.bcc||0===e.editable.bcc.length}):"replyall"==n.actionName?c.$replyAll().then(function(e){D.message=e,D.hideCc=!e.editable.cc||0===e.editable.cc.length,D.hideBcc=!e.editable.bcc||0===e.editable.bcc.length}):"forward"==n.actionName?c.$forward().then(function(e){D.message=e,m()}):angular.isDefined(c)&&(D.message=c,m()),$.ready().then(function(){$.defaults.SOGoMailAutoSave&&(D.autosave=d(D.autosaveDrafts,1e3*$.defaults.SOGoMailAutoSave*60)),D.localeCode=$.defaults.LocaleCode})}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(){"use strict";function e(){function e(e,t,n,o){o.pathToAttachment=n.sgImipPath}return{restrict:"A",link:e,controller:"sgImipController"}}function t(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 o;"delegate"==t&&(o={receiveUpdates:!1,delegatedTo:e.delegatedTo.c_email}),e.viewer.message.$imipAction(n.pathToAttachment,t,o)}}t.$inject=["$scope","User"],angular.module("SOGo.MailerUI").controller("sgImipController",t).directive("sgImip",e)}(),function(){"use strict";function e(){function e(e,t,n,o){var a,s=t.parent();a=function(e){"IMG"==e.target.tagName&&s.toggleClass("sg-zoom")},t.on("click",a)}return{restrict:"A",link:e}}angular.module("SOGo.MailerUI").directive("sgZoomableImage",e)}();
//# sourceMappingURL=Mailer.services.js.map