text: "use strict";!function(){function e(){return $.getJSON("davemail.json",function(){console.log("davemail.json loaded confirmation one")}).done(function(){console.log("davemail.json loaded confirmation two")}).fail(function(e,a,n){var o=a+", "+n;console.log("davemail.json failed to load: "+o),s()})}function a(e){$.getJSON("davemail.json",function(){console.log("davemail.json loaded confirmation one")}).done(function(a){console.log("davemail.json loaded confirmation two"),_.isEqual(e.jsonData.responseJSON,a)?($("#signUpReplaceDownload").remove(),$("#signUpButton").show(),$("#signingUpLoader").hide(),$("#fileReplacedButton").show(),$("#fileReplacedLoader").hide(),$("#usernameHeading").text(e.username),t(),e.messages=v(e),u(e)):($("#fileNotReplacedWarning").show(),$("#fileReplacedLoader").hide(),$("#fileReplacedButton").show())}).fail(function(a,n,s){var o=n+", "+s;console.log("davemail.json failed to load: "+o),$("#signUpReplaceDownload").remove(),$("#signUpButton").show(),$("#signingUpLoader").hide(),$("#fileReplacedButton").show(),$("#fileReplacedLoader").hide(),$("#usernameHeading").text(e.username),t(),e.messages=v(e),u(e)})}function n(e){$("#composeToList li").remove();var a=_.map(e.jsonData.responseJSON.davemail.users,function(e,a){return $("<li>").text(a).click(function(n){$("#composeTo").val(a),$("#composeTo").removeClass("invalid"),$("#composePublicKey").val(e.publicKey),$("#composeToListWrapper").hide(),$("#composeSendButton").show()}).appendTo("#composeToList"),a}),n=$("#composeTo"),s=$("input#clearfilter");$("#composeToList").listfilter({filter:n,clearlink:s,alternate:!0,alternateclass:"other"}),$("#composeTo").keyup(function(){$("#composeTo").val().length>0?($("#composeToListWrapper").show(),0==$("#composeToList li:visible").length&&$("#composeToListWrapper").hide(),-1==_.indexOf(a,$("#composeTo").val())?($("#composePublicKey").val(""),$("#composeSendButton").hide()):($("#composePublicKey").val(e.jsonData.responseJSON.davemail.users[$("#composeTo").val()].publicKey),$("#composeSendButton").show())):$("#composeToListWrapper").hide()}).focusout(function(){setTimeout(function(){-1==_.indexOf(a,$("#composeTo").val())?$("#composeTo").addClass("invalid"):($("#composeTo").removeClass("invalid"),$("#composeToListWrapper").hide())},10)}),$("#composePublicKeyButton").click(function(){$(this).prop("checked")?$("#composeShowPublicKey").show():$("#composeShowPublicKey").hide()})}function s(e){_.isObject(e)&&e.preventDefault(),$("#importDavemail").show(),$("nav").hide(),$("#signIn").hide(),$("#signUp").hide(),$("#messages").hide(),$("#signUpReplace").hide(),$("#navSignInButton").parent().removeClass("active"),$("#navSignUpButton").parent().removeClass("active"),$("#navMessagesButton").parent().removeClass("active")}function o(e){_.isObject(e)&&e.preventDefault(),$("#signIn").show(),$("#signUp").hide(),$("#messages").hide(),$("#signUpReplace").hide(),$("#navSignInButton").parent().addClass("active"),$("#navSignUpButton").parent().removeClass("active"),$("#navMessagesButton").parent().removeClass("active")}function i(e){_.isObject(e)&&e.preventDefault(),$("#signUp").show(),$("#signIn").hide(),$("#messages").hide(),$("#navSignUpButton").parent().addClass("active"),$("#navSignInButton").parent().removeClass("active"),$("#navMessagesButton").parent().removeClass("active")}function t(e){_.isObject(e)&&e.preventDefault(),$("#messages").show(),$("#compose").hide(),$("#signIn").hide(),$("#signUp").hide(),$("#signUpReplace").hide(),$("#navMessagesButton").show(),$("#navMessagesButton").parent().addClass("active"),$("#navComposeButton").show(),$("#navComposeButton").parent().removeClass("active"),$("#navSignInButton").parent().removeClass("active"),$("#navSignUpButton").parent().removeClass("active"),$("#navSignOutButton").show(),$("#navSignInButton").hide(),$("#navSignUpButton").hide(),$(".jumbotron").hide()}function l(e){_.isObject(e)&&e.preventDefault(),$("#messages").hide(),$("#compose").show(),$("#signIn").hide(),$("#signUp").hide(),$("#signUpReplace").hide(),$("#navMessagesButton").show(),$("#navMessagesButton").parent().removeClass("active"),$("#navComposeButton").show(),$("#navComposeButton").parent().addClass("active"),$("#navSignInButton").parent().removeClass("active"),$("#navSignUpButton").parent().removeClass("active"),$("#navSignOutButton").show(),$("#navSignInButton").hide(),$("#navSignUpButton").hide(),$(".jumbotron").hide()}function r(e){_.isObject(e)&&e.preventDefault(),$("#signIn").show(),$("#signInButton").show(),$("#messages").hide(),$("#compose").hide(),$("#signUp").hide(),$("#signUpReplace").hide(),$("#navComposeButton").hide(),$("#navMessagesButton").hide(),$("#navSignInButton").parent().addClass("active"),$("#navComposeButton").parent().removeClass("active"),$("#navMessagesButton").parent().removeClass("active"),$("#navSignUpButton").parent().removeClass("active"),$("#navSignInButton").show(),$("#navSignUpButton").show(),$("#navSignOutButton").hide(),$("#composeTo").val(""),$("#composeTo").removeClass("invalid"),$("#composePublicKey").val(""),$("#composeShowPublicKey").hide(),$("#composePublicKeyButton").attr("checked",!1),$(".jumbotron").show()}function d(e){return e.messagesTable.destroy(),e.messagesTable=$("#messagesTable").DataTable({data:[],ordering:!1,columns:[{title:"Message"},{title:"Time"}]}),e.username=void 0,e.password=void 0,e.passwordStrength=void 0,e.publicKey=void 0,e.privateKey=void 0,e.messages=void 0,e}function c(e){var a=e,n=g.encode_utf8(a),s=g.encode_utf8("davemail"),o=g.crypto_scrypt(n,s,Math.pow(2,14),8,1,64);return a=g.to_hex(o),console.log(a),a}function p(e){return e.privateKey=cryptico.generateRSAKey(c(e.password),1536),e.publicKey=cryptico.publicKeyString(e.privateKey),console.log(e.privateKey),console.log(e.publicKey),e}function m(e,a,n){var s=c(a),o=cryptico.encrypt(e.concat(s),n);return o}function v(e){return e.decryptedMessages=new Array,_.map(e.jsonData.responseJSON.davemail.emails,function(a,n){var s=cryptico.decrypt(a.cipher,e.privateKey);if("success"==s.status){var o=moment(a.time).format("MMM Do YY"),i=s.plaintext.substring(0,s.plaintext.length-128);return e.decryptedMessages.push([i,o]),[i,o]}})}function u(e){_.isUndefined(e.decryptedMessages[0])||(e.messagesTable.destroy(),e.messagesTable=$("#messagesTable").DataTable({data:e.decryptedMessages,ordering:!1,columns:[{title:"Message"},{title:"Time"}]}))}window.davemail=new Object,davemail.info="Davemail 2.0.0 by David Apple https://github.com/davidapple/davemail Donate Bitcoin to 13D3A8PP91MLF5VTBQMH5HG76F42RNRF28";var g=scrypt_module_factory();davemail.jsonData=e(),$(document).on("change","#importDavemailFile",function(e){var a=new FileReader;$("#importDavemailButton").hide(),$("#importingLoader").show(),a.onload=function(e){console.log("davemail.json loaded confirmation one");var a=JSON.parse(e.target.result);davemail.jsonData=new Object,davemail.jsonData.responseJSON=a,$("nav").show(),$("#signIn").show(),$("#importDavemail").hide()},a.readAsText(e.target.files[0])}),$("#navSignInButton").click(function(e){o(e)}),$("#navSignUpButton").click(function(e){i(e)}),$("#navMessagesButton").click(function(e){t(e)}),$("#navComposeButton").click(function(e){l(e)}),$("#navSignOutButton").click(function(e){r(e),davemail=d(davemail)}),$("#signUpButtonOnSignIn").click(function(e){i(e)}),davemail.messagesTable=$("#messagesTable").DataTable({data:[],ordering:!1,columns:[{title:"Message"},{title:"Time"}]}),$("#signInButton").click(function(){$("#signInButton").hide(),$("#signingInLoader").show(),davemail.password=$("#signInPassword").val(),davemail.passwordStrength=zxcvbn(davemail.password),davemail.passwordStrength.score<4?setTimeout(function(){$("#passwordWarningSignIn").show(),$("#signInButton").show(),$("#signingInLoader").hide()},100):setTimeout(function(){davemail=p(davemail),_.map(davemail.jsonData.responseJSON.davemail.users,function(e,a){davemail.publicKey==e.publicKey&&($("#usernameHeading").text(a),davemail.username=a)}),$("#signingInLoader").hide(),$("#signIn").hide(),$("#signInPassword").val(""),t(),davemail.messages=v(davemail),u(davemail),n(davemail)},10)}),$("#signUpButton").click(function(){if($("#signUpUsername").val($("#signUpUsername").val().toLowerCase()),davemail.username=$("#signUpUsername").val(),davemail.password=$("#signUpPassword").val(),davemail.passwordStrength=zxcvbn(davemail.password),$("#usernameTakenWarning").hide(),$("#passwordWarning").hide(),davemail.username.length>0){$("#usernameEmptyWarning").hide();var e=_.map(davemail.jsonData.responseJSON.davemail.users,function(e,a){return davemail.username==a.toLowerCase()});_.contains(e,!0)?($("#usernameTakenWarning").show(),$("#passwordWarning").hide(),e=!0):e=!1;var a=/^[a-z0-9]*$/.test(davemail.username);if(a?$("#usernameIllegalWarning").hide():$("#usernameIllegalWarning").show(),a&&!e&&davemail.passwordStrength.score>3)$("#passwordWarning").hide(),$("#signUpButton").hide(),$("#signingUpLoader").show(),setTimeout(function(){davemail=p(davemail);var e=davemail.jsonData.responseJSON.davemail.users,a=davemail.jsonData.responseJSON.davemail.emails,s=davemail.jsonData.responseJSON.davemail.servers;e[davemail.username]={publicKey:davemail.publicKey},davemail.jsonData.responseJSON={davemail:{users:e,emails:a,servers:s}},$("#signUpJson").text(JSON.stringify(davemail.jsonData.responseJSON,null,4));var o="text/json;charset=utf-8,"+encodeURIComponent(JSON.stringify(davemail.jsonData.responseJSON,null,4));$("#signUpUsername").val(""),$("#signUpPassword").val(""),$("#signUp").hide(),$("#signUpReplace").show(),$('<a id="signUpReplaceDownload" class="btn btn-primary tailor-paisley" href="data:'+o+'" download="davemail.json">Right click here</a>').appendTo("#signUpDownload"),n(davemail)},100);else{davemail.passwordStrength.score<4&&$("#passwordWarning").show(),$("#passwordWarningText").text(davemail.passwordStrength.feedback.warning);var s=$("#passwordSuggestionsText");s.children().remove(),$.each(davemail.passwordStrength.feedback.suggestions,function(e){var a=$("<p/>").appendTo(s).text(davemail.passwordStrength.feedback.suggestions[e]).appendTo(a)})}}else $("#usernameEmptyWarning").show()}),$("#composeSendButton").click(function(){if(davemail.jsonData.responseJSON.davemail.users[$("#composeTo").val()].publicKey==$("#composePublicKey").val()){$(this).hide(),$("#sendingLoader").show();var e=new Date,a=m($("#composeMessage").val(),e.toISOString(),$("#composePublicKey").val());console.log(a),"success"==a.status&&setTimeout(function(){$("#composeTo").val(""),$("#composePublicKey").val(""),$("#composeMessage").val(""),$("#sendingLoader").hide(),$("#compose").hide(),$("#signUpReplace").show();var n=davemail.jsonData.responseJSON.davemail.users,s=davemail.jsonData.responseJSON.davemail.emails,o=davemail.jsonData.responseJSON.davemail.servers;s.push({time:e.toISOString(),cipher:a.cipher}),davemail.jsonData.responseJSON={davemail:{users:n,emails:s,servers:o}},$("#signUpJson").text(JSON.stringify(davemail.jsonData.responseJSON,null,4));var i="text/json;charset=utf-8,"+encodeURIComponent(JSON.stringify(davemail.jsonData.responseJSON,null,4));$('<a id="signUpReplaceDownload" class="btn btn-primary tailor-paisley" href="data:'+i+'" download="davemail.json">Right click here</a>').appendTo("#signUpDownload")},100)}else console.log("fail")}),$("#fileReplacedButton").click(function(){$("#fileReplacedButton").hide(),$("#fileReplacedLoader").show(),setTimeout(function(){a(davemail)},500)})}();