51 lines
14 KiB
JavaScript
51 lines
14 KiB
JavaScript
/**
|
|
* Enigma plugin script
|
|
*
|
|
* @licstart The following is the entire license notice for the
|
|
* JavaScript code in this file.
|
|
*
|
|
* Copyright (c) The Roundcube Dev Team
|
|
*
|
|
* The JavaScript code in this page is free software: you can redistribute it
|
|
* and/or modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation, either version 3 of
|
|
* the License, or (at your option) any later version.
|
|
*
|
|
* @licend The above is the entire license notice
|
|
* for the JavaScript code in this file.
|
|
*/
|
|
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:!0}),rcmail.keys_list.addEventListener("select",function(b){rcmail.enigma_keylist_select(b)}).addEventListener("keypress",function(b){rcmail.list_keypress(b,{del:"plugin.enigma-key-delete"})}).init().focus(),rcmail.enigma_list(),rcmail.register_command("firstpage",function(b){return rcmail.enigma_list_page("first")}),
|
|
rcmail.register_command("previouspage",function(b){return rcmail.enigma_list_page("previous")}),rcmail.register_command("nextpage",function(b){return rcmail.enigma_list_page("next")}),rcmail.register_command("lastpage",function(b){return rcmail.enigma_list_page("last")})),"plugin.enigmakeys"==rcmail.env.action&&(rcmail.register_command("search",function(b){return rcmail.enigma_search(b)},!0),rcmail.register_command("reset-search",function(b){return rcmail.enigma_search_reset(b)},!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-import-search",function(){rcmail.enigma_key_import_search()},
|
|
!0),rcmail.register_command("plugin.enigma-key-delete",function(b){return rcmail.enigma_delete()}),rcmail.register_command("plugin.enigma-key-create",function(b){return rcmail.enigma_key_create()},!0),rcmail.register_command("plugin.enigma-key-save",function(b){return rcmail.enigma_key_create_save()},!0),rcmail.addEventListener("responseafterplugin.enigmakeys",function(){rcmail.enable_command("plugin.enigma-key-export",0<rcmail.env.rowcount);rcmail.triggerEvent("listupdate",{list:rcmail.keys_list,
|
|
rowcount:rcmail.env.rowcount})}),rcmail.gui_objects.importform&&$("#rcmimportsearch").keydown(function(b){if(13==b.which)return rcmail.enigma_import_search(),!1}))):"mail"==rcmail.env.task&&("compose"==rcmail.env.action&&(rcmail.addEventListener("beforesend",function(b){rcmail.enigma_beforesend_handler(b)}).addEventListener("beforesavedraft",function(b){rcmail.enigma_beforesavedraft_handler(b)}),$("#enigmamenu").find("input,label").mouseup(function(b){b.stopPropagation()}),$("a.button.enigma").prop("tabindex",
|
|
$("#messagetoolbar > a").first().prop("tabindex")),$.each(["encrypt","sign"],function(){var b=this,c=$("#enigma"+b+"opt");rcmail.env["enigma_force_"+b]&&c.prop("checked",!0);if(window.UI&&UI.compose_status)c.on("change",function(){UI.compose_status(b,this.checked)});c.trigger("change")})),rcmail.env.enigma_password_request&&rcmail.enigma_password_request(rcmail.env.enigma_password_request))});
|
|
rcube_webmail.prototype.enigma_key_import=function(){var a=$("<iframe>").attr("src",this.url("plugin.enigmakeys",{_a:"import",_framed:1}));this.enigma_import_dialog=this.simple_dialog(a,this.gettext("enigma.importkeys"),function(b){a[0].contentWindow.rcmail.enigma_import()},{button:"import",width:500,height:150})};
|
|
rcube_webmail.prototype.enigma_key_import_search=function(){var a=$("<iframe>").attr("src",this.url("plugin.enigmakeys",{_a:"import-search",_framed:1}));this.enigma_import_dialog=this.simple_dialog(a,this.gettext("enigma.keyimportsearchlabel"),function(){a[0].contentWindow.rcmail.enigma_import_search()},{button:"search",width:500,height:150})};rcube_webmail.prototype.enigma_import_success=function(){(this.enigma_import_dialog||parent.rcmail.enigma_import_dialog).dialog("destroy")};
|
|
rcube_webmail.prototype.enigma_key_create=function(){this.keys_list.clear_selection();this.enigma_loadframe("&_action=plugin.enigmakeys&_a=create&_nav=hide")};
|
|
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)if(b!=c)this.alert_dialog(this.get_label("enigma.passwordsdiffer"));else if(a.length)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(f){f={_a:"import",_keys:f.privateKeyArmored,_generated:1,_passwd:b,_keyid:f.key.primaryKey.getFingerprint()};rcmail.http_post("plugin.enigmakeys",f,e)},function(f){console.error(f);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");else this.alert_dialog(this.get_label("enigma.noidentselected"));
|
|
else this.alert_dialog(this.get_label("enigma.formerror"))};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();a.length&&this.confirm_dialog(this.get_label("enigma.keyremoveconfirm"),"delete",function(b,c){b=c.display_message(c.get_label("enigma.keyremoving"),"loading");c.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"),[{"class":"export mainaction",text:this.get_label("enigma.onlypubkeys"),click:function(e){rcmail.enigma_export_submit(d);
|
|
$(this).remove()}},{"class":"export",text:this.get_label("enigma.withprivkeys"),click:function(e){d._priv=1;rcmail.enigma_export_submit(d);$(this).remove()}},{"class":"cancel",text:this.get_label("close"),click:function(e){$(this).remove()}}],{width:500});this.enigma_export_submit(d)}};
|
|
rcube_webmail.prototype.enigma_export_submit=function(a){var b="keyexport-"+(new Date).getTime(),c=$("<form>").attr({target:b,method:"post",style:"display:none",action:"?_action=plugin.enigmakeys&_task=settings&_a=export"});b=$("<iframe>").attr({name:b,style:"display:none"});c.append($("<input>").attr({name:"_token",value:this.env.request_token}));$.each(a,function(d,e){c.append($("<input>").attr({name:d,value:e}))});b.appendTo(document.body);c.appendTo(document.body).submit()};
|
|
rcube_webmail.prototype.enigma_import=function(){var a,b,c="keyimport-"+(new Date).getTime();if(a=this.gui_objects.importform)if((b=document.getElementById("rcmimportfile"))&&!b.value)this.alert_dialog(this.get_label("selectimportfile"));else return b=this.set_busy(!0,"importwait"),$("<iframe>").attr({name:c,style:"display:none"}).appendTo(document.body),$(a).attr({target:c,action:this.add_url(a.action,"_unlock",b)}).submit(),!0};
|
|
rcube_webmail.prototype.enigma_import_search=function(){var a;this.gui_objects.importform&&(a=$("#rcmimportsearch").val())&&this.enigma_find_publickey(a)};rcube_webmail.prototype.enigma_keylist_select=function(a){var b=a.get_single_selection(),c;b&&!a.multi_selecting&&(c="&_action=plugin.enigmakeys&_a=info&_id="+b);this.enigma_loadframe(c);this.enable_command("plugin.enigma-key-delete","plugin.enigma-key-export-selected",0<a.get_selection().length)};
|
|
rcube_webmail.prototype.enigma_loadframe=function(a){var b;if(b=this.get_frame_window(this.env.contentframe))a?(this.env.frame_lock=this.set_busy(!0,"loading"),b.location.href=this.env.comm_path+"&_framed=1"+a):(b.location&&0>b.location.href.indexOf(this.env.blankpage)&&(b.location.href=this.env.blankpage),this.env.frame_lock&&this.set_busy(!1,null,this.env.frame_lock))};
|
|
rcube_webmail.prototype.enigma_search=function(a){!a&&this.gui_objects.qsearchbox&&(a=this.gui_objects.qsearchbox.value);if(a||this.env.search_request){a={_a:"search",_q:a};var b=this.set_busy(!0,"searching");this.env.current_page=1;this.enigma_loadframe();this.enigma_clear_list();this.http_post("plugin.enigmakeys",a,b)}return!1};
|
|
rcube_webmail.prototype.enigma_search_reset=function(a){a=this.env.search_request;this.reset_qsearch();a&&(this.enigma_loadframe(),this.enigma_clear_list(),this.enigma_list());return!1};
|
|
rcube_webmail.prototype.enigma_list=function(a,b){if(this.is_framed())return parent.rcmail.enigma_list(a,b);var c={_a:"list"},d=this.set_busy(!0,"loading");this.env.current_page=a?a:1;this.env.search_request&&(c._q=this.env.search_request);a&&(c._p=a);this.enigma_clear_list(b);this.http_post("plugin.enigmakeys",c,d)};
|
|
rcube_webmail.prototype.enigma_list_page=function(a){"next"==a?a=this.env.current_page+1:"last"==a?a=this.env.pagecount:"prev"==a&&1<this.env.current_page?a=this.env.current_page-1:"first"==a&&1<this.env.current_page&&(a=1);this.enigma_list(a)};
|
|
rcube_webmail.prototype.enigma_clear_list=function(a){!1!==a&&this.enigma_loadframe();this.keys_list&&this.keys_list.clear(!0);this.enable_command("plugin.enigma-key-delete","plugin.enigma-key-delete-selected",!1);this.triggerEvent("listupdate",{list:this.keys_list,rowcount:this.keys_list.rowcount})};
|
|
rcube_webmail.prototype.enigma_add_list_row=function(a){if(!this.gui_objects.keyslist||!this.keys_list)return!1;var b=this.keys_list,c=document.createElement("tr"),d=document.createElement("td");c.id="rcmrow"+a.id;c.className="message";a.flags&&$(c).data("flags",a.flags);d.className="name";d.innerHTML=a.name;c.appendChild(d);b.insert_row(c)};rcube_webmail.prototype.enigma_beforesend_handler=function(a){this.env.last_action="send";this.enigma_compose_handler(a)};
|
|
rcube_webmail.prototype.enigma_beforesavedraft_handler=function(a){this.env.last_action="savedraft";this.enigma_compose_handler(a)};rcube_webmail.prototype.enigma_compose_handler=function(a){var b=this.gui_objects.messageform;$("#enigmamenu input").each(function(){var c=this.id+"_cpy",d=$("#"+c);d.length||(d=$(this).clone(),d.prop({id:c,type:"hidden"}).appendTo(b));d.val(this.checked?"1":"")})};
|
|
rcube_webmail.prototype.enigma_import_attachment=function(a){var b=this.set_busy(!0,"loading");this.http_post("plugin.enigmaimport",{_uid:this.env.uid,_mbox:this.env.mailbox,_part:a},b);return!1};
|
|
rcube_webmail.prototype.enigma_password_request=function(a){if(a&&a.keyid){var b=this,c=this.get_label("enigma.enterkeypass"),d=$('<div class="prompt">'),e=$('<p class="message">').appendTo(d),f=$("<input>").attr({type:"password",size:30}).keypress(function(g){13==g.which&&(b.is_framed()?window.parent.$:$)(".ui-dialog-buttonpane button.mainaction:visible").click()}).appendTo(d);a.key=a.keyid;8<a.keyid.length&&(a.keyid=a.keyid.substr(a.keyid.length-8));$.each(["keyid","user"],function(){c=c.replace("$"+
|
|
this,a[this])});e.text(c);this.show_popup_dialog(d,this.get_label("enigma.enterkeypasstitle"),[{text:this.get_label("ok"),"class":"mainaction save unlock",click:function(g){g.stopPropagation();g=b.is_framed()?window.parent.$:$;a.password=f.val();a.password?(b.enigma_password_submit(a),g(this).remove()):f.focus()}},{text:this.get_label("cancel"),"class":"cancel",click:function(g){var h=b.is_framed()?window.parent.$:$;g.stopPropagation();h(this).remove()}}],{width:400});this.is_framed()&&parent.rcmail.message_list&&
|
|
parent.rcmail.message_list.blur()}};
|
|
rcube_webmail.prototype.enigma_password_submit=function(a){var b;if("compose"==this.env.action&&!a["compose-init"])return this.enigma_password_compose_submit(a);if("plugin.enigmakeys"==this.env.action&&(b=this.gui_objects.importform))return $('input[name="_keyid"]',b).length||$(b).append($("<input>").attr({type:"hidden",name:"_keyid",value:a.key})).append($("<input>").attr({type:"hidden",name:"_passwd",value:a.password})),this.enigma_import();var c=a.nolock?null:this.set_busy(!0,"loading");b=$("<form>").attr({method:"post",
|
|
action:a.action||location.href,style:"display:none"}).append($("<input>").attr({type:"hidden",name:"_keyid",value:a.key})).append($("<input>").attr({type:"hidden",name:"_passwd",value:a.password})).append($("<input>").attr({type:"hidden",name:"_token",value:this.env.request_token})).append($("<input>").attr({type:"hidden",name:"_unlock",value:c}));$.each(a,function(d,e){0==d.indexOf("input")&&b.append($("<input>").attr({type:"hidden",name:d.substring(5),value:e}))});a.iframe&&(a="enigma_frame_"+(new Date).getTime(),
|
|
$("<iframe>").attr({style:"display:none",name:a}).appendTo(document.body),b.attr("target",a));b.appendTo(document.body).submit()};
|
|
rcube_webmail.prototype.enigma_password_compose_submit=function(a){var b=this.gui_objects.messageform;$('input[name="_keyid"]',b).length?($('input[name="_keyid"]',b).val(a.key),$('input[name="_passwd"]',b).val(a.password)):$(b).append($("<input>").attr({type:"hidden",name:"_keyid",value:a.key})).append($("<input>").attr({type:"hidden",name:"_passwd",value:a.password}));this.submit_messageform("savedraft"==this.env.last_action)};
|
|
rcube_webmail.prototype.enigma_key_not_found=function(a){var b=[{"class":"mainaction search",text:a.button,click:function(){$(this).remove();rcmail.enigma_find_publickey(a.email)}}];"encrypt"==a.mode&&b.push({"class":"send",text:rcmail.get_label("enigma.sendunencrypted"),click:function(c){$(this).remove();$("#enigmaencryptopt").prop("checked",!1).change();rcmail.command("send",{nocheck:!0},c.target,c.originalEvent)}});b.push({"class":"cancel",text:this.get_label("cancel"),click:function(){$(this).remove()}});
|
|
return this.show_popup_dialog(a.text,a.title,b,{width:500,dialogClass:"error"})};rcube_webmail.prototype.enigma_find_publickey=function(a){this.mailvelope_search_pubkeys([a],function(b){},function(b){var c=rcmail.set_busy(!0,"enigma.importwait");b={_a:"import",_keys:b};"plugin.enigmakeys"==rcmail.env.action&&(b._refresh=1);rcmail.http_post("plugin.enigmakeys",b,c)})};
|