sogo/UI/WebServerResources/js/Mailer.services.js
2017-03-08 01:57:09 -05:00

3 lines
54 KiB
JavaScript

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