/** * Roundcube Webmail Client Script * * This file is part of the Roundcube Webmail client * * @licstart The following is the entire license notice for the * JavaScript code in this file. * * Copyright (C) 2005-2015, The Roundcube Dev Team * Copyright (C) 2011-2015, Kolab Systems AG * * 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 (GNU GPL) as published by the Free Software * Foundation, either version 3 of the License, or (at your option) * any later version. The code is distributed WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. * * As additional permission under GNU GPL version 3 section 7, you * may distribute non-source (e.g., minimized or compacted) forms of * that code without the copy of the GNU GPL normally required by * section 4, provided you include this license notice and a URL * through which recipients can access the Corresponding Source. * * @licend The above is the entire license notice * for the JavaScript code in this file. * * @author Thomas Bruederli * @author Aleksander 'A.L.E.C' Machniak * @author Charles McNulty * * @requires jquery.js, common.js, list.js */ function rcube_webmail(){this.labels={};this.buttons={};this.buttons_sel={};this.gui_objects={};this.gui_containers={};this.commands={};this.command_handlers={};this.onloads=[];this.messages={};this.group2expand={};this.http_request_jobs={};this.menu_stack=[];this.dblclick_time=500;this.message_time=5E3;this.identifier_expr=/[^0-9a-z_-]/gi;this.env={request_timeout:180,draft_autosave:0,comm_path:"./",recipients_separator:",",recipients_delimiter:", ",popup_width:1150,popup_width_small:900};this.ref= "rcmail";var f=this;$.ajaxSetup({cache:!1,timeout:1E3*this.env.request_timeout,error:function(a,b,d){f.http_error(a,b,d)},beforeSend:function(a){a.setRequestHeader("X-Roundcube-Request",f.env.request_token)}});$(window).on("beforeunload",function(){f.unload=!0});this.set_env=function(a,b){if(null==a||"object"!==typeof a||b)this.env[a]=b;else for(var d in a)this.env[d]=a[d]};this.add_label=function(a,b){"string"==typeof a?this.labels[a]=b:"object"==typeof a&&$.extend(this.labels,a)};this.register_button= function(a,b,d,e,g,h){b={id:b,type:d};e&&(b.act=e);g&&(b.sel=g);h&&(b.over=h);this.buttons[a]||(this.buttons[a]=[]);this.buttons[a].push(b);this.loaded&&v(a,b)};this.gui_object=function(a,b){this.gui_objects[a]=this.loaded?rcube_find_object(b):b};this.gui_container=function(a,b){this.gui_containers[a]=b};this.add_element=function(a,b){this.gui_containers[b]&&this.gui_containers[b].jquery&&this.gui_containers[b].append(a)};this.register_command=function(a,b,d){this.command_handlers[a]=b;d&&this.enable_command(a, !0)};this.add_onload=function(a){this.onloads.push(a)};this.init=function(){var a;this.task=this.env.task;if(409==this.env.server_error||bw.dom&&bw.xmlhttp_test()){this.env.blankpage||(this.env.blankpage=this.assets_path("program/resources/blank.gif"));for(a in this.gui_containers)this.gui_containers[a]=$("#"+this.gui_containers[a]);for(a in this.gui_objects)this.gui_objects[a]=rcube_find_object(this.gui_objects[a]);if(a=this.env.x_frame_options)try{if("deny"==a.toLowerCase()&&top.location.href!= self.location.href)top.location.href=self.location.href;else{if(/^allow-from[\s\t]+(.+)$/i.test(a)&&0!=RegExp.$1.indexOf(top.location.origin))throw 1;if(top.location.hostname!=self.location.hostname)throw 1;}}catch(k){$("form").each(function(){f.lock_form(this,!0)});this.display_message("Blocked: possible clickjacking attack!","error");return}this.init_buttons();this.is_framed()&&(parent.rcmail.set_busy(!1,null,parent.rcmail.env.frame_lock),parent.rcmail.env.frame_lock=null);this.enable_command("close", "logout","mail","addressbook","settings","save-pref","compose","undo","about","switch-task","menu-open","menu-close","menu-save",!0);this.set_button(this.task,"sel");this.env.permaurl&&this.enable_command("permaurl","extwin",!0);switch(this.task){case "mail":this.enable_command("list","checkmail","add-contact","search","reset-search","collapse-folder","import-messages",!0);this.gui_objects.messagelist&&(this.env.widescreen_list_template=[{className:"threads",cells:["threads"]},{className:"subject", cells:["fromto","date","status","subject"]},{className:"flags",cells:["flag","attachment"]}],this.message_list=new rcube_list_widget(this.gui_objects.messagelist,{multiselect:!0,multiexpand:!0,draggable:!0,keyboard:!0,column_movable:this.env.col_movable,dblclick_time:this.dblclick_time}),this.message_list.addEventListener("initrow",function(a){f.init_message_row(a)}).addEventListener("dblclick",function(a){f.msglist_dbl_click(a)}).addEventListener("click",function(a){f.msglist_click(a)}).addEventListener("keypress", function(a){f.msglist_keypress(a)}).addEventListener("select",function(a){f.msglist_select(a)}).addEventListener("dragstart",function(a){f.drag_start(a)}).addEventListener("dragmove",function(a){f.drag_move(a)}).addEventListener("dragend",function(a){f.drag_end(a)}).addEventListener("expandcollapse",function(a){f.msglist_expand(a)}).addEventListener("column_replace",function(a){f.msglist_set_coltypes(a)}).addEventListener("listupdate",function(a){f.triggerEvent("listupdate",a)}).init(),$(this.message_list.thead).on("click", "a.sortcol",function(a){return f.command("sort",$(this).attr("rel"),this)}),this.enable_command("toggle_status","toggle_flag","sort",!0),this.enable_command("set-listmode",this.env.threads&&!this.is_multifolder_listing()),this.command("list"),$(this.gui_objects.qsearchbox).val(this.env.search_text).focusin(function(){f.message_list.blur()}));this.set_button_titles();this.env.message_commands="show reply reply-all reply-list move copy delete open mark edit viewsource print load-attachment download-attachment show-headers hide-headers download forward forward-inline forward-attachment change-format".split(" "); if("show"==this.env.action||"preview"==this.env.action){if(this.enable_command(this.env.message_commands,this.env.uid),this.enable_command("reply-list",this.env.list_post),"show"==this.env.action&&this.http_request("pagenav",{_uid:this.env.uid,_mbox:this.env.mailbox,_search:this.env.search_request},this.display_message("","loading")),0 a",this.gui_objects.attachments).not(".drop").on("dragstart",function(a){var b=this.href,d=a.originalEvent.dataTransfer;d&&(b=b.replace(/^https?:\/\//,function(a){return a+urlencode(f.env.username)+ "@"}),a=$(this).clone(),a.children().remove(),d.setData("roundcube-uri",b),d.setData("roundcube-name",$.trim(a.text())))})}else if("compose"==this.env.action)this.env.address_group_stack=[],this.env.compose_commands="send-attachment remove-attachment send cancel toggle-editor list-addresses pushgroup search reset-search extwin insert-response save-response menu-open menu-close load-attachment download-attachment open-attachment rename-attachment".split(" "),this.env.drafts_mailbox&&this.env.compose_commands.push("savedraft"), this.enable_command(this.env.compose_commands,"identities","responses",!0),$.merge(this.env.compose_commands,["add-recipient","firstpage","previouspage","nextpage","lastpage"]),window.googie&&(this.env.editor_config.spellchecker=googie,this.env.editor_config.spellcheck_observer=function(a){f.spellcheck_state()},this.env.compose_commands.push("spellcheck"),this.enable_command("spellcheck",!0)),this.editor_init(this.env.editor_config,this.env.composebody),this.gui_objects.responseslist&&($("a.insertresponse", this.gui_objects.responseslist).attr("unselectable","on").mousedown(function(a){return rcube_event.cancel(a)}).on("mouseup keypress",function(a){if("mouseup"==a.type||13==rcube_event.get_keycode(a))return f.command("insert-response",$(this).attr("rel")),$(document.body).trigger("mouseup"),rcube_event.cancel(a)}),$.each(this.buttons["save-response"]||[],function(a,b){$("#"+b.id).mousedown(function(a){return rcube_event.cancel(a)})})),this.init_messageform();else if("get"==this.env.action){if(this.enable_command("download", !0),bw.mz&&"application/pdf"==this.env.mimetype?(a=0,$(this.gui_objects.messagepartframe).on("load",function(){if(a++)try{this.contentWindow.document,f.enable_command("print",!0)}catch(k){}})):this.enable_command("print",!0),this.env.is_message&&(this.enable_command("reply","reply-all","edit","viewsource","forward","forward-inline","forward-attachment",!0),this.env.list_post&&this.enable_command("reply-list",!0)),this.env.mimetype.startsWith("image/"))$(this.gui_objects.messagepartframe).on("load", function(){$(this).contents().find("head").append('')})}else"print"!=this.env.action||!this.env.uid||this.env.is_pgp_content||this.env.pgp_mime_part||this.print_dialog();this.gui_objects.mailboxlist&&(this.env.unread_counts={},this.gui_objects.folderlist=this.gui_objects.mailboxlist,this.http_request("getunread",{_page:this.env.current_page})); this.gui_objects.contactslist&&(this.contact_list=new rcube_list_widget(this.gui_objects.contactslist,{multiselect:!0,draggable:!1,keyboard:!0}),this.contact_list.addEventListener("initrow",function(a){f.triggerEvent("insertrow",{cid:a.uid,row:a})}).addEventListener("select",function(a){f.compose_recipient_select(a)}).addEventListener("dblclick",function(a){f.compose_add_recipient()}).addEventListener("keypress",function(a){a.key_pressed==a.ENTER_KEY&&(f.compose_add_recipient()||a.last_selected&& "G"==String(a.last_selected).charAt(0)&&$(a.rows[a.last_selected].obj).find("a").first().click())}).init(),$("#_to,#_cc,#_bcc").focus(function(){f.env.focused_field=this}));this.gui_objects.addressbookslist&&(this.gui_objects.folderlist=this.gui_objects.addressbookslist,this.enable_command("list-addresses",!0));if(this.env.mdn_request&&this.env.uid){var b="sendmdn",d={_uid:this.env.uid,_mbox:this.env.mailbox};confirm(this.get_label("mdnrequest"))||(d._flag="mdnsent",b="mark");this.http_post(b,d)}this.check_mailvelope(this.env.action); this.is_framed()||this.env.extwin||this.browser_capabilities_check();break;case "addressbook":this.env.address_group_stack=[];this.gui_objects.folderlist&&(this.env.contactfolders=$.extend($.extend({},this.env.address_sources),this.env.contactgroups));this.enable_command("add","import",this.env.writable_source);this.enable_command("list","listgroup","pushgroup","popgroup","listsearch","search","reset-search","advanced-search",!0);this.gui_objects.contactslist&&(this.contact_list=new rcube_list_widget(this.gui_objects.contactslist, {multiselect:!0,draggable:this.gui_objects.folderlist?!0:!1,keyboard:!0}),this.contact_list.addEventListener("initrow",function(a){f.triggerEvent("insertrow",{cid:a.uid,row:a})}).addEventListener("keypress",function(a){f.contactlist_keypress(a)}).addEventListener("select",function(a){f.contactlist_select(a)}).addEventListener("dragstart",function(a){f.drag_start(a)}).addEventListener("dragmove",function(a){f.drag_move(a)}).addEventListener("dragend",function(a){f.drag_end(a)}).init(),$(this.gui_objects.qsearchbox).focusin(function(){f.contact_list.blur()}), this.update_group_commands(),this.command("list"));this.gui_objects.savedsearchlist&&(this.savedsearchlist=new rcube_treelist_widget(this.gui_objects.savedsearchlist,{id_prefix:"rcmli",id_encode:this.html_identifier_encode,id_decode:this.html_identifier_decode}),this.savedsearchlist.addEventListener("select",function(a){f.triggerEvent("selectfolder",{folder:a.id,prefix:"rcmli"})}));this.set_page_buttons();this.env.cid&&(this.enable_command("show","edit","qrcode",!0),this.gui_objects.editform&&$("input.groupmember").change(function(){f.group_member_change(this.checked? "add":"del",f.env.cid,f.env.source,this.value)}));this.gui_objects.editform?(this.enable_command("save",!0),"add"!=this.env.action&&"edit"!=this.env.action&&"search"!=this.env.action||this.init_contact_form()):"print"==this.env.action&&this.print_dialog();break;case "settings":this.enable_command("preferences","identities","responses","save","folders",!0);"identities"==this.env.action?this.enable_command("add",2>this.env.identities_level):"edit-identity"==this.env.action||"add-identity"==this.env.action? (this.enable_command("save","edit","toggle-editor",!0),this.enable_command("delete",2>this.env.identities_level),this.editor_init(this.env.editor_config,"rcmfd_signature")):"folders"==this.env.action?this.enable_command("subscribe","unsubscribe","create-folder","rename-folder",!0):"edit-folder"==this.env.action&&this.gui_objects.editform?(this.enable_command("save","folder-size",!0),parent.rcmail.env.exists=this.env.messagecount,parent.rcmail.enable_command("purge",this.env.messagecount)):"responses"== this.env.action&&this.enable_command("add",!0);this.gui_objects.identitieslist?(this.identity_list=new rcube_list_widget(this.gui_objects.identitieslist,{multiselect:!1,draggable:!1,keyboard:!0}),this.identity_list.addEventListener("select",function(a){f.identity_select(a)}).addEventListener("keypress",function(a){a.key_pressed==a.ENTER_KEY&&f.identity_select(a)}).init().focus()):this.gui_objects.sectionslist?(this.sections_list=new rcube_list_widget(this.gui_objects.sectionslist,{multiselect:!1, draggable:!1,keyboard:!0}),this.sections_list.addEventListener("select",function(a){f.section_select(a)}).addEventListener("keypress",function(a){a.key_pressed==a.ENTER_KEY&&f.section_select(a)}).init().focus()):this.gui_objects.subscriptionlist?this.init_subscription_list():this.gui_objects.responseslist&&(this.responses_list=new rcube_list_widget(this.gui_objects.responseslist,{multiselect:!1,draggable:!1,keyboard:!0}),this.responses_list.addEventListener("select",function(a){var b;a=a.get_single_selection(); f.enable_command("delete",!!a&&0>$.inArray(a,f.env.readonly_responses));a&&(b=f.get_frame_window(f.env.contentframe))&&(f.set_busy(!0),f.location_href({_action:"edit-response",_key:a,_framed:1},b))}).init().focus());break;case "login":var e=window.jstz,g=$("#rcmloginuser"),h=$("#rcmlogintz");g.keyup(function(a){return f.login_user_keyup(a)});""==g.val()?g.focus():$("#rcmloginpwd").focus();e&&(b=e.determine())&&(d=b.name());h.val(d?d:(new Date).getStdTimezoneOffset()/-60);$("form").submit(function(){$("input[type=submit]", this).prop("disabled",!0);f.clear_messages();f.display_message("","loading")});this.enable_command("login",!0)}this.gui_objects.editform&&$("input,select,textarea",this.gui_objects.editform).not(":hidden").not(":disabled").first().select().focus();this.env.contentframe&&!$("#"+this.env.contentframe).is(":visible")&&(this.env.contentframe=null);bw.ie&&$("input[type=file]").keydown(function(a){"13"==a.keyCode&&a.preventDefault()});this.loaded=!0;this.env.lastrefresh=new Date;this.pending_message&&this.display_message.apply(this, this.pending_message);this.gui_objects.folderlist&&window.rcube_treelist_widget&&this.gui_objects.folderlist!=this.gui_objects.addressbookslist&&(this.treelist=new rcube_treelist_widget(this.gui_objects.folderlist,{selectable:!0,id_prefix:"rcmli",parent_focus:!0,id_encode:this.html_identifier_encode,id_decode:this.html_identifier_decode,check_droptarget:function(a){return!a.virtual&&f.check_droptarget(a.id)}}),this.treelist.addEventListener("collapse",function(a){f.folder_collapsed(a)}).addEventListener("expand", function(a){f.folder_collapsed(a)}).addEventListener("beforeselect",function(a){return!f.busy}).addEventListener("select",function(a){f.triggerEvent("selectfolder",{folder:a.id,prefix:"rcmli"});f.mark_all_read_state()}));this.gui_objects.filedrop&&this.env.filedrop&&(window.XMLHttpRequest&&XMLHttpRequest.prototype&&XMLHttpRequest.prototype.sendAsBinary||window.FormData)&&($(document.body).on("dragover dragleave drop",function(a){return f.document_drag_hover(a,"dragover"==a.type)}),$(this.gui_objects.filedrop).addClass("droptarget").on("dragover dragleave", function(a){return f.file_drag_hover(a,"dragover"==a.type)}).get(0).addEventListener("drop",function(a){return f.file_dropped(a)},!1));b=function(a){return f.doc_mouse_up(a)};$(document.body).mouseup(b).keydown(function(a){return f.doc_keypress(a)});rcube_webmail.set_iframe_events({mouseup:b});this.triggerEvent("init",{task:this.task,action:this.env.action});for(a in this.onloads)if("string"===typeof this.onloads[a])eval(this.onloads[a]);else if("function"===typeof this.onloads[a])this.onloads[a](); this.start_refresh();this.start_keepalive()}else this.goto_url("error","_code=0x199")};this.log=function(a){this.env.devel_mode&&window.console&&console.log&&console.log(a)};this.command=function(a,b,d,e){var g,h,k,l=!1;!d||!d.blur||e&&rcube_event.is_keyboard(e)||d.blur();if(this.busy&&("reset-search"!=a||"search"!=this.last_command)&&!a.match(/^menu-/))return!1;if(d&&d.href&&0>String(d.href).indexOf("#")&&rcube_event.get_modifier(e))return!0;if(!this.commands[a])return this.is_framed()&&parent.rcmail.command(a, b),!1;if("mail"==this.task&&"compose"==this.env.action&&!this.env.server_error&&"save-pref"!=a&&0>$.inArray(a,this.env.compose_commands)){if(!this.env.is_sent&&this.cmp_hash!=this.compose_field_hash()&&!confirm(this.get_label("notsentwarning")))return!1;this.remove_compose_data(this.env.compose_id);this.compose_skip_unsavedcheck=!0}this.last_command=a;if("function"===typeof this.command_handlers[a])return g=this.command_handlers[a](b,d,e),void 0!==g?g:d?!1:!0;if("string"===typeof this.command_handlers[a])return g= window[this.command_handlers[a]](b,d,e),void 0!==g?g:d?!1:!0;this.triggerEvent("actionbefore",{props:b,action:a,originalEvent:e});g=this.triggerEvent("before"+a,b||e);if(void 0!==g){if(!1===g)return!1;b=g}g=void 0;switch(a){case "login":this.gui_objects.loginform&&this.gui_objects.loginform.submit();break;case "logout":case "mail":case "addressbook":case "settings":this.switch_task(a);break;case "about":this.redirect("?_task=settings&_action=about",!1);break;case "permaurl":if(d&&d.href&&d.target)return!0; this.env.permaurl&&(parent.location.href=this.env.permaurl);break;case "extwin":if("compose"==this.env.action){if(e=this.gui_objects.messageform,h=this.open_window(""))this.save_compose_form_local(),this.compose_skip_unsavedcheck=!0,$("input[name='_action']",e).val("compose"),e.action=this.url("mail/compose",{_id:this.env.compose_id,_extwin:1}),e.target=h.name,e.submit()}else this.open_window(this.env.permaurl,!0);break;case "change-format":e=this.env.permaurl+"&_format="+b;"preview"==this.env.action&& (e=e.replace(/_action=show/,"_action=preview")+"&_framed=1");this.env.extwin&&(e+="&_extwin=1");location.href=e;break;case "menu-open":b&&"attachmentmenu"==b.menu&&((h=this.env.attachments[b.id])&&h.mimetype&&(h=h.mimetype),this.enable_command("open-attachment",h&&this.env.mimetypes&&0<=$.inArray(h,this.env.mimetypes)));this.show_menu(b,b.show||void 0,e);break;case "menu-close":this.hide_menu(b,e);break;case "menu-save":return this.triggerEvent(a,{props:b,originalEvent:e}),!1;case "open":if(h=this.get_single_uid())return d.href= this.url("show",this.params_from_uid(h)),!0;break;case "close":this.env.extwin&&window.close();break;case "list":b&&""!=b&&this.reset_qsearch(!0);"compose"==this.env.action&&this.env.extwin?window.close():"mail"==this.task?(this.list_mailbox(b),this.set_button_titles()):"addressbook"==this.task&&this.list_contacts(b);break;case "set-listmode":this.set_list_options(null,void 0,void 0,"threads"==b?1:0);break;case "sort":e=this.env.sort_order;h=this.env.disabled_sort_col?this.env.sort_col:b;this.env.disabled_sort_order|| (e=this.env.sort_col==h&&"ASC"==e?"DESC":"ASC");this.set_list_sorting(h,e);this.list_mailbox("","",h+"_"+e);break;case "nextpage":this.list_page("next");break;case "lastpage":this.list_page("last");break;case "previouspage":this.list_page("prev");break;case "firstpage":this.list_page("first");break;case "expunge":this.env.exists&&this.expunge_mailbox(this.env.mailbox);break;case "purge":case "empty-mailbox":this.env.exists&&this.purge_mailbox(this.env.mailbox);break;case "show":"mail"==this.task? (h=this.get_single_uid(),!h||this.env.uid&&h==this.env.uid||(this.env.mailbox==this.env.drafts_mailbox?this.open_compose_step({_draft_uid:h,_mbox:this.env.mailbox}):this.show_message(h))):"addressbook"==this.task&&(k=b?b:this.get_single_cid(),!k||"show"==this.env.action&&k==this.env.cid||this.load_contact(k,"show"));break;case "add":if("addressbook"==this.task)this.load_contact(0,"add");else if("settings"==this.task&&"responses"==this.env.action){if(e=this.get_frame_window(this.env.contentframe))this.set_busy(!0), this.location_href({_action:"add-response",_framed:1},e)}else"settings"==this.task&&(this.identity_list.clear_selection(),this.load_identity(0,"add-identity"));break;case "edit":"addressbook"==this.task&&(k=this.get_single_cid())?this.load_contact(k,"edit"):"settings"==this.task&&b?this.load_identity(b,"edit-identity"):"mail"==this.task&&(h=this.get_single_uid())&&(e={_mbox:this.get_message_mailbox(h)},e[this.env.mailbox==this.env.drafts_mailbox&&"new"!=b?"_draft_uid":"_uid"]=h,this.open_compose_step(e)); break;case "save":var m;if(e=this.gui_objects.editform){if("search"!=this.env.action)if((m=$("input[name='_pagesize']",e))&&m.length&&isNaN(parseInt(m.val()))){alert(this.get_label("nopagesizewarning"));m.focus();break}else if("reload"==b)e.action+="&_reload=1";else if("settings"==this.task&&0==this.env.identities_level%2&&(m=$("input[name='_email']",e))&&m.length&&!rcube_check_email(m.val())){alert(this.get_label("noemailwarning"));m.focus();break}parent.rcmail&&parent.rcmail.env.source&&(e.action= this.add_url(e.action,"_orig_source",parent.rcmail.env.source));e.submit()}break;case "delete":"mail"==this.task?this.delete_messages(e):"addressbook"==this.task?this.delete_contacts():"settings"==this.task&&"responses"==this.env.action?this.delete_response():"settings"==this.task&&this.delete_identity();break;case "move":case "moveto":"mail"==this.task?this.move_messages(b,e):"addressbook"==this.task&&this.move_contacts(b);break;case "copy":"mail"==this.task?this.copy_messages(b,e):"addressbook"== this.task&&this.copy_contacts(b);break;case "mark":b&&this.mark_message(b);break;case "toggle_status":case "toggle_flag":e="toggle_flag"==a?"flagged":"read";if(h=b)"flagged"==e?this.message_list.rows[h].flagged&&(e="unflagged"):this.message_list.rows[h].deleted?e="undelete":this.message_list.rows[h].unread||(e="unread"),this.mark_message(e,h);break;case "always-load":if(this.env.uid&&this.env.sender){this.add_contact(this.env.sender);setTimeout(function(){f.command("load-images")},300);break}case "load-images":this.env.uid&& this.show_message(this.env.uid,!0,"preview"==this.env.action);break;case "load-attachment":case "open-attachment":case "download-attachment":h=this.env.attachments[b];"compose"==this.env.action?(e={_file:b,_id:this.env.compose_id},h=h?h.mimetype:""):e={_mbox:this.env.mailbox,_uid:this.env.uid,_part:b};if("download-attachment"!=a&&h&&this.env.mimetypes&&0<=$.inArray(h,this.env.mimetypes)&&this.open_window(this.url("get",$.extend({_frame:1},e))))break;this.compose_skip_unsavedcheck=e._download=1;this.goto_url("get", e,!1,!0);this.compose_skip_unsavedcheck=0;break;case "select-all":this.select_all_mode=b?!1:!0;this.dummy_select=!0;"invert"==b?this.message_list.invert_selection():this.message_list.select_all("page"==b?"":b);this.dummy_select=null;break;case "select-none":this.select_all_mode=!1;this.message_list.clear_selection();break;case "expand-all":this.env.autoexpand_threads=1;this.message_list.expand_all();break;case "expand-unread":this.env.autoexpand_threads=2;this.message_list.collapse_all();this.expand_unread(); break;case "collapse-all":this.env.autoexpand_threads=0;this.message_list.collapse_all();break;case "nextmessage":this.env.next_uid&&this.show_message(this.env.next_uid,!1,"preview"==this.env.action);break;case "lastmessage":this.env.last_uid&&this.show_message(this.env.last_uid);break;case "previousmessage":this.env.prev_uid&&this.show_message(this.env.prev_uid,!1,"preview"==this.env.action);break;case "firstmessage":this.env.first_uid&&this.show_message(this.env.first_uid);break;case "compose":e= {};if("mail"==this.task)e={_mbox:this.env.mailbox,_search:this.env.search_request},b&&(e._to=b);else if("addressbook"==this.task)if(b&&0a?"prevAll":"nextAll",e=0>a?"last":"first";return f.focused_menu&&(b=$("#"+f.focused_menu))?(a=b.find(":focus").closest("li")[d](":has(:not([aria-disabled=true]))").find("a,input")[e](),a.length||(a=b.find(":focus").closest("ul")[d](":has(:not([aria-disabled=true]))").find("a,input")[e]()),a.focus().length): 0},d=a.target||{},e=rcube_event.get_keycode(a);if(27!=a.keyCode&&(!this.menu_keyboard_active||"TEXTAREA"==d.nodeName||"SELECT"==d.nodeName))return!0;switch(e){case 38:case 40:case 63232:case 63233:return b(38==e||63232==e?-1:1),rcube_event.cancel(a);case 9:return this.focused_menu&&(d=rcube_event.get_modifier(a),b(d==SHIFT_KEY?-1:1)||this.hide_menu(this.focused_menu,a)),rcube_event.cancel(a);case 27:this.menu_stack.length&&this.hide_menu(this.menu_stack[this.menu_stack.length-1],a)}return!0};this.msglist_select= function(a){this.preview_timer&&clearTimeout(this.preview_timer);var b=a.get_single_selection();this.enable_command(this.env.message_commands,null!=b);b&&(this.env.mailbox==this.env.drafts_mailbox?this.enable_command("reply","reply-all","reply-list","forward","forward-attachment","forward-inline",!1):this.env.messages[b].ml||this.enable_command("reply-list",!1));this.enable_command("delete","move","copy","mark","forward","forward-attachment",0"+this.get_label("loading")+""),this.triggerEvent("openwindow",{url:a,handle:g}),setTimeout(function(){g&&g.focus()},10),g};this.init_message_row=function(a){var b={},d=a.uid,e=(null!=this.env.status_col?"status":"msg")+"icn"+a.id;d&&this.env.messages[d]&&$.extend(a,this.env.messages[d]);if(a.icon=document.getElementById(e))b.icon= function(a){f.command("toggle_status",d)};a.msgicon=null!=this.env.status_col?document.getElementById("msgicn"+a.id):a.icon;null!=this.env.flagged_col&&(a.flagicon=document.getElementById("flagicn"+a.id))&&(b.flagicon=function(a){f.command("toggle_flag",d)});!a.depth&&a.has_children&&(a.expando=document.getElementById("rcmexpando"+a.id))&&(b.expando=function(a){f.expand_message_row(a,d)});$.each(b,function(b,d){a[b].onclick=function(a){d(a);return rcube_event.cancel(a)};bw.touch&&a[b].addEventListener&& a[b].addEventListener("touchend",function(a){if(1==a.changedTouches.length)return d(a),rcube_event.cancel(a)},!1)});this.triggerEvent("insertrow",{uid:d,row:a})};this.add_message_row=function(a,b,d,e){if(!this.gui_objects.messagelist||!this.message_list||d.mbox!=this.env.mailbox&&!d.skip_mbox_check)return!1;this.env.messages[a]||(this.env.messages[a]={});$.extend(this.env.messages[a],{deleted:d.deleted?1:0,replied:d.answered?1:0,unread:d.seen?0:1,forwarded:d.forwarded?1:0,flagged:d.flagged?1:0,has_children:d.has_children? 1:0,depth:d.depth?d.depth:0,unread_children:d.unread_children||0,flagged_children:d.flagged_children||0,parent_uid:d.parent_uid||0,selected:this.select_all_mode||this.message_list.in_selection(a),ml:d.ml?1:0,ctype:d.ctype,mbox:d.mbox,flags:d.extra_flags});var g,h,f,l,m="",n=f="",p="",q=this.message_list;l=q.rows;var t=this.env.messages[a],u=this.html_identifier(a,!0),w="message"+(d.seen?"":" unread")+(d.deleted?" deleted":"")+(d.flagged?" flagged":"")+(t.selected?" selected":""),x={cols:[],style:{}, id:"rcmrow"+u,uid:a};g="msgicon";null===this.env.status_col&&(g+=" status",d.deleted?(m+=" deleted",f+=this.get_label("deleted")+" "):d.seen?0  ',l[t.parent_uid]&&!1===l[t.parent_uid].expanded||!(0!=this.env.autoexpand_threads&&2!=this.env.autoexpand_threads||l[t.parent_uid]&&l[t.parent_uid].expanded)?(x.style.display="none",t.expanded=!1):t.expanded=!0,w+=" thread expanded"):t.has_children&&(void 0===t.expanded&&(1==this.env.autoexpand_threads||2==this.env.autoexpand_threads&&t.unread_children)&&(t.expanded=!0),p='
  
', w+=" thread"+(t.expanded?" expanded":"")),d.unread_children&&d.seen&&!t.expanded&&(w+=" unroot"),d.flagged_children&&!t.expanded&&(w+=" flaggedroot"));n+='';x.className=w;b.subject&&(g=d.mbox==this.env.drafts_mailbox?"compose":"show",f={_mbox:d.mbox},f[d.mbox==this.env.drafts_mailbox?"_draft_uid":"_uid"]=a,b.subject=''+b.subject+"");for(h in this.env.listcols)g=this.env.listcols[h],f={className:String(g).toLowerCase(),events:{}},this.env.coltypes[g]&&this.env.coltypes[g].hidden&&(f.className+=" hidden"),"flag"==g?(g=d.flagged?"flagged":"unflagged",l=this.get_label(g),g=''):"attachment"==g?(l=this.get_label("withattachment"),g=d.attachmentClass?'': /application\/|multipart\/(m|signed)/.test(d.ctype)?'':/multipart\/report/.test(d.ctype)?'':"multipart/encrypted"==d.ctype||"application/pkcs7-mime"==d.ctype?'':" "):"status"==g?(l="",d.deleted?(g="deleted",l=this.get_label("deleted")):d.seen?g=0'):"threads"==g?g=p:"subject"==g?g=n+b[g]:"priority"==g?0d.prio?(l=this.get_label("priority")+" "+d.prio,g=''):g=" ":g="folder"==g?''+b[g]+"":b[g],f.innerHTML=g,x.cols.push(f);"widescreen"==this.env.layout&&(x=this.widescreen_message_row(x,a,t));q.insert_row(x,e);e&&this.env.pagesize&&q.rowcount>this.env.pagesize&&(a=q.get_last_row(),q.remove_row(a),q.clear_selection(a))}; this.widescreen_message_row=function(a,b,d){var e=document.createElement("tr");e.id=a.id;e.uid=a.uid;e.className=a.className;a.style&&$.extend(e.style,a.style);$.each(this.env.widescreen_list_template,function(){if(f.env.threading||"threads"!=this.className){var b,d,k,l=document.createElement("td");this.className&&(l.className=this.className);for(b=0;this.cells&&b a").prop("rel","arrival"==a?"arrival":"date");this.env.sort_col=a;this.env.sort_order=b};this.set_list_options=function(a,b,d,e,g){var h,f={};void 0===b&&(b=this.env.sort_col);d||(d=this.env.sort_order);if(this.env.sort_col!=b||this.env.sort_order!=d)h=1,this.set_list_sorting(b,d);this.env.threading!=e&&(h=1,f._threads=e);g&&this.env.layout!=g&&(this.triggerEvent("layout-change",{old_layout:this.env.layout,new_layout:g}),h=1,this.env.layout=f._layout= g);if(a&&a.length){var l,m=[],n=this.env.listcols;for(e=0;ed.location.href.indexOf(this.env.blankpage)&&(d.stop?d.stop():d.document.execCommand("Stop"),d.location.href=this.env.blankpage);else if(!bw.safari&&!bw.konq)$(b)[a?"show":"hide"]();!a&&this.env.frame_lock&&this.set_busy(!1,null,this.env.frame_lock)};this.get_frame_element=function(a){var b;if(a&& (b=document.getElementById(a)))return b};this.get_frame_window=function(a){if((a=this.get_frame_element(a))&&a.name&&window.frames)return window.frames[a.name]};this.lock_frame=function(){this.env.frame_lock||((this.is_framed()?parent.rcmail:this).env.frame_lock=this.set_busy(!0,"loading"))};this.list_page=function(a){"next"==a?a=this.env.current_page+1:"last"==a?a=this.env.pagecount:"prev"==a&&1d.depth?(g=e-d.depth,h[b][g]&2||(h[b][g]=h[b][g]?h[b][g]+2:2)):e==d.depth&&(h[b][0]&2||(h[b][0]+=2)),d.depth>e);b--);h.push(Array(d.depth));h[h.length-1][0]=1;f.push(d.uid)}else{if(h.length){for(b in h)this.set_tree_icons(f[b],h[b]);h=[];f=[]}if(a&&l!=m[a].obj)break}l=l.nextSibling}if(h.length)for(b in h)this.set_tree_icons(f[b], h[b])};this.set_tree_icons=function(a,b){var d,e=[],g="",h=b.length;for(d=0;d'):g+('
');g&&$("#rcmtab"+this.html_identifier(a,!0)).html(g)};this.update_thread_root=function(a, b){if(this.env.threading){var d=this.message_list.find_root(a);if(a!=d){var e=this.message_list.rows[d];if("read"==b&&e.unread_children)e.unread_children--;else if("unread"==b&&e.has_children)e.unread_children=(e.unread_children||0)+1;else if("unflagged"==b&&e.flagged_children)e.flagged_children--;else if("flagged"==b&&e.has_children)e.flagged_children=(e.flagged_children||0)+1;else return;this.set_message_icon(d);this.set_unread_children(d);this.set_flagged_children(d)}}};this.update_thread=function(a){if(!this.env.threading)return 0; var b,d,e=0,g=this.message_list.rows,h=g[a],k=g[a].depth,l=[];h.depth||e--;h.depth&&h.unread&&(d=this.message_list.find_root(a),g[d].unread_children--,this.set_unread_children(d));h.depth&&h.flagged&&(d=this.message_list.find_root(a),g[d].flagged_children--,this.set_flagged_children(d));d=h.parent_uid;for(h=h.obj.nextSibling;h;){if(1==h.nodeType&&(b=g[h.uid])){if(!b.depth||b.depth<=k)break;b.depth--;$("#rcmtab"+b.id).width(15*b.depth).html("");b.depth?(b.depth==k&&(b.parent_uid=d),b.unread&&l.length&& l[l.length-1].unread_children++):(e++,b.parent_uid=0,b.has_children&&($("#"+b.id+" .leaf:first").attr("id","rcmexpando"+b.id).attr("class","none"!=b.obj.style.display?"expanded":"collapsed").mousedown({uid:b.uid},function(a){return f.expand_message_row(a,a.data.uid)}),b.unread_children=0,l.push(b)),"none"==b.obj.style.display&&$(b.obj).show())}h=h.nextSibling}for(b=0;b$.inArray(m,n)&&n.push(m)),h&&this.message_list.remove_row(l,this.env.display_next&&f==p.length-1);!this.env.display_next&&h&&this.message_list.clear_selection();f=0;for(len=n.length;fg?b._count=-1*g:0h?d._count=-1*h:0=a.length?a.join(","):a};this.set_button_titles=function(){var a="deletemessage";this.env.flag_for_deletion||!this.env.trash_mailbox||this.env.mailbox==this.env.trash_mailbox||this.env.delete_junk&&this.env.junk_mailbox&&this.env.mailbox==this.env.junk_mailbox||(a="movemessagetotrash"); this.set_alttext("delete",a)};this.init_pagejumper=function(a){$(a).addClass("rcpagejumper").on("focus",function(b){var d,e="";for(d=1;d<=f.env.pagecount;d++)e+="
  • "+d+"
  • ";e='
      '+e+"
    ";f.pagejump||(f.pagejump=$('
    ').appendTo(document.body).on("click","li",function(){f.busy||$(a).val($(this).text()).change()}));f.pagejump.data("count")!=d&&f.pagejump.html(e);f.pagejump.attr("rel","#"+this.id).data("count",d);f.show_menu("pagejump-selector", !0,b);$(this).keydown()}).on("keydown keyup click",function(b){var d=$("#pagejump-selector"),e=$("ul",d),g=$("li",e);e.height();var h=parseInt(this.value);if(27!=b.which&&9!=b.which&&13!=b.which&&!d.is(":visible"))return f.show_menu("pagejump-selector",!0,b);if("keydown"==b.type)if(40==b.which)g.length>h&&(this.value=h+=1);else if(38==b.which)1h-1&&(this.value=--h);else{if(13==b.which)return $(this).change();if(27==b.which||9==b.which)return $(a).val(f.env.current_page)}$("li.selected", e).removeClass("selected");(b=$(g[h-1])).length&&(b.addClass("selected"),$("#pagejump-selector").scrollTop(e.height()/g.length*(h-1)-d.height()/2))}).on("change",function(a){(a=parseInt(this.value))&&a!=f.env.current_page&&!f.busy&&(f.hide_menu("pagejump-selector"),f.list_page(a))})};this.update_pagejumper=function(){$("input.rcpagejumper").val(this.env.current_page).prop("disabled",2>this.env.pagecount)};this.check_mailvelope=function(a){if("undefined"!==typeof window.mailvelope)this.mailvelope_load(a); else $(window).on("mailvelope",function(){f.mailvelope_load(a)})};this.mailvelope_load=function(a){this.env.browser_capabilities&&(this.env.browser_capabilities.pgpmime=1);var b=this.env.user_id;mailvelope.getKeyring(b).then(function(b){f.mailvelope_keyring=b;f.mailvelope_init(a,b)},function(d){mailvelope.createKeyring(b).then(function(b){f.mailvelope_keyring=b;f.mailvelope_init(a,b)},function(a){console.error(a)})})};this.mailvelope_init=function(a,b){if(window.mailvelope)if("show"==a||"preview"== a||"print"==a)if(this.env.is_pgp_content){var d=$(this.env.is_pgp_content).text();f.mailvelope_display_container(this.env.is_pgp_content,d,b)}else{if(this.env.pgp_mime_part){var e=this.display_message(this.get_label("loadingdata"),"loading"),g=this.env.pgp_mime_container;$.ajax({type:"GET",url:this.url("get",{_mbox:this.env.mailbox,_uid:this.env.uid,_part:this.env.pgp_mime_part}),error:function(a,b,d){f.http_error(a,b,d,e)},success:function(a){f.mailvelope_display_container(g,a,b,e)}})}}else if("compose"== a){this.env.compose_commands.push("compose-encrypted");var h=0<$('input[name="_is_html"]').val();if(this.env.pgp_mime_message){var k=this.set_busy(!0,this.get_label("loadingdata"));$.ajax({type:"GET",url:this.url("get",this.env.pgp_mime_message),error:function(a,b,d){f.http_error(a,b,d,k);f.enable_command("compose-encrypted",!h)},success:function(a){f.set_busy(!1,null,k);h&&(f.command("toggle-editor",{html:!1,noconvert:!0}),$("#"+f.env.composebody).val(""));f.compose_encrypted({quotedMail:a});f.enable_command("compose-encrypted", !0)}})}else this.enable_command("compose-encrypted",!h);this.addEventListener("actionafter",function(a){a.ret&&"toggle-editor"==a.action&&f.enable_command("compose-encrypted",!a.props.html)})}};this.compose_encrypted=function(a){var b,d=$("#"+this.env.composebody).parent();f.mailvelope_editor?(f.mailvelope_editor=null,f.compose_skip_unsavedcheck=!1,f.set_button("compose-encrypted","act"),d.removeClass("mailvelope").find("iframe:not([aria-hidden=true])").remove(),$("#"+f.env.composebody).show(),$("[name='_pgpmime']").remove(), f.enable_command("spellcheck","insert-sig","toggle-editor","insert-response","save-response",!0),f.triggerEvent("compose-encrypted",{active:!1})):(this.spellcheck_state()&&this.editor.spellcheck_stop(),b=a.quotedMail?{quotedMail:a.quotedMail,quotedMailIndent:!1}:{predefinedText:$("#"+this.env.composebody).val()},"reply"==this.env.compose_mode&&(b.quotedMailIndent=!0,b.quotedMailHeader=this.env.compose_reply_header),mailvelope.createEditorContainer("#"+d.attr("id"),f.mailvelope_keyring,b).then(function(a){f.mailvelope_editor= a;f.compose_skip_unsavedcheck=!0;f.set_button("compose-encrypted","sel");d.addClass("mailvelope");$("#"+f.env.composebody).hide();f.enable_command("spellcheck","insert-sig","toggle-editor","insert-response","save-response",!1);f.triggerEvent("compose-encrypted",{active:!0});f.env.attachments&&!$.isEmptyObject(f.env.attachments)&&(alert(f.get_label("encryptnoattachments")),$.each(f.env.attachments,function(a,b){f.remove_from_attachment_list(a)}))},function(a){console.error(a);console.log(b)}))};this.mailvelope_submit_messageform= function(a,b){var d=[];$.each(["to","cc","bcc"],function(a,b){for(var e,g=$.trim($('[name="_'+b+'"]').val());g.length&&rcube_check_email(g,!0);)e=RegExp.$2,d.push(e),g=g.substr(g.indexOf(e)+e.length+1).replace(/^\s*,\s*/,"")});var e=0"+f.get_label("searchpubkeyservers")+ "

    ","encryptedsendialog",function(){f.mailvelope_search_pubkeys(h,function(){return!0})},{button:"search"}),!1;if(!e)return d.length||(alert(f.get_label("norecipientwarning")),$("[name='_to']").focus()),!1;var k=[],l=f.env.identities[$("[name='_from'] option:selected").val()];$.each(f.env.identities,function(a,b){k.push(b.email)});f.mailvelope_keyring.validKeyForAddress(k).then(function(e){valid_sender=null;$.each(e,function(a,b){if(!1!==b&&(valid_sender=a,valid_sender==l))return!1});if(!valid_sender&& !confirm(f.get_label("nopubkeyforsender")))return!1;d.push(valid_sender);f.mailvelope_editor.encrypt(d).then(function(d){var e=f.gui_objects.messageform,g=$("[name='_pgpmime']",e),h=f.set_busy(!0,a||b?"savingmessage":"sendingmessage");e.target="savetarget";e._draft.value=a?"1":"";e.action=f.add_url(e.action,"_unlock",h);e.action=f.add_url(e.action,"_framed",1);b&&(e.action=f.add_url(e.action,"_saveonly",1));g.length||(g=$('').appendTo(e));g.val(d);e.submit()}, function(a){console.log(a)})},function(a){console.error(a)})},function(a){console.error(a)});return!1};this.mailvelope_display_container=function(a,b,d,e){var g=function(b){$(a+" > iframe").remove();f.hide_message(e);f.display_message(b.message,"error")};mailvelope.createDisplayContainer(a,b,d,{showExternalContent:this.env.safemode}).then(function(b){if(b.error&&b.error.message)return g(b.error);f.hide_message(e);$(a).addClass("mailvelope").children().not("iframe").hide();f.env.pgp_mime_part&&$("#attach"+ f.env.pgp_mime_part).remove();setTimeout(function(){$(window).resize()},10)},g)};this.mailvelope_search_pubkeys=function(a,b,d){var e=[],g=new PublicKey,h=f.display_message(f.get_label("loading"),"loading");$.each(a,function(a,b){var d=$.Deferred();g.search(b,function(a,e){null!==e?d.resolve([b]):d.resolve([b].concat(a))});e.push(d)});$.when.apply($,e).then(function(){var a=[],e=[];$.each(arguments,function(b,d){var g=d.shift();d.length?e=e.concat(d):a.push(g)});f.hide_message(h);b(!0);e.length&& f.mailvelope_key_import_dialog(e,d);a.length&&f.display_message(f.get_label("nopubkeyfor").replace("$email",a.join(", ")),"warning")}).fail(function(){console.error("Pubkey lookup failed with",arguments);f.hide_message(h);f.display_message("pubkeysearcherror","error");b(!1)})};this.mailvelope_key_import_dialog=function(a,b){var d=$("
    ").addClass("listing pgpkeyimport");$.each(a,function(a,b){var e=$("
    ").addClass("key");b.revoked&&e.addClass("revoked");b.disabled&&e.addClass("disabled");b.expired&& e.addClass("expired");e.append($("