var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.defineProperty="function"==typeof Object.defineProperties?Object.defineProperty:function(a,c,e){if(e.get||e.set)throw new TypeError("ES3 does not support getters and setters.");a!=Array.prototype&&a!=Object.prototype&&(a[c]=e.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_";
$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.symbolCounter_=0;$jscomp.Symbol=function(a){return $jscomp.SYMBOL_PREFIX+(a||"")+$jscomp.symbolCounter_++};
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var a=$jscomp.global.Symbol.iterator;a||(a=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[a]&&$jscomp.defineProperty(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(a){var c=0;return $jscomp.iteratorPrototype(function(){return c<a.length?{done:!1,value:a[c++]}:{done:!0}})};
$jscomp.iteratorPrototype=function(a){$jscomp.initSymbolIterator();a={next:a};a[$jscomp.global.Symbol.iterator]=function(){return this};return a};$jscomp.makeIterator=function(a){$jscomp.initSymbolIterator();var c=a[Symbol.iterator];return c?c.call(a):$jscomp.arrayIterator(a)};
$jscomp.checkStringArgs=function(a,c,e){if(null==a)throw new TypeError("The 'this' value for String.prototype."+e+" must not be null or undefined");if(c instanceof RegExp)throw new TypeError("First argument to String.prototype."+e+" must not be a regular expression");return a+""};
$jscomp.polyfill=function(a,c,e,h){if(c){e=$jscomp.global;a=a.split(".");for(h=0;h<a.length-1;h++){var g=a[h];g in e||(e[g]={});e=e[g]}a=a[a.length-1];h=e[a];c=c(h);c!=h&&null!=c&&$jscomp.defineProperty(e,a,{configurable:!0,writable:!0,value:c})}};
$jscomp.polyfill("String.prototype.endsWith",function(a){return a?a:function(a,e){var c=$jscomp.checkStringArgs(this,a,"endsWith");a+="";void 0===e&&(e=c.length);for(var g=Math.max(0,Math.min(e|0,c.length)),l=a.length;0<l&&0<g;)if(c[--g]!=a[--l])return!1;return 0>=l}},"es6-impl","es3");
$jscomp.polyfill("String.prototype.startsWith",function(a){return a?a:function(a,e){var c=$jscomp.checkStringArgs(this,a,"startsWith");a+="";for(var g=c.length,l=a.length,m=Math.max(0,Math.min(e|0,c.length)),k=0;k<l&&m<g;)if(c[m++]!=a[k++])return!1;return k>=l}},"es6-impl","es3");
var userManager=function(){function a(b){var a=void 0===b.message?"Unknown error":b.message,c=b.title;b=(void 0===b.buttons?[]:b.buttons).map(function(b){return"<div id="+b.id+' class="btn"> \n\t\t\t\t\t\t'+b.text+" \n\t\t\t\t\t</div>"});return'\n\t\t<div id="oidc-error-msgBox">\n\t\t\t<div class="oidc-msg-container" >\n\t\t\t\t<div class="title">\n\t\t\t\t\t<span>'+c+'</span>\n\t\t\t\t</div>\n\t\t\t\t<div class="body">\n\t\t\t\t\t<span>'+a+'</span>\n\t\t\t\t</div>\n\t\t\t\t<div class="button-container">\n\t\t\t\t\t'+
b.join("")+"\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t\t"}function c(b){document.body.innerHTML=DOMPurify.sanitize(a(b));b=$jscomp.makeIterator(void 0===b.buttons?[]:b.buttons);for(var f=b.next();!f.done;f=b.next())f=f.value,f.id&&document.getElementById(f.id).addEventListener("click",f.handler)}function e(){var b=window.location.toString();0<b.indexOf("#")&&(b=b.substring(0,b.indexOf("#")),window.history.replaceState({},document.title,b))}function h(b){q(b.error.hcode,{title:"Authorization failed",
message:b.error.message,handler:function(a){"retry"===a?g(b,!1):"signout"===a&&v()},buttons:[{text:"Retry",id:"btnRetry",handler:function(){g(b,!1)}},{text:"Signout",id:"btnSignout",handler:v}]})}function g(b,a){d.getUser().then(function(c){n(c)?!1===a?k(c):window.setTimeout(function(){k(c)},3E3):h(b)})}function l(){try{var a=JSON.parse(this.responseText)}catch(f){console.error("oidc unable to parse post token response",f)}if(a&&a.error)switch(console.error("oidc post token failed",a),a.error.hcode){case "MAPI_E_LOGON_FAILED":case "MAPI_E_UNCONFIGURED":case "MAPI_E_NETWORK_ERROR":5>=
++w?g(a,!0):h(a)}else p?window.location.href=window.location.origin+window.location.pathname:a&&!1===a.authenticated?q("AUTHENTICATION_FAILURE",{handler:function(){r()}}):w=0}function m(a,c){var b=new XMLHttpRequest;b.open(a,c,!0);b.setRequestHeader("Content-type","application/x-www-form-urlencoded");return b}function k(a){var b=m("POST","kopano.php?service=token");a="token="+a.access_token;p&&(a+="&new=true");b.addEventListener("load",l);b.send(a)}function t(a){var b=m("GET","kopano.php?service=logout");
b.addEventListener("load",a);b.send()}function q(a,f){if(window.Zarafa)switch(a){case "ACCESS_TOKEN_EXPIRED":case "AUTHENTICATION_FAILURE":var b="ACCESS_TOKEN_EXPIRED"===a?_("Access token expired"):_("Authorization failed");window.Zarafa.core.Util.showMessageBox({title:b,msg:_("Failed to renew session, re-authentication is required."),cls:Ext.MessageBox.ERROR_CLS,minWidth:250,fn:f.handler,buttons:Ext.MessageBox.OK});break;case "MAPI_E_LOGON_FAILED":case "MAPI_E_UNCONFIGURED":case "MAPI_E_NETWORK_ERROR":window.Zarafa.core.Util.showMessageBox({title:f.title,
msg:f.message,cls:Ext.MessageBox.ERROR_CLS,fn:f.handler,customButton:[{text:_("Retry"),name:"retry"},{text:_("Signout"),name:"signout"}],scope:this},!0);break;default:console.error("UnKnown action type:",a)}else f&&c(f)}function u(a){window.Zarafa&&Zarafa.core.Util.disableLeaveRequester();return d.signinRedirect(a)}function n(a){return a&&a.access_token&&!a.expired}function y(a){return a.signinSilent().then(function(a){n(a)&&(console.debug("oidc sign-in silent successfully."),k(a));return a})["catch"](function(a){console.debug("oidc silent sign-in failed",
a);return null})}function v(){t(function(){d.signoutRedirect()})}function r(){t(function(){u({prompt:"select_account"})})}function x(a){return a.getUser().then(function(a){a||t(function(){console.debug("webapp php session cleared.");Zarafa.core.Util.disableLeaveRequester();window.location="?oidclogin"});return a})}var p=!1,d,w=0,z=void 0!==window.nw;Oidc.Log.logger=console;Oidc.Log.level=Oidc.Log.WARN;return{init:function(a,f){p=f;var b=window.location.href;b.endsWith("/")||(b+="/");a.redirect_uri=
b+"#oidc-callback";a.post_logout_redirect_uri=b+"?logout";a.silent_redirect_uri=b+"?oidc-silent-refresh";a.accessTokenExpiringNotificationTime=120;z&&(a.userStore=new Oidc.WebStorageStateStore({store:window.localStorage}),a.scope+=" offline_access");d=new Oidc.UserManager(a);d.clearStaleState();d.events.addUserSignedOut(function(){console.debug("oidc user signed out at OP");d.removeUser();t(function(){console.debug("webapp php session cleared.");Zarafa.core.Util.disableLeaveRequester();window.location=
"?oidclogin"})});d.events.addAccessTokenExpiring(function(){console.debug("oidc token expiring")});var g=function(){console.warn("oidc access token expired");d.getUser().then(function(a){if(a)if(n(a))console.debug("oidc sign-in silent successfully."),k(a);else{var b=a.refresh_token;b||d.removeUser();y(d).then(function(a){a||(console.debug("oidc sign-in silent did not return a user"),b?setTimeout(function(a){x(a)},5E3,d):q("ACCESS_TOKEN_EXPIRED",{handler:function(){r()}}))})}})};d.events.addAccessTokenExpired(g);
d.events.addSilentRenewError(function(a){console.error("oidc silent renew error",a);if(a)switch(a.error){case "interaction_required":case "login_required":g();return}setTimeout(function(){console.debug("oidc retrying silent renew");d.getUser().then(function(a){console.debug("oidc retrying silent renew of user");if(n(a))console.debug("oidc start silent renew",a),d.startSilentRenew();else{var b=a.refresh_token;console.debug("oidc failed to renew in time so try once to silently renew user.");d.signinSilent()["catch"](function(a){console.debug("oidc silent sign-in failed",
a);return null}).then(function(a){null===a&&(console.debug("oidc sign-in silent did not return a user"),b?setTimeout(function(a){x(a)},5E3,d):q("ACCESS_TOKEN_EXPIRED",{handler:function(){r()}}))})}})},5E3)});d.events.addUserLoaded(function(a){console.debug("oidc user loaded",a);d.getUser().then(function(a){k(a)})});d.getUser().then(function(a){if(n(a))k(a);else if(p&&window.location.hash.startsWith("#oidc-callback")){var b=void 0;d.signinRedirectCallback()["catch"](function(a){console.error("oidc failed to complete authentication",
a);b=a;return null}).then(function(a){e();a||c({title:"Incomplete login",message:"Unable to complete the login. Please try again.\n\t\t\t\t\t\t<br/><br/>\n\t\t\t\t\t\tIf this problem persists, contact your system administrator with the following details:<br/>\n\t\t\t\t\t\tError: "+(b&&b.message||"Unable to complete login."),buttons:[{text:"Retry",id:"btnRetry",handler:function(){e();d.removeUser();u({prompt:"select_account"})}}]})})}else d.signinSilent()["catch"](function(a){console.error("oidc sign-in silent failed",
a);p&&(console.debug("oidc sign-in silent did not return a user"),u()["catch"](function(a){console.error("Unreachable kopano konnect service.",a);c({title:"Connection error",message:"Problem occurred while connecting to an authorization service.",buttons:[{text:"OK",id:"btnOk",handler:function(){u()}}]})}))})})},signOut:v,reauthenticateWithRedirect:r}}();
document.addEventListener("DOMContentLoaded",function(){var a=document.querySelector("meta[name='kopano:webapp-view']");if(a&&"interactive-signin"===a.content)a=[location.protocol,"//",location.host,location.pathname].join(""),window.history.replaceState({},document.title,a),document.getElementById("signin-btn").addEventListener("click",function(){window.location.reload()});else{var c=document.getElementById("oidc-settings");c&&(a=JSON.parse(c.getAttribute("content")),c=""===c.getAttribute("logon"),
userManager.init(a,c))}});
