window.rcmail&&rcmail.addEventListener("init",function(a){"settings"==rcmail.env.task?(rcmail.gui_objects.keyslist&&(rcmail.keys_list=new rcube_list_widget(rcmail.gui_objects.keyslist,{multiselect:!0,draggable:!1,keyboard:!1}),rcmail.keys_list.addEventListener("select",function(a){rcmail.enigma_keylist_select(a)}).addEventListener("keypress",function(a){rcmail.enigma_keylist_keypress(a)}).init().focus(),rcmail.enigma_list(),rcmail.register_command("firstpage",function(a){return rcmail.enigma_list_page("first")}), rcmail.register_command("previouspage",function(a){return rcmail.enigma_list_page("previous")}),rcmail.register_command("nextpage",function(a){return rcmail.enigma_list_page("next")}),rcmail.register_command("lastpage",function(a){return rcmail.enigma_list_page("last")})),"plugin.enigmakeys"==rcmail.env.action&&(rcmail.register_command("search",function(a){return rcmail.enigma_search(a)},!0),rcmail.register_command("reset-search",function(a){return rcmail.enigma_search_reset(a)},!0),rcmail.register_command("plugin.enigma-import", function(){rcmail.enigma_import()},!0),rcmail.register_command("plugin.enigma-import-search",function(){rcmail.enigma_import_search()},!0),rcmail.register_command("plugin.enigma-key-export",function(){rcmail.enigma_export()}),rcmail.register_command("plugin.enigma-key-export-selected",function(){rcmail.enigma_export(!0)}),rcmail.register_command("plugin.enigma-key-import",function(){rcmail.enigma_key_import()},!0),rcmail.register_command("plugin.enigma-key-delete",function(a){return rcmail.enigma_delete()}), rcmail.register_command("plugin.enigma-key-create",function(a){return rcmail.enigma_key_create()},!0),rcmail.register_command("plugin.enigma-key-save",function(a){return rcmail.enigma_key_create_save()},!0),rcmail.addEventListener("responseafterplugin.enigmakeys",function(){rcmail.enable_command("plugin.enigma-key-export",0 a:first").prop("tabindex"))),$.each(["encrypt","sign"],function(){rcmail.env["enigma_force_"+this]&&$('[name="_enigma_'+this+'"]').prop("checked", !0)}),rcmail.env.enigma_password_request&&rcmail.enigma_password_request(rcmail.env.enigma_password_request))});rcube_webmail.prototype.enigma_key_import=function(){this.enigma_loadframe("&_action=plugin.enigmakeys&_a=import")};rcube_webmail.prototype.enigma_key_create=function(){this.enigma_loadframe("&_action=plugin.enigmakeys&_a=create")}; rcube_webmail.prototype.enigma_key_create_save=function(){var a=[],b=$("#key-pass").val();var c=$("#key-pass-confirm").val();var d=$("#key-size").val();$('[name="identity[]"]:checked').each(function(){a.push({name:$(this).data("name")||"",email:$(this).data("email")})});if(!b||!c)return alert(this.get_label("enigma.formerror"));if(b!=c)return alert(this.get_label("enigma.passwordsdiffer"));if(!a.length)return alert(this.get_label("enigma.noidentselected"));if(window.openpgp&&(window.msCrypto||window.crypto&& (window.crypto.getRandomValues||window.crypto.subtle))){var e=this.set_busy(!0,"enigma.keygenerating");c={numBits:d,userIds:a,passphrase:b};openpgp.generateKey(c).then(function(a){rcmail.http_post("plugin.enigmakeys",{_a:"import",_keys:a.privateKeyArmored,_generated:1,_passwd:b,_keyid:a.key.primaryKey.fingerprint},e)},function(a){console.error(a);rcmail.set_busy(!1,null,e);rcmail.display_message(rcmail.get_label("enigma.keygenerateerror"),"error")})}else rcmail.display_message(rcmail.get_label("enigma.keygennosupport"), "error")};rcube_webmail.prototype.enigma_key_create_success=function(){parent.rcmail.enigma_list(1)};rcube_webmail.prototype.enigma_delete=function(){var a=this.keys_list.get_selection();if(a.length&&confirm(this.get_label("enigma.keyremoveconfirm"))){var b=this.display_message(this.get_label("enigma.keyremoving"),"loading");this.http_post("plugin.enigmakeys",{_a:"delete",_keys:a},b)}}; rcube_webmail.prototype.enigma_export=function(a){var b=!1,c=this.keys_list;a=a?c.get_selection().join(","):"*";var d={_keys:a};if(a.length){"*"==a?b=!0:$.each(c.get_selection(),function(){if((flags=$(c.rows[this].obj).data("flags"))&&0<=flags.indexOf("p"))return b=!0,!1});if(b)return this.show_popup_dialog(this.get_label("enigma.keyexportprompt"),this.get_label("enigma.exportkeys"),[{text:this.get_label("enigma.onlypubkeys"),click:function(a){rcmail.enigma_export_submit(d);$(this).remove()}},{text:this.get_label("enigma.withprivkeys"), click:function(a){d._priv=1;rcmail.enigma_export_submit(d);$(this).remove()}}],{width:400});this.enigma_export_submit(d)}}; rcube_webmail.prototype.enigma_export_submit=function(a){var b="keyexport-"+(new Date).getTime(),c=$("
").attr({target:b,method:"post",style:"display:none",action:"?_action=plugin.enigmakeys&_task=settings&_a=export"});b=$("