/**
 * 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 <roundcube@gmail.com>
 * @author Aleksander 'A.L.E.C' Machniak <alec@alec.pl>
 * @author Charles McNulty <charles@charlesmcnulty.com>
 *
 * @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.preview_delay_select=400,this.preview_delay_click=60,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 ref=this;$.ajaxSetup({cache:!1,timeout:1e3*this.env.request_timeout,error:function(e,t,s){ref.http_error(e,t,s)},beforeSend:function(e){e.setRequestHeader("X-Roundcube-Request",ref.env.request_token)}}),$(window).on("beforeunload",(function(){ref.unload=!0})),this.set_env=function(e,t){if(null==e||"object"!=typeof e||t)this.env[e]=t;else for(var s in e)this.env[s]=e[s]},this.add_label=function(e,t){"string"==typeof e?this.labels[e]=t:"object"==typeof e&&$.extend(this.labels,e)},this.register_button=function(e,t,s,i,n,a){var r={id:t,type:s};i&&(r.act=i),n&&(r.sel=n),a&&(r.over=a),this.buttons[e]||(this.buttons[e]=[]),this.buttons[e].push(r),this.loaded&&init_button(e,r)},this.gui_object=function(e,t){this.gui_objects[e]=this.loaded?rcube_find_object(t):t},this.gui_container=function(e,t){this.gui_containers[e]=t},this.add_element=function(e,t){this.gui_containers[t]&&this.gui_containers[t].jquery&&this.gui_containers[t].append(e)},this.register_command=function(e,t,s){this.command_handlers[e]=t,s&&this.enable_command(e,!0)},this.add_onload=function(e){this.onloads.push(e)},this.init=function(){var n;if(this.task=this.env.task,409==this.env.server_error||bw.dom&&bw.xmlhttp_test()){for(n in this.env.blankpage||(this.env.blankpage=this.assets_path("program/resources/blank.gif")),this.gui_containers)this.gui_containers[n]=$("#"+this.gui_containers[n]);for(n in this.gui_objects)this.gui_objects[n]=rcube_find_object(this.gui_objects[n]);switch(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),this.task){case"mail":if(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(e){ref.init_message_row(e)})).addEventListener("dblclick",(function(e){ref.msglist_dbl_click(e)})).addEventListener("keypress",(function(e){ref.msglist_keypress(e)})).addEventListener("select",(function(e){ref.msglist_select(e)})).addEventListener("dragstart",(function(e){ref.drag_start(e)})).addEventListener("dragmove",(function(e){ref.drag_move(e)})).addEventListener("dragend",(function(e){ref.drag_end(e)})).addEventListener("expandcollapse",(function(e){ref.msglist_expand(e)})).addEventListener("column_replace",(function(e){ref.msglist_set_coltypes(e)})).addEventListener("listupdate",(function(e){ref.triggerEvent("listupdate",e)})).init(),$(this.message_list.thead).on("click","a.sortcol",(function(e){return ref.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(){ref.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"],"show"==this.env.action||"preview"==this.env.action?(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")),this.env.mail_read_time>0&&setTimeout((function(){ref.http_post("mark",{_uid:ref.env.uid,_flag:"read",_mbox:ref.env.mailbox,_quiet:1})}),1e3*this.env.mail_read_time),this.env.blockedobjects&&(this.gui_objects.remoteobjectsmsg&&(this.gui_objects.remoteobjectsmsg.style.display="block"),this.enable_command("load-images","always-load",!0)),"preview"==this.env.action&&this.is_framed()&&(this.enable_command("compose","add-contact",!1),parent.rcmail.show_contentframe(!0)),this.gui_objects.attachments&&$("li > a",this.gui_objects.attachments).not(".drop").on("dragstart",(function(e){var t,s=this.href,i=e.originalEvent.dataTransfer;i&&(s=s.replace(/^https?:\/\//,(function(e){return e+urlencode(ref.env.username)+"@"})),(t=$(this).clone()).children().remove(),i.setData("roundcube-uri",s),i.setData("roundcube-name",$.trim(t.text())))}))):"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"],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(e){ref.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(e){return rcube_event.cancel(e)})).on("mouseup keypress",(function(e){if("mouseup"==e.type||13==rcube_event.get_keycode(e))return ref.command("insert-response",$(this).attr("rel")),$(document.body).trigger("mouseup"),rcube_event.cancel(e)})),$.each(this.buttons["save-response"]||[],(function(e,t){$("#"+t.id).mousedown((function(e){return rcube_event.cancel(e)}))}))),this.init_messageform()):"get"==this.env.action?(this.enable_command("download",!0),bw.mz&&"application/pdf"==this.env.mimetype?(n=0,$(this.gui_objects.messagepartframe).on("load",(function(){if(n++)try{this.contentWindow.document&&ref.enable_command("print",!0)}catch(e){}}))):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('<style type="text/css">img { max-width:100%; max-height:100%; } body { display:flex; align-items:center; justify-content:center; height:100%; margin:0; }</style>')}))):"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(e){ref.triggerEvent("insertrow",{cid:e.uid,row:e})})).addEventListener("select",(function(e){ref.compose_recipient_select(e)})).addEventListener("dblclick",(function(e){ref.compose_add_recipient()})).addEventListener("keypress",(function(e){e.key_pressed==e.ENTER_KEY&&(ref.compose_add_recipient()||e.last_selected&&"G"==String(e.last_selected).charAt(0)&&$(e.rows[e.last_selected].obj).find("a").first().click())})).init(),$("#_to,#_cc,#_bcc").focus((function(){ref.env.focused_field=this}))),this.gui_objects.addressbookslist&&(this.gui_objects.folderlist=this.gui_objects.addressbookslist,this.enable_command("list-addresses",!0)),this.env.mdn_request&&this.env.uid){var postact="sendmdn",postdata={_uid:this.env.uid,_mbox:this.env.mailbox};confirm(this.get_label("mdnrequest"))||(postdata._flag="mdnsent",postact="mark"),this.http_post(postact,postdata)}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,keyboard:!0}),this.contact_list.addEventListener("initrow",(function(e){ref.triggerEvent("insertrow",{cid:e.uid,row:e})})).addEventListener("keypress",(function(e){ref.contactlist_keypress(e)})).addEventListener("select",(function(e){ref.contactlist_select(e)})).addEventListener("dragstart",(function(e){ref.drag_start(e)})).addEventListener("dragmove",(function(e){ref.drag_move(e)})).addEventListener("dragend",(function(e){ref.drag_end(e)})).init(),$(this.gui_objects.qsearchbox).focusin((function(){ref.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(e){ref.triggerEvent("selectfolder",{folder:e.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(){ref.group_member_change(this.checked?"add":"del",ref.env.cid,ref.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",this.env.identities_level<2):"edit-identity"==this.env.action||"add-identity"==this.env.action?(this.enable_command("save","edit","toggle-editor",!0),this.enable_command("delete",this.env.identities_level<2),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(e){ref.identity_select(e)})).addEventListener("keypress",(function(e){e.key_pressed==e.ENTER_KEY&&ref.identity_select(e)})).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(e){ref.section_select(e)})).addEventListener("keypress",(function(e){e.key_pressed==e.ENTER_KEY&&ref.section_select(e)})).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(e){var t,s=e.get_single_selection();ref.enable_command("delete",!!s&&$.inArray(s,ref.env.readonly_responses)<0),s&&(t=ref.get_frame_window(ref.env.contentframe))&&(ref.set_busy(!0),ref.location_href({_action:"edit-response",_key:s,_framed:1},t))})).init().focus());break;case"login":var tz,tz_name,jstz=window.jstz,input_user=$("#rcmloginuser"),input_tz=$("#rcmlogintz");input_user.keyup((function(e){return ref.login_user_keyup(e)})),""==input_user.val()?input_user.focus():$("#rcmloginpwd").focus(),jstz&&(tz=jstz.determine())&&(tz_name=tz.name()),input_tz.val(tz_name||(new Date).getStdTimezoneOffset()/-60),$("form").submit((function(){$("input[type=submit]",this).prop("disabled",!0),ref.clear_messages(),ref.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(),bw.ie&&$("input[type=file]").keydown((function(e){"13"==e.keyCode&&e.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(e){return!e.virtual&&ref.check_droptarget(e.id)}}),this.treelist.addEventListener("collapse",(function(e){ref.folder_collapsed(e)})).addEventListener("expand",(function(e){ref.folder_collapsed(e)})).addEventListener("beforeselect",(function(e){return!ref.busy})).addEventListener("select",(function(e){ref.triggerEvent("selectfolder",{folder:e.id,prefix:"rcmli"}),ref.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(e){return ref.document_drag_hover(e,"dragover"==e.type)})),$(this.gui_objects.filedrop).addClass("droptarget").on("dragover dragleave",(function(e){return ref.file_drag_hover(e,"dragover"==e.type)})).get(0).addEventListener("drop",(function(e){return ref.file_dropped(e)}),!1));var body_mouseup=function(e){return ref.doc_mouse_up(e)};for(n in $(document.body).mouseup(body_mouseup).keydown((function(e){return ref.doc_keypress(e)})),rcube_webmail.set_iframe_events({mouseup:body_mouseup}),this.triggerEvent("init",{task:this.task,action:this.env.action}),this.onloads)"string"==typeof this.onloads[n]?eval(this.onloads[n]):"function"==typeof this.onloads[n]&&this.onloads[n]();this.start_refresh(),this.start_keepalive()}else this.goto_url("error","_code=0x199")},this.log=function(e){this.env.devel_mode&&window.console&&console.log&&console.log(e)},this.command=function(e,t,s,i){var n,a,r,o,l,c=!1;if(!s||!s.blur||i&&rcube_event.is_keyboard(i)||s.blur(),this.busy&&("reset-search"!=e||"search"!=this.last_command)&&!e.match(/^menu-/))return!1;if(s&&s.href&&String(s.href).indexOf("#")<0&&rcube_event.get_modifier(i))return!0;if(!this.commands[e])return this.is_framed()&&parent.rcmail.command(e,t),!1;if("mail"==this.task&&"compose"==this.env.action&&!this.env.server_error&&"save-pref"!=e&&$.inArray(e,this.env.compose_commands)<0){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}if(this.last_command=e,"function"==typeof this.command_handlers[e])return void 0!==(n=this.command_handlers[e](t,s,i))?n:!s;if("string"==typeof this.command_handlers[e])return void 0!==(n=window[this.command_handlers[e]](t,s,i))?n:!s;if(this.triggerEvent("actionbefore",{props:t,action:e,originalEvent:i}),void 0!==(n=this.triggerEvent("before"+e,t||i))){if(!1===n)return!1;t=n}switch(n=void 0,e){case"login":this.gui_objects.loginform&&this.gui_objects.loginform.submit();break;case"logout":case"mail":case"addressbook":case"settings":this.switch_task(e);break;case"about":this.redirect("?_task=settings&_action=about",!1);break;case"permaurl":if(s&&s.href&&s.target)return!0;this.env.permaurl&&(parent.location.href=this.env.permaurl);break;case"extwin":if("compose"==this.env.action){var h=this.gui_objects.messageform,d=this.open_window("");d&&(this.save_compose_form_local(),this.compose_skip_unsavedcheck=!0,$("input[name='_action']",h).val("compose"),h.action=this.url("mail/compose",{_id:this.env.compose_id,_extwin:1}),h.target=d.name,h.submit())}else this.open_window(this.env.permaurl,!0);break;case"change-format":o=this.env.permaurl+"&_format="+t,"preview"==this.env.action&&(o=o.replace(/_action=show/,"_action=preview")+"&_framed=1"),this.env.extwin&&(o+="&_extwin=1"),location.href=o;break;case"menu-open":if(t&&"attachmentmenu"==t.menu)(g=this.env.attachments[t.id])&&g.mimetype&&(g=g.mimetype),this.enable_command("open-attachment",g&&this.env.mimetypes&&$.inArray(g,this.env.mimetypes)>=0);this.show_menu(t,t.show||void 0,i);break;case"menu-close":this.hide_menu(t,i);break;case"menu-save":return this.triggerEvent(e,{props:t,originalEvent:i}),!1;case"open":if(a=this.get_single_uid())return s.href=this.url("show",this.params_from_uid(a)),!0;break;case"close":this.env.extwin&&window.close();break;case"list":t&&""!=t&&this.reset_qsearch(!0),"compose"==this.env.action&&this.env.extwin?window.close():"mail"==this.task?(this.list_mailbox(t),this.set_button_titles()):"addressbook"==this.task&&this.list_contacts(t);break;case"set-listmode":this.set_list_options(null,void 0,void 0,"threads"==t?1:0);break;case"sort":var _=this.env.sort_order,u=this.env.disabled_sort_col?this.env.sort_col:t;this.env.disabled_sort_order||(_=this.env.sort_col==u&&"ASC"==_?"DESC":"ASC"),this.set_list_sorting(u,_),this.list_mailbox("","",u+"_"+_);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?!(a=this.get_single_uid())||this.env.uid&&a==this.env.uid||(this.env.mailbox==this.env.drafts_mailbox?this.open_compose_step({_draft_uid:a,_mbox:this.env.mailbox}):this.show_message(a)):"addressbook"==this.task&&(!(r=t||this.get_single_cid())||"show"==this.env.action&&r==this.env.cid||this.load_contact(r,"show"));break;case"add":if("addressbook"==this.task)this.load_contact(0,"add");else if("settings"==this.task&&"responses"==this.env.action){var m;(m=this.get_frame_window(this.env.contentframe))&&(this.set_busy(!0),this.location_href({_action:"add-response",_framed:1},m))}else"settings"==this.task&&(this.identity_list.clear_selection(),this.load_identity(0,"add-identity"));break;case"edit":"addressbook"==this.task&&(r=this.get_single_cid())?this.load_contact(r,"edit"):"settings"==this.task&&t?this.load_identity(t,"edit-identity"):"mail"==this.task&&(a=this.get_single_uid())&&((o={_mbox:this.get_message_mailbox(a)})[this.env.mailbox==this.env.drafts_mailbox&&"new"!=t?"_draft_uid":"_uid"]=a,this.open_compose_step(o));break;case"save":var p;if(h=this.gui_objects.editform){if("search"==this.env.action);else{if((p=$("input[name='_pagesize']",h))&&p.length&&isNaN(parseInt(p.val()))){alert(this.get_label("nopagesizewarning")),p.focus();break}if("reload"==t)h.action+="&_reload=1";else if("settings"==this.task&&this.env.identities_level%2==0&&(p=$("input[name='_email']",h))&&p.length&&!rcube_check_email(p.val())){alert(this.get_label("noemailwarning")),p.focus();break}}parent.rcmail&&parent.rcmail.env.source&&(h.action=this.add_url(h.action,"_orig_source",parent.rcmail.env.source)),h.submit()}break;case"delete":"mail"==this.task?this.delete_messages(i):"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(t,i):"addressbook"==this.task&&this.move_contacts(t);break;case"copy":"mail"==this.task?this.copy_messages(t,i):"addressbook"==this.task&&this.copy_contacts(t);break;case"mark":t&&this.mark_message(t);break;case"toggle_status":case"toggle_flag":l="toggle_flag"==e?"flagged":"read",(a=t)&&("flagged"==l?this.message_list.rows[a].flagged&&(l="unflagged"):this.message_list.rows[a].deleted?l="undelete":this.message_list.rows[a].unread||(l="unread"),this.mark_message(l,a));break;case"always-load":if(this.env.uid&&this.env.sender){this.add_contact(this.env.sender),setTimeout((function(){ref.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":var f,g=this.env.attachments[t];if("compose"==this.env.action?(f={_file:t,_id:this.env.compose_id},g=g?g.mimetype:""):f={_mbox:this.env.mailbox,_uid:this.env.uid,_part:t},"download-attachment"!=e&&g&&this.env.mimetypes&&$.inArray(g,this.env.mimetypes)>=0&&this.open_window(this.url("get",$.extend({_frame:1},f))))break;f._download=1,this.compose_skip_unsavedcheck=1,this.goto_url("get",f,!1,!0),this.compose_skip_unsavedcheck=0;break;case"select-all":this.select_all_mode=!t,this.dummy_select=!0,"invert"==t?this.message_list.invert_selection():this.message_list.select_all("page"==t?"":t),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":if(o={},"mail"==this.task)o={_mbox:this.env.mailbox,_search:this.env.search_request},t&&(o._to=t);else if("addressbook"==this.task){if(!(t&&t.indexOf("@")>0)){var v=[];t?v.push(t):this.contact_list&&(v=this.contact_list.get_selection()),v.length?this.http_post("mailto",{_cid:v.join(","),_source:this.env.source},!0):this.env.group&&this.http_post("mailto",{_gid:this.env.group,_source:this.env.source},!0);break}o._to=t}else t&&"string"==typeof t?o._to=t:t&&"object"==typeof t&&$.extend(o,t);this.open_compose_step(o);break;case"spellcheck":this.spellcheck_state()?this.editor.spellcheck_stop():this.editor.spellcheck_start();break;case"savedraft":if(clearTimeout(this.save_timer),this.env.draft_id&&this.cmp_hash==this.compose_field_hash()){this.auto_save_start();break}this.submit_messageform(!0);break;case"send":if(!t.nocheck&&!this.env.is_sent&&!this.check_compose_input(e))break;clearTimeout(this.save_timer),this.submit_messageform();break;case"send-attachment":clearTimeout(this.save_timer),(l=this.upload_file(t||this.gui_objects.uploadform,"upload"))||(!1!==l&&alert(this.get_label("selectimportfile")),c=!0);break;case"insert-sig":this.change_identity($("[name='_from']")[0],!0);break;case"list-addresses":this.list_contacts(t),this.enable_command("add-recipient",!1);break;case"add-recipient":this.compose_add_recipient(t);break;case"reply-all":case"reply-list":case"reply":(a=this.get_single_uid())&&(o={_reply_uid:a,_mbox:this.get_message_mailbox(a),_search:this.env.search_request},"reply-all"==e?o._all=!t&&1==this.env.reply_all_mode&&this.commands["reply-list"]?"list":"all":"reply-list"==e&&(o._all="list"),this.open_compose_step(o));break;case"forward-attachment":case"forward-inline":case"forward":var b=this.env.uid?[this.env.uid]:this.message_list?this.message_list.get_selection():[];b.length&&(o={_forward_uid:this.uids_to_list(b),_mbox:this.env.mailbox,_search:this.env.search_request},("forward-attachment"==e||!t&&this.env.forward_attachment||b.length>1)&&(o._attachment=1),this.open_compose_step(o));break;case"print":"addressbook"==this.task?(a=this.contact_list.get_single_selection())&&(o="&_action=print&_cid="+a,this.env.source&&(o+="&_source="+urlencode(this.env.source)),this.open_window(this.env.comm_path+o,!0,!0)):"get"!=this.env.action||this.env.is_message?(a=this.get_single_uid())&&(o=this.url("print",this.params_from_uid(a,{_safe:this.env.safemode?1:0})),this.open_window(o,!0,!0)&&"show"!=this.env.action&&"get"!=this.env.action&&this.mark_message("read",a)):this.gui_objects.messagepartframe.contentWindow.print();break;case"viewsource":(a=this.get_single_uid())&&this.open_window(this.url("viewsource",this.params_from_uid(a)),!0,!0);break;case"download":"get"==this.env.action?location.href=this.secure_url(location.href.replace(/_frame=/,"_download=")):(a=this.get_single_uid())&&this.goto_url("viewsource",this.params_from_uid(a,{_save:1}),!1,!0);break;case"search":n=this.qsearch(t);break;case"reset-search":var w,y=this.env.search_request||this.env.qsearch;if(this.reset_qsearch(!0),y&&"compose"==this.env.action)this.contact_list&&this.list_contacts_clear();else if(y&&this.env.mailbox)this.list_mailbox(this.env.mailbox,1);else if(y&&"addressbook"==this.task){if(""==this.env.source){for(w in this.env.address_sources)break;this.env.source=w,this.env.group=""}this.list_contacts(this.env.source,this.env.group,1)}break;case"pushgroup":var k={id:t.id,search_request:this.env.search_request,page:this.env.current_page,search:this.env.search_request&&this.gui_objects.qsearchbox?this.gui_objects.qsearchbox.value:null};this.env.address_group_stack.push(k),s&&i&&rcube_event.cancel(i);case"listgroup":this.reset_qsearch(),this.list_contacts(t.source,t.id,1,k);break;case"popgroup":if(this.env.address_group_stack.length){var x=this.env.address_group_stack.pop();this.reset_qsearch(),x.search_request?(x.search&&this.gui_objects.qsearchbox&&$(this.gui_objects.qsearchbox).val(x.search),this.env.search_request=x.search_request,this.list_contacts_remote(null,null,this.env.current_page=x.page)):this.list_contacts(t.source,this.env.address_group_stack[this.env.address_group_stack.length-1].id)}break;case"import-messages":h=t||this.gui_objects.importform;var j=this.set_busy(!0,"importwait");$('input[name="_unlock"]',h).val(j),(l=this.upload_file(h,"import",j))||(this.set_busy(!1,null,j),!1!==l&&alert(this.get_label("selectimportfile")),c=!0);break;case"import":if("import"==this.env.action&&this.gui_objects.importform){var E=document.getElementById("rcmimportfile");if(E&&!E.value){alert(this.get_label("selectimportfile")),c=!0;break}this.gui_objects.importform.submit(),this.set_busy(!0,"importwait"),this.lock_form(this.gui_objects.importform,!0)}else this.goto_url("import",this.env.source?"_target="+urlencode(this.env.source)+"&":"");break;case"export":this.contact_list.rowcount>0&&this.goto_url("export",{_source:this.env.source,_gid:this.env.group,_search:this.env.search_request},!1,!0);break;case"export-selected":this.contact_list.rowcount>0&&this.goto_url("export",{_source:this.env.source,_gid:this.env.group,_cid:this.contact_list.get_selection().join(",")},!1,!0);break;case"upload-photo":this.upload_contact_photo(t||this.gui_objects.uploadform);break;case"delete-photo":this.replace_contact_photo("-del-");break;case"preferences":case"identities":case"responses":case"folders":this.goto_url("settings/"+e);break;case"undo":this.http_request("undo","",this.display_message("","loading"));break;default:var q=e.replace(/-/g,"_");this[q]&&"function"==typeof this[q]&&(n=this[q](t,s,i))}return c||!1!==this.triggerEvent("after"+e,t)||(n=!1),this.triggerEvent("actionafter",{props:t,action:e,aborted:c,ret:n}),!1!==n&&!s},this.enable_command=function(){var e,t,s,i=Array.prototype.slice.call(arguments),n=i.pop();for(t=0;t<i.length;t++)if("string"==typeof(s=i[t]))this.commands[s]=n,this.set_button(s,n?"act":"pas"),this.triggerEvent("enable-command",{command:s,status:n});else for(e in s)i.push(s[e])},this.command_enabled=function(e){return this.commands[e]},this.set_busy=function(e,t,s){if(e&&t){var i=this.get_label(t);i==t&&(i="Loading..."),s=this.display_message(i,"loading")}else!e&&s&&this.hide_message(s);return this.busy=e,this.gui_objects.editform&&this.lock_form(this.gui_objects.editform,e),s},this.get_label=function(e,t){return t&&this.labels[t+"."+e]?this.labels[t+"."+e]:this.labels[e]?this.labels[e]:e},this.gettext=this.get_label,this.switch_task=function(e){if(this.task!==e||"mail"==e){var t=this.get_task_url(e);"mail"==e?t+="&_mbox=INBOX":"logout"!=e||this.env.server_error||(t=this.secure_url(t),this.clear_compose_data()),this.redirect(t)}},this.get_task_url=function(e,t){return t||(t=this.env.comm_path),t.match(/[?&]_task=[a-zA-Z0-9_-]+/)?t.replace(/_task=[a-zA-Z0-9_-]+/,"_task="+e):t.replace(/\?.*$/,"")+"?_task="+e},this.reload=function(e){this.is_framed()?parent.rcmail.reload(e):e?setTimeout((function(){ref.reload()}),e):window.location&&(location.href=this.url("",{_extwin:this.env.extwin}))},this.add_url=function(e,t,s){if(s=urlencode(s),/(\?.*)$/.test(e)){var i=RegExp.$1,n=RegExp("((\\?|&)"+RegExp.escape(t)+"=[^&]*)");return n.test(i)?i=i.replace(n,RegExp.$2+t+"="+s):i+="&"+t+"="+s,e.replace(/(\?.*)$/,i)}return e+"?"+t+"="+s},this.secure_url=function(e){return this.add_url(e,"_token",this.env.request_token)},this.is_framed=function(){return this.env.framed&&parent.rcmail&&parent.rcmail!=this&&"function"==typeof parent.rcmail.command},this.save_pref=function(e){var t={_name:e.name,_value:e.value};e.session&&(t._session=e.session),e.env&&(this.env[e.env]=e.value),this.http_post("save-pref",t)},this.html_identifier=function(e,t){return t?this.html_identifier_encode(e):String(e).replace(this.identifier_expr,"_")},this.html_identifier_encode=function(e){return Base64.encode(String(e)).replace(/=+$/,"").replace(/\+/g,"-").replace(/\//g,"_")},this.html_identifier_decode=function(e){for(e=String(e).replace(/-/g,"+").replace(/_/g,"/");e.length%4;)e+="=";return Base64.decode(e)},this.drag_menu=function(e,t){var s=rcube_event.get_modifier(e),i=this.gui_objects.dragmenu;if(i&&s==SHIFT_KEY&&this.commands.copy){var n=rcube_event.get_mouse_pos(e);return this.env.drag_target=t,this.show_menu(this.gui_objects.dragmenu.id,!0,e),$(i).css({top:n.y-10+"px",left:n.x-10+"px"}),!0}return!1},this.drag_menu_action=function(e){var t=this.gui_objects.dragmenu;t&&$(t).hide(),this.command(e,this.env.drag_target),this.env.drag_target=null},this.drag_start=function(e){this.drag_active=!0,this.preview_timer&&clearTimeout(this.preview_timer),this.treelist&&this.treelist.drag_start()},this.drag_end=function(e){var t,s;if(this.treelist&&this.treelist.drag_end(),(t=this.message_list)?s=this.env.mailboxes:(t=this.contact_list)&&(s=this.env.contactfolders),this.drag_active&&s&&this.env.last_folder_target&&!rcube_event.is_keyboard(e)){var i=s[this.env.last_folder_target];t.draglayer.hide(),this.contact_list?this.contacts_drag_menu(e,i)||this.command("move",i):this.drag_menu(e,i)||this.command("move",i)}this.drag_active=!1,this.env.last_folder_target=null},this.drag_move=function(e){if(this.gui_objects.folderlist){var t,s,i="draglayernormal",n=rcube_event.get_mouse_pos(e);this.contact_list&&this.contact_list.draglayer&&(s=this.contact_list.draglayer.attr("class")),this.treelist&&(t=this.treelist.intersects(n,!0))?(this.env.last_folder_target=t,i="draglayer"+(this.check_droptarget(t)>1?"copy":"normal")):this.env.last_folder_target=null,i!=s&&this.contact_list&&this.contact_list.draglayer&&this.contact_list.draglayer.attr("class",i)}},this.collapse_folder=function(e){this.treelist&&this.treelist.toggle(e)},this.folder_collapsed=function(e){var t="addressbook"==this.env.task?"collapsed_abooks":"collapsed_folders",s=this.env[t];if(e.collapsed)this.env[t]=this.env[t]+"&"+urlencode(e.id)+"&",!e.virtual&&this.env.mailbox&&this.env.mailbox.startsWith(e.id+this.env.delimiter)&&this.command("list",e.id);else{var i=new RegExp("&"+urlencode(e.id)+"&");this.env[t]=this.env[t].replace(i,"")}this.drag_active||(s!==this.env[t]&&this.command("save-pref",{name:t,value:this.env[t]}),this.env.unread_counts&&this.set_unread_count_display(e.id,!1))},this.doc_mouse_up=function(e){var t,s=rcube_event.get_target(e);if(!$(s).closest(".ui-dialog, .ui-widget-overlay").length){if(window.rcube_list_widget&&rcube_list_widget._instances.length&&$.each(rcube_list_widget._instances,(function(t,s){s&&!rcube_mouse_is_over(e,s.list.parentNode)&&s.blur()})),this.buttons_sel){for(t in this.buttons_sel)"function"!=typeof t&&this.button_out(this.buttons_sel[t],t);this.buttons_sel={}}setTimeout((function(e){var t,i,n,a,r=$(s).parents();for(a=ref.menu_stack.length-1;a>=0;a--)n=ref.menu_stack[a],!(t=$("#"+n)).is(":visible")||s==t.data("opener")||s==t.get(0)||r.is(t.data("opener"))||n==i||"true"==t.attr("data-editable")&&$(s).parents("#"+n).length||"true"==t.attr("data-sticky")&&rcube_mouse_is_over(e,t.get(0))||ref.hide_menu(n,e),i=t.data("parent")}),10,e)}},this.doc_keypress=function(e){var t=function(e){var t,s,i=e<0?"prevAll":"nextAll",n=e<0?"last":"first";return ref.focused_menu&&(t=$("#"+ref.focused_menu))?((s=t.find(":focus").closest("li")[i](":has(:not([aria-disabled=true]))").find("a,input")[n]()).length||(s=t.find(":focus").closest("ul")[i](":has(:not([aria-disabled=true]))").find("a,input")[n]()),s.focus().length):0},s=e.target||{},i=rcube_event.get_keycode(e);if(27!=e.keyCode&&(!this.menu_keyboard_active||"TEXTAREA"==s.nodeName||"SELECT"==s.nodeName))return!0;switch(i){case 38:case 40:case 63232:case 63233:return t(38==i||63232==i?-1:1),rcube_event.cancel(e);case 9:if(this.focused_menu)t(rcube_event.get_modifier(e)==SHIFT_KEY?-1:1)||this.hide_menu(this.focused_menu,e);return rcube_event.cancel(e);case 27:this.menu_stack.length&&this.hide_menu(this.menu_stack[this.menu_stack.length-1],e)}return!0},this.msglist_select=function(e){this.preview_timer&&clearTimeout(this.preview_timer);var t=e.get_single_selection();(this.enable_command(this.env.message_commands,null!=t),t)&&(this.env.mailbox==this.env.drafts_mailbox?this.enable_command("reply","reply-all","reply-list","forward","forward-attachment","forward-inline",!1):this.env.messages[t].ml||this.enable_command("reply-list",!1));if(this.enable_command("delete","move","copy","mark","forward","forward-attachment",e.selection.length>0),(t||e.selection.length&&e.selection.length!=e.rowcount)&&(this.select_all_mode=!1),t&&this.env.contentframe&&!e.multi_selecting&&!this.dummy_select){var s=(new Date).getTime(),i=s-(this._last_msglist_select_time||0),n=this.preview_delay_click;i<this.preview_delay_select&&(n=this.preview_delay_select,this.preview_timer&&clearTimeout(this.preview_timer),this.env.contentframe&&this.show_contentframe(!1)),this._last_msglist_select_time=s,this.preview_timer=setTimeout((function(){ref.msglist_get_preview()}),n)}else this.env.contentframe&&this.show_contentframe(!1)},this.msglist_dbl_click=function(e){this.preview_timer&&clearTimeout(this.preview_timer);var t=e.get_single_selection();t&&(this.env.messages[t].mbox||this.env.mailbox)==this.env.drafts_mailbox?this.open_compose_step({_draft_uid:t,_mbox:this.env.mailbox}):t&&this.show_message(t,!1,!1)},this.msglist_keypress=function(e){e.modkey!=CONTROL_KEY&&(e.key_pressed==e.ENTER_KEY?this.command("show"):e.key_pressed==e.DELETE_KEY||e.key_pressed==e.BACKSPACE_KEY?this.command("delete"):33==e.key_pressed?this.command("previouspage"):34==e.key_pressed&&this.command("nextpage"))},this.msglist_get_preview=function(){var e=this.get_single_uid();e&&this.env.contentframe&&!this.drag_active?this.show_message(e,!1,!0):this.env.contentframe&&this.show_contentframe(!1)},this.msglist_expand=function(e){this.env.messages[e.uid]&&(this.env.messages[e.uid].expanded=e.expanded),$(e.obj)[e.expanded?"addClass":"removeClass"]("expanded")},this.msglist_set_coltypes=function(e){var t,s,i,n=e.thead.rows[0].cells;for(this.env.listcols=[],t=0;t<n.length;t++)n[t].id&&n[t].id.startsWith("rcm")&&(i=n[t].id.slice(3),this.env.listcols.push(i));(s=$.inArray("flag",this.env.listcols))>=0&&(this.env.flagged_col=s),(s=$.inArray("subject",this.env.listcols))>=0&&(this.env.subject_col=s),this.command("save-pref",{name:"list_cols",value:this.env.listcols,session:"list_attrib/columns"})},this.check_droptarget=function(e){switch(this.task){case"mail":return!this.env.mailboxes[e]||this.env.mailboxes[e].virtual||this.env.mailboxes[e].id==this.env.mailbox&&!this.is_multifolder_listing()?0:1;case"addressbook":var t;if(e!=this.env.source&&(t=this.env.contactfolders[e]))if("group"==t.type){if(t.id!=this.env.group&&!this.env.contactfolders[t.source].readonly)return!(this.env.selection_sources.length>1||-1==$.inArray(t.source,this.env.selection_sources))||this.commands.move?1:2}else if(!t.readonly&&(this.env.selection_sources.length>1||-1==$.inArray(e,this.env.selection_sources)))return this.commands.move?1:2}return 0},this.open_window=function(e,t,s){var i="rcmextwin"+(new Date).getTime();if(e+=(e.match(/\?/)?"&":"?")+"_extwin=1",this.env.standard_windows)var n=window.open(e,i);else{var a=this.is_framed()?parent.window:window,r=$(a),o=r.width(),l=bw.mz?$("body",a).height():r.height(),c=Math.min(t?this.env.popup_width_small:this.env.popup_width,o),h=l,d=(a.screenLeft||a.screenX)+20,_=(a.screenTop||a.screenY)+20;n=window.open(e,i,"width="+c+",height="+h+",top="+_+",left="+d+",resizable=yes,location=no,scrollbars=yes"+(s?",toolbar=yes,menubar=yes,status=yes":",toolbar=no,menubar=no,status=no"))}if(n&&!n.closed)return!e&&n.document&&n.document.write("<html><body>"+this.get_label("loading")+"</body></html>"),this.triggerEvent("openwindow",{url:e,handle:n}),setTimeout((function(){n&&n.focus()}),10),n;this.display_message(this.get_label("windowopenerror"),"warning")},this.init_message_row=function(e){var t={},s=e.uid,i=(null!=this.env.status_col?"status":"msg")+"icn"+e.id;s&&this.env.messages[s]&&$.extend(e,this.env.messages[s]),(e.icon=document.getElementById(i))&&(t.icon=function(e){ref.command("toggle_status",s)}),null!=this.env.status_col?e.msgicon=document.getElementById("msgicn"+e.id):e.msgicon=e.icon,null!=this.env.flagged_col&&(e.flagicon=document.getElementById("flagicn"+e.id))&&(t.flagicon=function(e){ref.command("toggle_flag",s)}),!e.depth&&e.has_children&&(e.expando=document.getElementById("rcmexpando"+e.id))&&(t.expando=function(e){ref.expand_message_row(e,s)}),$.each(t,(function(t,s){e[t].onclick=function(e){return s(e),rcube_event.cancel(e)},bw.touch&&e[t].addEventListener&&e[t].addEventListener("touchend",(function(e){if(1==e.changedTouches.length)return s(e),rcube_event.cancel(e)}),!1)})),this.triggerEvent("insertrow",{uid:s,row:e})},this.add_message_row=function(e,t,s,i){if(!this.gui_objects.messagelist||!this.message_list)return!1;if(s.mbox!=this.env.mailbox&&!s.skip_mbox_check)return!1;if(this.message_list.rows[e])return!1;this.env.messages[e]||(this.env.messages[e]={}),$.extend(this.env.messages[e],{deleted:s.deleted?1:0,replied:s.answered?1:0,unread:s.seen?0:1,forwarded:s.forwarded?1:0,flagged:s.flagged?1:0,has_children:s.has_children?1:0,depth:s.depth?s.depth:0,unread_children:s.unread_children||0,flagged_children:s.flagged_children||0,parent_uid:s.parent_uid||0,selected:this.select_all_mode||this.message_list.in_selection(e),ml:s.ml?1:0,ctype:s.ctype,mbox:s.mbox,flags:s.extra_flags});var n,a,r,o,l,c,h="",d="",_="",u="",m=this.message_list,p=m.rows,f=this.env.messages[e],g=this.html_identifier(e,!0),v="message"+(s.seen?"":" unread")+(s.deleted?" deleted":"")+(s.flagged?" flagged":"")+(f.selected?" selected":""),b={cols:[],style:{},id:"rcmrow"+g,uid:e};if(l="msgicon",null===this.env.status_col&&(l+=" status",s.deleted?(h+=" deleted",d+=this.get_label("deleted")+" "):s.seen?s.unread_children>0&&(h+=" unreadchildren"):(h+=" unread",d+=this.get_label("unread")+" ")),s.answered&&(h+=" replied",d+=this.get_label("replied")+" "),s.forwarded&&(h+=" forwarded",d+=this.get_label("forwarded")+" "),f.selected&&!m.in_selection(e)&&m.selection.push(e),this.env.threading&&(f.depth?(_+='<span id="rcmtab'+g+'" class="branch" style="width:'+15*f.depth+'px;">&nbsp;&nbsp;</span>',p[f.parent_uid]&&!1===p[f.parent_uid].expanded||!(0!=this.env.autoexpand_threads&&2!=this.env.autoexpand_threads||p[f.parent_uid]&&p[f.parent_uid].expanded)?(b.style.display="none",f.expanded=!1):f.expanded=!0,v+=" thread expanded"):f.has_children&&(void 0===f.expanded&&(1==this.env.autoexpand_threads||2==this.env.autoexpand_threads&&f.unread_children)&&(f.expanded=!0),u='<div id="rcmexpando'+b.id+'" class="'+(f.expanded?"expanded":"collapsed")+'">&nbsp;&nbsp;</div>',v+=" thread"+(f.expanded?" expanded":"")),s.unread_children&&s.seen&&!f.expanded&&(v+=" unroot"),s.flagged_children&&!f.expanded&&(v+=" flaggedroot")),_+='<span id="msgicn'+b.id+'" class="'+l+h+'" title="'+d+'"></span>',b.className=v,t.subject){var w=s.mbox==this.env.drafts_mailbox?"compose":"show",y=s.mbox==this.env.drafts_mailbox?"_draft_uid":"_uid",k={_mbox:s.mbox};k[y]=e,t.subject='<a href="'+this.url(w,k)+'" onclick="return rcube_event.keyboard_only(event)" onmouseover="rcube_webmail.long_subject_title(this,'+(f.depth+1)+')" tabindex="-1"><span>'+t.subject+"</span></a>"}for(a in this.env.listcols)n=this.env.listcols[a],r={className:String(n).toLowerCase(),events:{}},this.env.coltypes[n]&&this.env.coltypes[n].hidden&&(r.className+=" hidden"),"flag"==n?(l=s.flagged?"flagged":"unflagged",c=this.get_label(l),o='<span id="flagicn'+b.id+'" class="'+l+'" title="'+c+'"></span>'):"attachment"==n?(c=this.get_label("withattachment"),o=s.attachmentClass?'<span class="'+s.attachmentClass+'" title="'+c+'"></span>':/application\/|multipart\/(m|signed)/.test(s.ctype)?'<span class="attachment" title="'+c+'"></span>':/multipart\/report/.test(s.ctype)?'<span class="report"></span>':"multipart/encrypted"==s.ctype||"application/pkcs7-mime"==s.ctype?'<span class="encrypted"></span>':"&nbsp;"):"status"==n?(c="",s.deleted?(l="deleted",c=this.get_label("deleted")):s.seen?l=s.unread_children>0?"unreadchildren":"msgicon":(l="unread",c=this.get_label("unread")),o='<span id="statusicn'+b.id+'" class="'+l+h+'" title="'+c+'"></span>'):"threads"==n?o=u:"subject"==n?o=_+t[n]:"priority"==n?s.prio>0&&s.prio<6?(c=this.get_label("priority")+" "+s.prio,o='<span class="prio'+s.prio+'" title="'+c+'"></span>'):o="&nbsp;":o="folder"==n?'<span onmouseover="rcube_webmail.long_subject_title(this)">'+t[n]+"<span>":t[n],r.innerHTML=o,b.cols.push(r);if("widescreen"==this.env.layout&&(b=this.widescreen_message_row(b,e,f)),m.insert_row(b,i),i&&this.env.pagesize&&m.rowcount>this.env.pagesize){e=m.get_last_row();m.remove_row(e),m.clear_selection(e)}},this.widescreen_message_row=function(e,t,s){var i=document.createElement("tr");return i.id=e.id,i.uid=e.uid,i.className=e.className,e.style&&$.extend(i.style,e.style),$.each(this.env.widescreen_list_template,(function(){if(ref.env.threading||"threads"!=this.className){var t,s,n,a,r=document.createElement("td");for(this.className&&(r.className=this.className),t=0;this.cells&&t<this.cells.length;t++)for(s=0;e.cols&&s<e.cols.length;s++)if(this.cells[t]==e.cols[s].className){n=e.cols[s],(a=document.createElement("span")).className=this.cells[t],"subject"==this.className&&"subject"!=a.className&&(a.className+=" skip-on-drag"),n.innerHTML&&(a.innerHTML=n.innerHTML),r.appendChild(a);break}i.appendChild(r)}})),this.env.threading&&s.depth&&($("td.subject",i).attr("style","padding-left:"+Math.min(90,15*s.depth)+"px !important"),$("span.branch",i).remove()),i},this.set_list_sorting=function(e,t){var s="arrival"==this.env.sort_col?"date":this.env.sort_col,i="arrival"==e?"date":e;$("#rcm"+s).removeClass("sorted"+this.env.sort_order.toUpperCase()),i&&$("#rcm"+i).addClass("sorted"+t),$("#rcmdate > a").prop("rel","arrival"==e?"arrival":"date"),this.env.sort_col=e,this.env.sort_order=t},this.set_list_options=function(e,t,s,i,n){var a,r={};if(void 0===t&&(t=this.env.sort_col),s||(s=this.env.sort_order),this.env.sort_col==t&&this.env.sort_order==s||(a=1,this.set_list_sorting(t,s)),this.env.threading!=i&&(a=1,r._threads=i),n&&this.env.layout!=n&&(this.triggerEvent("layout-change",{old_layout:this.env.layout,new_layout:n}),a=1,this.env.layout=r._layout=n),e&&e.length){var o,l,c,h=[],d=this.env.listcols;for(o=0;o<d.length;o++)c=d[o],-1!=(l=$.inArray(c,e))&&(h.push(c),delete e[l]);for(o=0;o<e.length;o++)e[o]&&h.push(e[o]);h.join()!=d.join()&&(a=1,r._cols=h.join(","))}a&&this.list_mailbox("","",t+"_"+s,r)},this.show_message=function(e,t,s){if(e){var i,n=window,a=this.params_from_uid(e,{_caps:this.browser_capabilities()});s&&(i=this.get_frame_window(this.env.contentframe))&&(n=i,a._framed=1),t&&(a._safe=1),this.env.search_request&&(a._search=this.env.search_request),this.env.extwin&&(a._extwin=1),a=this.url(s?"preview":"show",a),s&&String(n.location.href).indexOf(a)>=0?this.show_contentframe(!0):s||!this.env.message_extwin||this.env.extwin?this.location_href(a,n,!0):this.open_window(a,!0)}},this.set_unread_message=function(e,t){var s=this;s.message_list||(s=s.opener()),!s&&window.parent&&(s=parent.rcmail),s&&s.message_list&&(!1===s.set_message(e,"unread",!1)&&s.set_message(e+"-"+t,"unread",!1),s.env.unread_counts[t]>0&&(s.env.unread_counts[t]-=1,s.set_unread_count(t,s.env.unread_counts[t],"INBOX"==t&&!s.is_multifolder_listing())))},this.show_contentframe=function(e){var t,s,i=this.env.contentframe;(t=this.get_frame_element(i))&&(!e&&(s=this.get_frame_window(i))?s.location.href.indexOf(this.env.blankpage)<0&&(s.stop?s.stop():s.document.execCommand("Stop"),s.location.href=this.env.blankpage):bw.safari||bw.konq||$(t)[e?"show":"hide"]()),!e&&this.env.frame_lock&&this.set_busy(!1,null,this.env.frame_lock)},this.get_frame_element=function(e){var t;if(e&&(t=document.getElementById(e)))return t},this.get_frame_window=function(e){var t=this.get_frame_element(e);if(t&&t.name&&window.frames)return window.frames[t.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(e){"next"==e?e=this.env.current_page+1:"last"==e?e=this.env.pagecount:"prev"==e&&this.env.current_page>1?e=this.env.current_page-1:"first"==e&&this.env.current_page>1&&(e=1),e>0&&e<=this.env.pagecount&&(this.env.current_page=e,"addressbook"==this.task||this.contact_list?this.list_contacts(this.env.source,this.env.group,e):"mail"==this.task&&this.list_mailbox(this.env.mailbox,e))},this.checkmail=function(){var e=this.set_busy(!0,"checkingmail"),t=this.check_recent_params();this.http_post("check-recent",t,e)},this.filter_mailbox=function(e){if(!this.filter_disabled){var t=this.set_busy(!0,"searching");this.clear_message_list(),this.env.current_page=1,this.env.search_filter=e,this.http_request("search",this.search_params(!1,e),t)}},this.refresh_list=function(){this.list_mailbox(this.env.mailbox,this.env.current_page||1,null,{_clear:1},!0),this.message_list&&this.message_list.clear_selection()},this.list_mailbox=function(e,t,s,i,n){var a,r=window;"object"!=typeof i&&(i={}),e||(e=this.env.mailbox?this.env.mailbox:"INBOX"),s&&(i._sort=s),this.env.mailbox!=e?(t=1,this.env.current_page=t,this.env.search_scope="base",this.select_all_mode=!1,this.reset_search_filter()):this.env.search_request&&(i._search=this.env.search_request),n||(this.clear_message_list(),e==this.env.mailbox&&(e!=this.env.mailbox||t||s)||(i._refresh=1),this.select_folder(e,"",!0),this.unmark_folder(e,"recent","",!0),this.env.mailbox=e),this.gui_objects.messagelist?this.list_mailbox_remote(e,t,i):((a=this.get_frame_window(this.env.contentframe))&&(r=a,i._framed=1),this.env.uid&&(i._uid=this.env.uid),e&&(this.set_busy(!0,"loading"),i._mbox=e,t&&(i._page=t),this.location_href(i,r)))},this.clear_message_list=function(){this.env.messages={},this.show_contentframe(!1),this.message_list&&this.message_list.clear(!0)},this.list_mailbox_remote=function(e,t,s){var i=this.set_busy(!0,"loading");"object"!=typeof s&&(s={}),s._mbox=e,t&&(s._page=t),this.http_request("list",s,i),this.update_state({_mbox:e,_page:t&&t>1?t:null})},this.update_selection=function(){var e,t=this.message_list,s=t.selection,i=t.rows,n=[];for(e in s)i[s[e]]&&n.push(s[e]);t.selection=n;try{var a=this.get_frame_window(this.env.contentframe).rcmail.env.uid;a&&!t.in_selection(a)&&this.show_contentframe(!1)}catch(e){}},this.expand_unread=function(){for(var e,t=this.message_list.tbody.firstChild;t;)1==t.nodeType&&(e=this.message_list.rows[t.uid])&&e.unread_children&&(this.message_list.expand_all(e),this.set_unread_children(e.uid)),t=t.nextSibling;return!1},this.expand_message_row=function(e,t){var s=this.message_list.rows[t];s.expanded=!s.expanded,this.set_unread_children(t),this.set_flagged_children(t),s.expanded=!s.expanded,this.message_list.expand_row(e,t)},this.expand_threads=function(){if(this.env.threading&&this.env.autoexpand_threads&&this.message_list)switch(this.env.autoexpand_threads){case 2:this.expand_unread();break;case 1:this.message_list.expand_all()}},this.init_threads=function(e,t){if(t&&t!=this.env.mailbox)return!1;for(var s=0,i=e.length;s<i;s++)this.add_tree_icons(e[s]);this.expand_threads()},this.add_tree_icons=function(e){var t,s,i,n,a,r=[],o=[],l=this.message_list.rows;for(a=e?l[e]?l[e].obj:null:this.message_list.tbody.firstChild;a;){if(1==a.nodeType&&(s=l[a.uid]))if(s.depth){for(t=r.length-1;t>=0&&((i=r[t].length)>s.depth?(n=i-s.depth,2&r[t][n]||(r[t][n]=r[t][n]?r[t][n]+2:2)):i==s.depth&&(2&r[t][0]||(r[t][0]+=2)),!(s.depth>i));t--);r.push(new Array(s.depth)),r[r.length-1][0]=1,o.push(s.uid)}else{if(r.length){for(t in r)this.set_tree_icons(o[t],r[t]);r=[],o=[]}if(e&&a!=l[e].obj)break}a=a.nextSibling}if(r.length)for(t in r)this.set_tree_icons(o[t],r[t])},this.set_tree_icons=function(e,t){var s,i=[],n="",a=t.length;for(s=0;s<a;s++)t[s]>2?i.push({class:"l3",width:15}):t[s]>1?i.push({class:"l2",width:15}):t[s]>0?i.push({class:"l1",width:15}):i.length&&!i[i.length-1].class?i[i.length-1].width+=15:i.push({class:null,width:15});for(s=i.length-1;s>=0;s--)i[s].class?n+='<div class="tree '+i[s].class+'" />':n+='<div style="width:'+i[s].width+'px" />';n&&$("#rcmtab"+this.html_identifier(e,!0)).html(n)},this.update_thread_root=function(e,t){if(this.env.threading){var s=this.message_list.find_root(e);if(e!=s){var i=this.message_list.rows[s];if("read"==t&&i.unread_children)i.unread_children--;else if("unread"==t&&i.has_children)i.unread_children=(i.unread_children||0)+1;else if("unflagged"==t&&i.flagged_children)i.flagged_children--;else{if("flagged"!=t||!i.has_children)return;i.flagged_children=(i.flagged_children||0)+1}this.set_message_icon(s),this.set_unread_children(s),this.set_flagged_children(s)}}},this.update_thread=function(e){if(!this.env.threading||!this.message_list.rows[e])return 0;var t,s,i=0,n=this.message_list,a=n.rows,r=a[e],o=a[e].depth,l=[];for(r.depth||i--,r.depth&&r.unread&&(a[s=n.find_root(e)].unread_children--,this.set_unread_children(s)),r.depth&&r.flagged&&(a[s=n.find_root(e)].flagged_children--,this.set_flagged_children(s)),s=r.parent_uid,r=r.obj.nextSibling;r;){if(1==r.nodeType&&(t=a[r.uid])){if(!t.depth||t.depth<=o)break;t.depth--,$("#rcmtab"+t.id).width(15*t.depth).html(""),t.depth?(t.depth==o&&(t.parent_uid=s),t.unread&&l.length&&l[l.length-1].unread_children++):(i++,t.parent_uid=0,t.has_children&&($("#"+t.id+" .leaf:first").attr("id","rcmexpando"+t.id).attr("class","none"!=t.obj.style.display?"expanded":"collapsed").mousedown({uid:t.uid},(function(e){return ref.expand_message_row(e,e.data.uid)})),t.unread_children=0,l.push(t)),"none"==t.obj.style.display&&$(t.obj).show())}r=r.nextSibling}for(t=0;t<l.length;t++)this.set_unread_children(l[t].uid),this.set_flagged_children(l[t].uid);return i},this.delete_excessive_thread_rows=function(){for(var e=this.message_list.rows,t=this.message_list.tbody.firstChild,s=this.env.pagesize+1;t;)1==t.nodeType&&(r=e[t.uid])&&(!r.depth&&s&&s--,s||this.message_list.remove_row(t.uid)),t=t.nextSibling},this.set_message_icon=function(e){var t,s="",i=this.message_list.rows[e];if(!i)return!1;i.icon&&(t="msgicon",i.deleted?(t+=" deleted",s+=this.get_label("deleted")+" "):i.unread?(t+=" unread",s+=this.get_label("unread")+" "):i.unread_children&&(t+=" unreadchildren"),i.msgicon==i.icon&&(i.replied&&(t+=" replied",s+=this.get_label("replied")+" "),i.forwarded&&(t+=" forwarded",s+=this.get_label("forwarded")+" "),t+=" status"),$(i.icon).attr("class",t).attr("title",s)),i.msgicon&&i.msgicon!=i.icon&&(s="",t="msgicon",!i.unread&&i.unread_children&&(t+=" unreadchildren"),i.replied&&(t+=" replied",s+=this.get_label("replied")+" "),i.forwarded&&(t+=" forwarded",s+=this.get_label("forwarded")+" "),$(i.msgicon).attr("class",t).attr("title",s)),i.flagicon&&(t=i.flagged?"flagged":"unflagged",s=this.get_label(t),$(i.flagicon).attr("class",t).attr("aria-label",s).attr("title",s))},this.set_message_status=function(e,t,s){var i=this.message_list.rows[e];if(!i)return!1;"unread"==t?i.unread!=s&&this.update_thread_root(e,s?"unread":"read"):"flagged"==t&&this.update_thread_root(e,s?"flagged":"unflagged"),$.inArray(t,["unread","deleted","replied","forwarded","flagged"])>-1&&(i[t]=s)},this.set_message=function(e,t,s){var i=this.message_list&&this.message_list.rows[e];if(!i)return!1;t&&this.set_message_status(e,t,s),$.inArray(t,["unread","deleted","flagged"])>-1&&$(i.obj)[i[t]?"addClass":"removeClass"](t),this.set_unread_children(e),this.set_message_icon(e)},this.set_unread_children=function(e){var t=this.message_list.rows[e];if(!t.parent_uid){var s=!t.unread&&t.unread_children&&!t.expanded;$(t.obj)[s?"addClass":"removeClass"]("unroot")}},this.set_flagged_children=function(e){var t=this.message_list.rows[e];if(!t.parent_uid){var s=t.flagged_children&&!t.expanded;$(t.obj)[s?"addClass":"removeClass"]("flaggedroot")}},this.copy_messages=function(e,t){if(e&&"object"==typeof e)e=e.id;else if(!e)return this.folder_selector(t,(function(e){ref.command("copy",e)}));if(e&&e!=this.env.mailbox){var s=this.selection_post_data({_target_mbox:e});s._uid&&this.http_post("copy",s,this.display_message(this.get_label("copyingmessage"),"loading"))}},this.move_messages=function(e,t){if(e&&"object"==typeof e)e=e.id;else if(!e)return this.folder_selector(t,(function(e){ref.command("move",e)}));if(e&&(e!=this.env.mailbox||this.is_multifolder_listing())){var s=!1,i=this.selection_post_data({_target_mbox:e});i._uid&&("show"==this.env.action?s=this.set_busy(!0,"movingmessage"):this.show_contentframe(!1),this.enable_command(this.env.message_commands,!1),this.with_selected_messages("move",i,s))}},this.delete_messages=function(e){var t=this.message_list,s=this.env.trash_mailbox;return this.env.flag_for_deletion?(this.mark_message("delete"),!1):(s&&this.env.mailbox!=s?this.env.delete_junk&&this.env.junk_mailbox&&this.env.mailbox==this.env.junk_mailbox?this.permanently_remove_messages():t&&t.modkey==SHIFT_KEY||e&&rcube_event.get_modifier(e)==SHIFT_KEY?confirm(this.get_label("deletemessagesconfirm"))&&this.permanently_remove_messages():this.move_messages(s):this.permanently_remove_messages(),!0)},this.permanently_remove_messages=function(){var e=this.selection_post_data();e._uid&&(this.show_contentframe(!1),this.with_selected_messages("delete",e))},this.with_selected_messages=function(e,t,s,i){var n,a=0,r="delete"==e||!this.is_multifolder_listing();if(this.message_list){var o,l,c,h=[],d=this.message_list.get_selection();for(o=0,len=d.length;o<len;o++)l=d[o],this.env.threading&&(a+=this.update_thread(l),(c=this.message_list.find_root(l))!=l&&$.inArray(c,h)<0&&h.push(c)),r&&this.message_list.remove_row(l,this.env.display_next&&o==d.length-1);for(!this.env.display_next&&r&&this.message_list.clear_selection(),o=0,len=h.length;o<len;o++)this.add_tree_icons(h[o])}a<0?t._count=-1*a:a>0&&r&&this.delete_excessive_thread_rows(),r||(t._refresh=1),s||(n="move"==e?"movingmessage":"deletingmessage",s=this.display_message(this.get_label(n),"loading")),this.http_post(i||e,t,s)},this.selection_post_data=function(e){if("object"!=typeof e&&(e={}),e._mbox=this.env.mailbox,!e._uid){var t=this.env.uid?[this.env.uid]:this.message_list.get_selection();e._uid=this.uids_to_list(t)}return this.env.action&&(e._from=this.env.action),this.env.search_request&&(e._search=this.env.search_request),this.env.display_next&&this.env.next_uid&&(e._next_uid=this.env.next_uid),e},this.mark_message=function(e,t){var s,i,n,a=[],r=[],o=this.message_list;if(t?a[0]=t:this.env.uid?a[0]=this.env.uid:o&&(a=o.get_selection()),o)for(o.focus(),i=0,s=a.length;i<s;i++)n=a[i],("read"==e&&o.rows[n].unread||"unread"==e&&!o.rows[n].unread||"delete"==e&&!o.rows[n].deleted||"undelete"==e&&o.rows[n].deleted||"flagged"==e&&!o.rows[n].flagged||"unflagged"==e&&o.rows[n].flagged)&&r.push(n);else r=a;if(r.length||this.select_all_mode)switch(e){case"read":case"unread":this.toggle_read_status(e,r);break;case"delete":case"undelete":this.toggle_delete_status(r);break;case"flagged":case"unflagged":this.toggle_flagged_status(e,a)}},this.toggle_read_status=function(e,t){var s,i=t.length,n=this.selection_post_data({_uid:this.uids_to_list(t),_flag:e}),a=this.display_message(this.get_label("markingmessage"),"loading");for(s=0;s<i;s++)this.set_message(t[s],"unread","unread"==e);this.http_post("mark",n,a)},this.toggle_flagged_status=function(e,t){var s,i="flagged"==e,n=i?"markingmessage":"unmarkingmessage",a=t.length,r=this.selection_post_data({_uid:this.uids_to_list(t),_flag:e}),o=this.display_message(this.get_label(n),"loading");for(s=0;s<a;s++)this.set_message(t[s],"flagged",i);this.http_post("mark",r,o)},this.toggle_delete_status=function(e){var t,s,i=e.length,n=!0,a=this.message_list?this.message_list.rows:{};if(1==i)return!this.message_list||a[e[0]]&&!a[e[0]].deleted?this.flag_as_deleted(e):this.flag_as_undeleted(e),!0;for(t=0;t<i;t++)if(a[s=e[t]]&&!a[s].deleted){n=!1;break}return n?this.flag_as_undeleted(e):this.flag_as_deleted(e),!0},this.flag_as_undeleted=function(e){var t,s=e.length,i=this.selection_post_data({_uid:this.uids_to_list(e),_flag:"undelete"}),n=this.display_message(this.get_label("markingmessage"),"loading");for(t=0;t<s;t++)this.set_message(e[t],"deleted",!1);this.http_post("mark",i,n)},this.flag_as_deleted=function(e){for(var t=[],s=this.selection_post_data({_uid:this.uids_to_list(e),_flag:"delete"}),i=this.display_message(this.get_label("markingmessage"),"loading"),n=this.message_list,a=n?n.rows:{},r=0,o=0,l=e.length;o<l;o++)uid=e[o],a[uid]&&(a[uid].unread&&(t[t.length]=uid),this.env.skip_deleted?(r+=this.update_thread(uid),n.remove_row(uid,this.env.display_next&&o==n.selection.length-1)):this.set_message(uid,"deleted",!0));this.env.skip_deleted&&n&&(this.env.display_next&&n.rowcount||n.clear_selection(),r<0?s._count=-1*r:r>0&&this.delete_excessive_thread_rows()),t.length&&(s._ruid=this.uids_to_list(t)),this.env.skip_deleted&&this.env.display_next&&this.env.next_uid&&(s._next_uid=this.env.next_uid),this.http_post("mark",s,i)},this.flag_deleted_as_read=function(e){var t,s,i,n=this.message_list?this.message_list.rows:{};for("string"==typeof e&&(e=e.split(",")),s=0,i=e.length;s<i;s++)n[t=e[s]]&&this.set_message(t,"unread",!1)},this.uids_to_list=function(e){return this.select_all_mode?"*":e.length<=1?e.join(","):e},this.set_button_titles=function(){var e="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||(e="movemessagetotrash"),this.set_alttext("delete",e)},this.init_pagejumper=function(e){$(e).addClass("rcpagejumper").on("focus",(function(t){var s,i="";for(s=1;s<=ref.env.pagecount;s++)i+="<li>"+s+"</li>";i='<ul class="toolbarmenu">'+i+"</ul>",ref.pagejump||(ref.pagejump=$('<div id="pagejump-selector" class="popupmenu"></div>').appendTo(document.body).on("click","li",(function(){ref.busy||$(e).val($(this).text()).change()}))),ref.pagejump.data("count")!=s&&ref.pagejump.html(i),ref.pagejump.attr("rel","#"+this.id).data("count",s),ref.show_menu("pagejump-selector",!0,t),$(this).keydown()})).on("keydown keyup click",(function(t){var s,i=$("#pagejump-selector"),n=$("ul",i),a=$("li",n),r=(n.height(),parseInt(this.value));if(27!=t.which&&9!=t.which&&13!=t.which&&!i.is(":visible"))return ref.show_menu("pagejump-selector",!0,t);if("keydown"==t.type)if(40==t.which)a.length>r&&(this.value=r+=1);else if(38==t.which)r>1&&a.length>r-1&&(this.value=r-=1);else{if(13==t.which)return $(this).change();if(27==t.which||9==t.which)return $(e).val(ref.env.current_page)}$("li.selected",n).removeClass("selected"),(s=$(a[r-1])).length&&(s.addClass("selected"),$("#pagejump-selector").scrollTop(n.height()/a.length*(r-1)-i.height()/2))})).on("change",(function(e){var t=parseInt(this.value);t&&t!=ref.env.current_page&&!ref.busy&&(ref.hide_menu("pagejump-selector"),ref.list_page(t))}))},this.update_pagejumper=function(){$("input.rcpagejumper").val(this.env.current_page).prop("disabled",this.env.pagecount<2)},this.check_mailvelope=function(e){void 0!==window.mailvelope?this.mailvelope_load(e):$(window).on("mailvelope",(function(){ref.mailvelope_load(e)}))},this.mailvelope_load=function(e){this.env.browser_capabilities&&(this.env.browser_capabilities.pgpmime=1);var t=this.env.user_id;mailvelope.getKeyring(t).then((function(t){ref.mailvelope_keyring=t,ref.mailvelope_init(e,t)}),(function(s){mailvelope.createKeyring(t).then((function(t){ref.mailvelope_keyring=t,ref.mailvelope_init(e,t)}),(function(e){console.error(e)}))}))},this.mailvelope_init=function(e,t){if(window.mailvelope)if("show"==e||"preview"==e||"print"==e){if(this.env.is_pgp_content){var s=$(this.env.is_pgp_content).text();ref.mailvelope_display_container(this.env.is_pgp_content,s,t)}else if(this.env.pgp_mime_part){var i=this.display_message(this.get_label("loadingdata"),"loading"),n=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(e,t,s){ref.http_error(e,t,s,i)},success:function(e){ref.mailvelope_display_container(n,e,t,i)}})}}else if("compose"==e){this.env.compose_commands.push("compose-encrypted");var a=$('input[name="_is_html"]').val()>0;if(this.env.pgp_mime_message){var r=this.set_busy(!0,this.get_label("loadingdata"));$.ajax({type:"GET",url:this.url("get",this.env.pgp_mime_message),error:function(e,t,s){ref.http_error(e,t,s,r),ref.enable_command("compose-encrypted",!a)},success:function(e){ref.set_busy(!1,null,r),a&&(ref.command("toggle-editor",{html:!1,noconvert:!0}),$("#"+ref.env.composebody).val("")),ref.compose_encrypted({quotedMail:e}),ref.enable_command("compose-encrypted",!0)}})}else this.enable_command("compose-encrypted",!a);this.addEventListener("actionafter",(function(e){e.ret&&"toggle-editor"==e.action&&ref.enable_command("compose-encrypted",!e.props.html)}))}},this.compose_encrypted=function(e){var t,s=$("#"+this.env.composebody).parent();ref.mailvelope_editor?(ref.mailvelope_editor=null,ref.compose_skip_unsavedcheck=!1,ref.set_button("compose-encrypted","act"),s.removeClass("mailvelope").find("iframe:not([aria-hidden=true])").remove(),$("#"+ref.env.composebody).show(),$("[name='_pgpmime']").remove(),ref.enable_command("spellcheck","insert-sig","toggle-editor","insert-response","save-response",!0),ref.triggerEvent("compose-encrypted",{active:!1})):(this.spellcheck_state()&&this.editor.spellcheck_stop(),t=e.quotedMail?{quotedMail:e.quotedMail,quotedMailIndent:!1}:{predefinedText:$("#"+this.env.composebody).val()},"reply"==this.env.compose_mode&&(t.quotedMailIndent=!0,t.quotedMailHeader=this.env.compose_reply_header),mailvelope.createEditorContainer("#"+s.attr("id"),ref.mailvelope_keyring,t).then((function(e){ref.mailvelope_editor=e,ref.compose_skip_unsavedcheck=!0,ref.set_button("compose-encrypted","sel"),s.addClass("mailvelope"),$("#"+ref.env.composebody).hide(),ref.enable_command("spellcheck","insert-sig","toggle-editor","insert-response","save-response",!1),ref.triggerEvent("compose-encrypted",{active:!0}),ref.env.attachments&&!$.isEmptyObject(ref.env.attachments)&&(alert(ref.get_label("encryptnoattachments")),$.each(ref.env.attachments,(function(e,t){ref.remove_from_attachment_list(e)})))}),(function(e){console.error(e),console.log(t)})))},this.mailvelope_submit_messageform=function(e,t){var s=[];$.each(["to","cc","bcc"],(function(e,t){for(var i,n=$.trim($('[name="_'+t+'"]').val());n.length&&rcube_check_email(n,!0);)i=RegExp.$2,s.push(i),n=n.substr(n.indexOf(i)+i.length+1).replace(/^\s*,\s*/,"")}));var i=s.length>0;return ref.mailvelope_keyring.validKeyForAddress(s).then((function(n){var a=[];if($.each(n,(function(e,t){!1===t&&(i=!1,a.push(e))})),!i&&a.length)return ref.simple_dialog(ref.get_label("nopubkeyfor").replace("$email",a.join(", "))+"<p>"+ref.get_label("searchpubkeyservers")+"</p>","encryptedsendialog",(function(){ref.mailvelope_search_pubkeys(a,(function(){return!0}))}),{button:"search"}),!1;if(!i)return s.length||(alert(ref.get_label("norecipientwarning")),$("[name='_to']").focus()),!1;var r=[],o=ref.env.identities[$("[name='_from'] option:selected").val()];$.each(ref.env.identities,(function(e,t){r.push(t.email)})),ref.mailvelope_keyring.validKeyForAddress(r).then((function(i){if(valid_sender=null,$.each(i,(function(e,t){if(!1!==t&&(valid_sender=e,valid_sender==o))return!1})),!valid_sender&&!confirm(ref.get_label("nopubkeyforsender")))return!1;s.push(valid_sender),ref.mailvelope_editor.encrypt(s).then((function(s){var i=ref.gui_objects.messageform,n=$("[name='_pgpmime']",i),a=ref.set_busy(!0,e||t?"savingmessage":"sendingmessage");i.target="savetarget",i._draft.value=e?"1":"",i.action=ref.add_url(i.action,"_unlock",a),i.action=ref.add_url(i.action,"_framed",1),t&&(i.action=ref.add_url(i.action,"_saveonly",1)),n.length||(n=$('<input type="hidden" name="_pgpmime">').appendTo(i)),n.val(s),i.submit()}),(function(e){console.log(e)}))}),(function(e){console.error(e)}))}),(function(e){console.error(e)})),!1},this.mailvelope_display_container=function(e,t,s,i){var n=function(t){$(e+" > iframe").remove(),ref.hide_message(i),ref.display_message(t.message,"error")};mailvelope.createDisplayContainer(e,t,s,{showExternalContent:this.env.safemode}).then((function(t){if(t.error&&t.error.message)return n(t.error);ref.hide_message(i),$(e).addClass("mailvelope").children().not("iframe").hide(),ref.env.pgp_mime_part&&$("#attach"+ref.env.pgp_mime_part).remove(),setTimeout((function(){$(window).resize()}),10)}),n)},this.mailvelope_search_pubkeys=function(e,t,s){var i=[],n=new PublicKey,a=ref.display_message(ref.get_label("loading"),"loading");$.each(e,(function(e,t){var s=$.Deferred();n.search(t,(function(e,i){null!==i?s.resolve([t]):s.resolve([t].concat(e))})),i.push(s)})),$.when.apply($,i).then((function(){var e=[],i=[];$.each(arguments,(function(t,s){var n=s.shift();s.length?i=i.concat(s):e.push(n)})),ref.hide_message(a),t(!0),i.length&&ref.mailvelope_key_import_dialog(i,s),e.length&&ref.display_message(ref.get_label("nopubkeyfor").replace("$email",e.join(", ")),"warning")})).fail((function(){console.error("Pubkey lookup failed with",arguments),ref.hide_message(a),ref.display_message("pubkeysearcherror","error"),t(!1)}))},this.mailvelope_key_import_dialog=function(e,t){var s=$("<div>").addClass("listing pgpkeyimport");$.each(e,(function(e,t){var i=$("<div>").addClass("key");t.revoked&&i.addClass("revoked"),t.disabled&&i.addClass("disabled"),t.expired&&i.addClass("expired"),i.append($("<label>").addClass("keyid").text(ref.get_label("keyid"))),i.append($("<a>").text(t.keyid.substr(-8).toUpperCase()).attr("href",t.info).attr("target","_blank").attr("tabindex","-1")),i.append($("<label>").addClass("keylen").text(ref.get_label("keylength"))),i.append($("<span>").text(t.keylen)),t.expirationdate&&(i.append($("<label>").addClass("keyexpired").text(ref.get_label("keyexpired"))),i.append($("<span>").text(new Date(1e3*t.expirationdate).toDateString()))),t.revoked&&i.append($("<span>").addClass("keyrevoked").text(ref.get_label("keyrevoked")));var n=$("<ul>").addClass("uids");$.each(t.uids,(function(e,t){var s=$("<li>").addClass("uid");t.revoked&&s.addClass("revoked"),t.disabled&&s.addClass("disabled"),t.expired&&s.addClass("expired"),n.append(s.text(t.uid))})),i.append(n),i.append($("<input>").attr("type","button").attr("rel",t.keyid).attr("value",ref.get_label("import")).addClass("button importkey").prop("disabled",t.revoked||t.disabled||t.expired)),s.append(i)})),ref.show_popup_dialog($("<div>").append($("<p>").html(ref.get_label("encryptpubkeysfound"))).append(s),ref.get_label("importpubkeys"),[{text:ref.get_label("close"),click:function(){(ref.is_framed()?parent.$:$)(this).dialog("close")}}]),s.on("click","input.button.importkey",(function(){var e=$(this),s=e.attr("rel"),i=new PublicKey,n=ref.display_message(ref.get_label("loading"),"loading");i.get(s,(function(i,a){ref.hide_message(n),a?ref.display_message(ref.get_label("keyservererror"),"error"):t?t(i):ref.mailvelope_keyring.importPublicKey(i).then((function(t){if("REJECTED"===t);else{var i=s.substr(-8).toUpperCase();e.closest(".key").fadeOut(),ref.display_message(ref.get_label("keyimportsuccess").replace("$key",i),"confirmation")}}),(function(e){console.log(e)}))}))}))},this.expunge_mailbox=function(e){var t,s={_mbox:e};e==this.env.mailbox&&(t=this.set_busy(!0,"loading"),s._reload=1,this.env.search_request&&(s._search=this.env.search_request)),this.http_post("expunge",s,t)},this.purge_mailbox=function(e){var t,s={_mbox:e};if(!confirm(this.get_label("purgefolderconfirm")))return!1;e==this.env.mailbox&&(t=this.set_busy(!0,"loading"),s._reload=1),this.http_post("purge",s,t)},this.purge_mailbox_test=function(){return this.env.exists&&(this.env.mailbox==this.env.trash_mailbox||this.env.mailbox==this.env.junk_mailbox||this.env.mailbox.startsWith(this.env.trash_mailbox+this.env.delimiter)||this.env.mailbox.startsWith(this.env.junk_mailbox+this.env.delimiter))},this.mark_all_read=function(e,t){var s,i,n=[],a=this.message_list,r=e||this.env.mailbox,o={_uid:"*",_flag:"read",_mbox:r,_folders:t};if("string"!=typeof t){if(!(s=this.mark_all_read_state(r)))return;if(s>1)return $.each({cur:1,sub:2,all:4},(function(e,t){var i=$("<label>").attr("style","display:block; line-height:22px"),a=$("<span>").text(ref.get_label("folders-"+e)),r=$("<input>").attr({type:"radio",value:e,name:"mode"});s&t||(i.attr("class","disabled"),r.attr("disabled",!0)),n.push(i.append(r).append(a))})),i=$("<div>").append(n),$("input:not([disabled]):first",i).attr("checked",!0),void this.show_popup_dialog(i,this.get_label("markallread"),[{class:"mainaction",text:this.get_label("mark"),click:function(){ref.mark_all_read(r,$("input:checked",this).val()),$(this).dialog("close")}},{text:this.get_label("cancel"),click:function(){$(this).dialog("close")}}]);o._folders="cur"}$.each(a?a.rows:[],(function(e,s){if(s.unread){var i=ref.env.messages[e].mbox;("all"==t||i==ref.env.mailbox||"sub"==t&&i.startsWith(ref.env.mailbox+ref.env.delimiter))&&ref.set_message(e,"unread",!1)}})),this.http_post("mark",o,this.display_message(this.get_label("markingmessage"),"loading"))},this.mark_all_read_state=function(e){var t=0,s=this.treelist.get_item(e||this.env.mailbox),i=$(s).is(".unread")?1:0,n=$("li.unread",s).length;return t+=i,t+=n?2:0,t+=$("li.unread",ref.gui_objects.folderlist).length>i+n?4:0,this.enable_command("mark-all-read",t>0),t},this.login_user_keyup=function(e){var t=rcube_event.get_keycode(e),s=$("#rcmloginpwd");return!(13==t&&s.length&&!s.val())||(s.focus(),rcube_event.cancel(e))},this.open_compose_step=function(e){var t=this.url("mail/compose",e);this.env.compose_extwin&&!this.env.extwin?this.open_window(t):(this.redirect(t),this.env.extwin&&window.resizeTo(Math.max(this.env.popup_width,$(window).width()),$(window).height()+24))},this.init_messageform=function(){if(!this.gui_objects.messageform)return!1;var e,t,s,i,n=$("[name='_from']"),a=$("[name='_to']"),r=$("input[name='_subject']"),o=$("[name='_message']").get(0),l="1"==$("input[name='_is_html']").val(),c=["cc","bcc","replyto","followupto"],h=this.opener();for(e in h&&"compose"==h.env.action&&(setTimeout((function(){opener.history.length>1?opener.history.back():h.redirect(h.get_task_url("mail"))}),100),this.env.opened_extwin=!0),this.env.autocomplete_threads>0&&(i={threads:this.env.autocomplete_threads,sources:this.env.autocomplete_sources}),this.init_address_input_events(a,i),c)this.init_address_input_events($("[name='_"+c[e]+"']"),i);l||(s=this.env.top_posting&&this.env.compose_mode?0:o.value.length,"select-one"==n.prop("type")&&(this.set_caret_pos(o,0),this.change_identity(n[0])),this.set_caret_pos(o,s),s&&$(o).scrollTop(o.scrollHeight)),this.env.save_localstorage&&this.compose_restore_dialog(0,l),""==a.val()?t=a:""==r.val()?t=r:o&&(t=o),this.env.compose_focus_elem=$(t).filter(":visible").focus().get(0),this.compose_field_hash(!0),this.auto_save_start()},this.compose_restore_dialog=function(e,t){var s,i,n,a=this.local_storage_get_item("compose.index",[]),r=function(e){++e<a.length&&ref.compose_restore_dialog(e,t)};for(s=e||0;s<a.length;s++)if(i=a[s],n=this.local_storage_get_item("compose."+i,null,!0)){if(n.changed&&i==this.env.compose_id){this.restore_compose_form(i,t);break}if((!this.env.draft_id||!n.draft_id||n.draft_id==this.env.draft_id)&&(!this.env.reply_msgid||n.reply_msgid==this.env.reply_msgid)&&n.changed&&n.session!=this.env.session_id){this.show_popup_dialog(this.get_label("restoresavedcomposedata").replace("$date",new Date(n.changed).toLocaleString()).replace("$subject",n._subject).replace(/\n/g,"<br/>"),this.get_label("restoremessage"),[{text:this.get_label("restore"),class:"mainaction",click:function(){ref.restore_compose_form(i,t),ref.remove_compose_data(i),ref.save_compose_form_local(),$(this).dialog("close")}},{text:this.get_label("delete"),class:"delete",click:function(){ref.remove_compose_data(i),$(this).dialog("close"),r(s)}},{text:this.get_label("ignore"),click:function(){$(this).dialog("close"),r(s)}}]);break}}},this.init_address_input_events=function(e,t){this.env.recipients_delimiter=this.env.recipients_separator+" ",e.keydown((function(e){return ref.ksearch_keydown(e,this,t)})).attr({autocomplete:"off","aria-autocomplete":"list","aria-expanded":"false",role:"combobox"}),$(document).on("click",(function(){ref.ksearch_hide()}))},this.submit_messageform=function(e,t){var s=this.gui_objects.messageform;if(s){if(!t&&this.env.is_sent)return this.simple_dialog(this.get_label("messageissent"),"",(function(){return ref.submit_messageform(!1,!0),!0}));if(this.mailvelope_editor)return this.mailvelope_submit_messageform(e,t);var i=this.set_busy(!0,e||t?"savingmessage":"sendingmessage"),n=this.spellcheck_lang(),a=[];$("li",this.gui_objects.attachmentlist).each((function(){a.push(this.id.replace(/^rcmfile/,""))})),$('input[name="_attachments"]',s).val(a.join()),s.target="savetarget",s._draft.value=e?"1":"",s.action=this.add_url(s.action,"_unlock",i),s.action=this.add_url(s.action,"_lang",n),s.action=this.add_url(s.action,"_framed",1),t&&(s.action=this.add_url(s.action,"_saveonly",1)),this.submit_timer=setTimeout((function(){ref.set_busy(!1,null,i),ref.display_message(ref.get_label("requesttimedout"),"error")}),1e3*this.env.request_timeout),s.submit()}},this.compose_recipient_select=function(e){var t,s,i=0;for(s=0;s<e.selection.length;s++)t=e.selection[s],this.env.contactdata[t]&&i++;this.enable_command("add-recipient",i)},this.compose_add_recipient=function(e){e||(e=(e=$(this.env.focused_field).filter(":visible")).length?e.attr("id").replace("_",""):"to");var t=[],s=$("#_"+e),i=this.env.recipients_delimiter;if(this.contact_list&&this.contact_list.selection.length)for(var n,a=0;a<this.contact_list.selection.length;a++)if((n=this.contact_list.selection[a])&&this.env.contactdata[n]&&(t.push(this.env.contactdata[n]),"E"==n.charAt(0)&&this.env.contactdata[n].indexOf("@")<0&&s.length)){var r=n.substr(1);this.group2expand[r]={name:this.env.contactdata[n],input:s.get(0)},this.http_request("group-expand",{_source:this.env.source,_gid:r},!1)}if(t.length&&s.length){var o=s.val(),l=new RegExp(RegExp.escape(i)+"\\s*$");o&&!l.test(o)&&(o+=i+" "),s.val(o+t.join(i+" ")+i+" ").change(),this.triggerEvent("add-recipient",{field:e,recipients:t})}return t.length},this.check_compose_input=function(e){var t,s,i,n=this.env.max_disclosed_recipients,a=$("[name='_to']"),r=$("[name='_cc']"),o=$("[name='_bcc']"),l=$("[name='_from']"),c=$("[name='_subject']"),h=function(e){return(e=$.map(e,(function(e){return(e=$.trim(e.val())).length?e:null}))).join(",").replace(/^[\s,;]+/,"").replace(/[\s,;]+$/,"")};if("text"==l.prop("type")&&!rcube_check_email(l.val(),!0))return alert(this.get_label("nosenderwarning")),l.focus(),!1;if(!rcube_check_email(h([a,r,o]),!0))return alert(this.get_label("norecipientwarning")),a.focus(),!1;for(t in this.env.attachments)if("object"==typeof this.env.attachments[t]&&!this.env.attachments[t].complete)return alert(this.get_label("notuploadedwarning")),!1;if(n&&!this.env.disclosed_recipients_warned&&rcube_check_email(s=h([a,r]),!0,!0)>n){var d=function(t){if(t){var n=o.val();o.val((n?n+", ":"")+s).change(),a.val("").change(),r.val("").change()}i.dialog("close"),ref.check_compose_input(e)&&ref.command(e,{nocheck:!0})};return i=this.show_popup_dialog(this.get_label("disclosedrecipwarning"),this.get_label("disclosedreciptitle"),[{text:this.get_label("sendmessage"),click:function(){d(!1)},class:"mainaction"},{text:this.get_label("bccinstead"),click:function(){d(!0)}},{text:this.get_label("cancel"),click:function(){i.dialog("close")}}],{dialogClass:"warning"}),this.env.disclosed_recipients_warned=!0,!1}if(!this.env.nosubject_warned&&""==c.val()){var _=$("<input>").attr({type:"text",size:40}),u=$('<div class="prompt">').append($('<div class="message">').text(this.get_label("nosubjectwarning"))).append(_);d=function(){c.val(_.val()),i.dialog("close"),ref.check_compose_input(e)&&ref.command(e,{nocheck:!0})};return i=this.show_popup_dialog(u,this.get_label("nosubjecttitle"),[{text:this.get_label("sendmessage"),click:function(){d()},class:"mainaction"},{text:this.get_label("cancel"),click:function(){c.focus(),i.dialog("close")}}],{dialogClass:"warning"}),_.select().keydown((function(e){13==e.which&&d()})),this.env.nosubject_warned=!0,!1}return this.mailvelope_editor||this.editor.get_content()||confirm(this.get_label("nobodywarning"))?(this.editor.save(),!0):(this.editor.focus(),!1)},this.toggle_editor=function(e,t,s){var i=this.editor.toggle(e.html,e.noconvert||!1);return e.mode=e.html?"html":"plain",!i&&s&&(e.mode=e.html?"plain":"html",$(s.target).filter("select").val(e.mode)),i&&$("input[name='_is_html']").val(e.html?1:0),i},this.insert_response=function(e){return this.editor.replace(this.env.textresponses[e])},this.save_response=function(){var e={},t=this.editor.get_content({selection:!0,format:"text",nosig:!0}),s='<form class="propform"><div class="prop block"><label>'+this.get_label("responsename")+'</label><input type="text" name="name" id="ffresponsename" size="40" /></div><div class="prop block"><label>'+this.get_label("responsetext")+'</label><textarea name="text" id="ffresponsetext" cols="40" rows="8"></textarea></div></form>';e[this.get_label("save")]=function(e){var t=$("#ffresponsename").val(),s=$("#ffresponsetext").val();if(!s)return $("#ffresponsetext").select(),!1;t||(t=s.replace(/[\r\n]+/g," ").substring(0,40));var i=ref.display_message(ref.get_label("savingresponse"),"loading");ref.http_post("settings/responses",{_insert:1,_name:t,_text:s},i),$(this).dialog("close")},e[this.get_label("cancel")]=function(){$(this).dialog("close")},this.show_popup_dialog(s,this.get_label("newresponse"),e,{button_classes:["mainaction"]}),$("#ffresponsetext").val(t),$("#ffresponsename").select()},this.add_response_item=function(e){var t=e.key;if(this.env.textresponses[t]=e,this.gui_objects.responseslist){var s=$("<li>").appendTo(this.gui_objects.responseslist);$("<a>").addClass("insertresponse active").attr("href","#").attr("rel",t).attr("tabindex","0").html(this.quote_html(e.name)).appendTo(s).mousedown((function(e){return rcube_event.cancel(e)})).on("mouseup keypress",(function(e){if("mouseup"==e.type||13==rcube_event.get_keycode(e))return ref.command("insert-response",$(this).attr("rel")),$(document.body).trigger("mouseup"),rcube_event.cancel(e)}))}},this.edit_responses=function(){},this.delete_response=function(e){!e&&this.responses_list&&(e=this.responses_list.get_selection()[0]);e&&confirm(this.get_label("deleteresponseconfirm"))&&this.http_post("settings/delete-response",{_key:e},!1)},this.spellcheck_state=function(){var e=this.editor.spellcheck_state();return $.each(this.buttons.spellcheck||[],(function(t,s){$("#"+s.id)[e?"addClass":"removeClass"]("selected")})),e},this.spellcheck_lang=function(){return this.editor.get_language()},this.spellcheck_lang_set=function(e){this.editor.set_language(e)},this.spellcheck_resume=function(e){this.editor.spellcheck_resume(e)},this.set_draft_id=function(e){if(e&&e!=this.env.draft_id){var t={task:"mail",action:""},s=this.opener(!1,t)||this.opener(!0,t);s&&s.env.mailbox==this.env.drafts_mailbox&&s.command("checkmail"),this.env.draft_id=e,$("input[name='_draft_saveid']").val(e),window.frames.savetarget&&window.frames.savetarget.history&&!this.draft_autosave_submit&&!this.mailvelope_editor&&window.frames.savetarget.history.back(),this.draft_autosave_submit=!1}this.remove_compose_data(this.env.compose_id),this.compose_skip_unsavedcheck=!1},this.auto_save_start=function(){this.env.draft_autosave&&(this.draft_autosave_submit=!1,this.save_timer=setTimeout((function(){ref.draft_autosave_submit=!0,ref.command("savedraft")}),1e3*this.env.draft_autosave)),!this.local_save_timer&&window.localStorage&&this.env.save_localstorage&&(this.compose_type_activity=this.compose_type_activity_last=0,$(document).keypress((function(e){ref.compose_type_activity++})),this.local_save_timer=setInterval((function(){ref.compose_type_activity>ref.compose_type_activity_last&&(ref.save_compose_form_local(),ref.compose_type_activity_last=ref.compose_type_activity)}),5e3),$(window).on("unload",(function(){ref.env.server_error||ref.remove_compose_data(ref.env.compose_id)}))),window.onbeforeunload||(window.onbeforeunload=function(){if(!ref.compose_skip_unsavedcheck&&ref.cmp_hash!=ref.compose_field_hash())return ref.get_label("notsentwarning")}),this.busy=!1},this.compose_field_hash=function(e){var t,s,i,n="",a=["to","cc","bcc","subject"];for(t=0;t<a.length;t++)(i=$('[name="_'+a[t]+'"]').val())&&(n+=i+":");if(n+=this.editor.get_content({refresh:!1}),this.env.attachments)for(s in this.env.attachments)n+=s;return this.mailvelope_editor&&(n+=";"+(new Date).getTime()),e&&(this.cmp_hash=n),n},this.save_compose_form_local=function(){if(this.env.save_localstorage){var e={session:this.env.session_id,changed:(new Date).getTime()},t=!0;if(this.editor.save(),this.env.draft_id&&(e.draft_id=this.env.draft_id),this.env.reply_msgid&&(e.reply_msgid=this.env.reply_msgid),$("input, select, textarea",this.gui_objects.messageform).each((function(s,i){switch(i.tagName.toLowerCase()){case"input":if("button"==i.type||"submit"==i.type||"hidden"==i.type&&"_is_html"!=i.name)break;e[i.name]="checkbox"!=i.type||i.checked?$(i).val():"",""!=e[i.name]&&"hidden"!=i.type&&(t=!1);break;case"select":e[i.name]=$("option:checked",i).val();break;default:e[i.name]=$(i).val(),""!=e[i.name]&&(t=!1)}})),!t){var s=this.local_storage_get_item("compose.index",[]),i=this.env.compose_id;$.inArray(i,s)<0&&s.push(i),this.local_storage_set_item("compose."+i,e,!0),this.local_storage_set_item("compose.index",s)}}},this.restore_compose_form=function(e,t){var s=this.local_storage_get_item("compose."+e,!0);s&&"object"==typeof s&&($.each(s,(function(e,t){if("_"==e[0]){var s=$("*[name='"+e+"']");s[0]&&"checkbox"==s[0].type?s.prop("checked",""!=t):s.val(t)}})),("1"==s._is_html&&!t||"1"!=s._is_html&&t)&&this.command("toggle-editor",{id:this.env.composebody,html:!t,noconvert:!0}))},this.remove_compose_data=function(e){var t=this.local_storage_get_item("compose.index",[]);$.inArray(e,t)>=0&&(this.local_storage_remove_item("compose."+e),this.local_storage_set_item("compose.index",$.grep(t,(function(t,s){return t!=e}))))},this.clear_compose_data=function(){var e,t=this.local_storage_get_item("compose.index",[]);for(e=0;e<t.length;e++)this.local_storage_remove_item("compose."+t[e]);this.local_storage_remove_item("compose.index")},this.change_identity=function(e,t){if(!e||!e.options)return!1;t||(t=this.env.show_sig);var s=e.options[e.selectedIndex].value,i=this.env.identity,n=this.env.recipients_separator,a=RegExp.escape(n);return this.env.signatures&&this.env.signatures[s]?(this.enable_command("insert-sig",!0),this.env.compose_commands.push("insert-sig")):this.enable_command("insert-sig",!1),this.env.identities_initialized||(this.env.identities_initialized=!0,this.env.show_sig_later&&(this.env.show_sig=!0),!this.env.opened_extwin)?($.each(["replyto","bcc"],(function(){var e,t=i&&ref.env.identities[i]?ref.env.identities[i][this]:"",r=s&&ref.env.identities[s]?ref.env.identities[s][this]:"",o=$('[name="_'+this+'"]'),l=o.val();t&&l&&(e=new RegExp("\\s*"+RegExp.escape(t)+"\\s*"),l=l.replace(e,"")),e=new RegExp(a+"\\s*"+a,"g"),l=String(l).replace(e,n),e=new RegExp("^[\\s"+a+"]+"),l=l.replace(e,""),r&&-1==l.indexOf(r)&&-1==l.indexOf(r.replace(/"/g,""))&&(l&&(e=new RegExp("["+a+"\\s]+$"),l=l.replace(e,"")+n+" "),l+=r+n+" "),(t||r)&&o.val(l).change()})),this.editor.change_signature(s,t),this.env.identity=s,this.triggerEvent("change_identity"),!0):void 0},this.upload_input=function(e){$("#"+e+' input[type="file"]').click()},this.upload_file=function(e,t,s){if(e){var i=0,n=0;if($.each($(e).get(0).elements||[],(function(){if("file"==this.type){var e,t=this.files?this.files.length:this.value?1:0;if(this.files)for(e=0;e<t;e++)i+=this.files[e].size;n+=t}})),n){if(this.env.max_filesize&&this.env.filesizeerror&&i>this.env.max_filesize)return this.display_message(this.env.filesizeerror,"error"),!1;if(this.env.max_filecount&&this.env.filecounterror&&n>this.env.max_filecount)return this.display_message(this.env.filecounterror,"error"),!1;var a=this.async_upload_form(e,t||"upload",(function(e){var t,i="";try{this.contentDocument?t=this.contentDocument:this.contentWindow&&(t=this.contentWindow.document),i=t.childNodes[1].innerHTML}catch(e){}i.match(/add2attachment/)||bw.opera&&(!ref.env.uploadframe||ref.env.uploadframe!=e.data.ts)||(i.match(/display_message/)||ref.display_message(ref.get_label("fileuploaderror"),"error"),ref.remove_from_attachment_list(e.data.ts),s&&ref.set_busy(!1,null,s)),bw.opera&&(ref.env.uploadframe=e.data.ts)})),r="<span>"+this.get_label("uploading"+(n>1?"many":""))+"</span>",o=a.replace(/^rcmupload/,"");return this.add2attachment_list(o,{name:"",html:r,classname:"uploading",frame:a,complete:!1}),this.env.upload_progress_time&&this.upload_progress_start("upload",o),this.gui_objects.attachmentform=e,!0}}},this.add2attachment_list=function(e,t,s){if(s&&this.triggerEvent("fileuploaded",{name:e,attachment:t,id:s}),this.env.attachments||(this.env.attachments={}),s&&this.env.attachments[s]&&delete this.env.attachments[s],this.env.attachments[e]=t,!this.gui_objects.attachmentlist)return!1;!t.complete&&this.env.loadingicon&&(t.html='<img src="'+this.env.loadingicon+'" alt="" class="uploading" />'+t.html),!t.complete&&t.frame&&(t.html='<a title="'+this.get_label("cancel")+'" onclick="return rcmail.cancel_attachment_upload(\''+e+"', '"+t.frame+'\');" href="#cancelupload" class="cancelupload">'+(this.env.cancelicon?'<img src="'+this.env.cancelicon+'" alt="'+this.get_label("cancel")+'" />':this.get_label("cancel"))+"</a>"+t.html);var i,n=$("<li>");n.attr("id",e).addClass(t.classname).html(t.html).on("mouseover",(function(){rcube_webmail.long_subject_title_ex(this)})),s&&(i=document.getElementById(s))?n.replaceAll(i):n.appendTo(this.gui_objects.attachmentlist);var a=$(this.gui_objects.attachmentlist).attr("data-tabindex")||"0";return n.find("a").attr("tabindex",a),this.triggerEvent("fileappended",{name:e,attachment:t,id:s,item:n}),!0},this.remove_from_attachment_list=function(e){this.env.attachments&&(delete this.env.attachments[e],$("#"+e).remove())},this.remove_attachment=function(e){return e&&this.env.attachments[e]&&this.http_post("remove-attachment",{_id:this.env.compose_id,_file:e}),!1},this.cancel_attachment_upload=function(e,t){return!(!e||!t)&&(this.remove_from_attachment_list(e),$("iframe[name='"+t+"']").remove(),!1)},this.upload_progress_start=function(e,t){setTimeout((function(){ref.http_request(e,{_progress:t})}),1e3*this.env.upload_progress_time)},this.upload_progress_update=function(e){var t=$("#"+e.name+" > span");t.length&&e.text&&(t.text(e.text),e.done||this.upload_progress_start(e.action,e.name))},this.rename_attachment=function(e){var t=this.env.attachments?this.env.attachments[e]:null;if(t){var s=$("<input>").attr({type:"text",size:50}).val(t.name),i=$("<label>").text(this.get_label("namex")).append(s);this.simple_dialog(i,"attachmentrename",(function(){var i;if((i=s.val())&&i!=t.name)return ref.http_post("rename-attachment",{_id:ref.env.compose_id,_file:e,_name:i},ref.set_busy(!0,"loading")),!0}),{open:function(){s.select()}})}},this.rename_attachment_handler=function(e,t){var s=this.env.attachments?this.env.attachments[e]:null,i=$("#"+e+" > a.filename"),n=$("<a>");s&&t&&(s.name=t,1==i.length&&(n.text(t).append($("span",i).clone()),i.html(n.html()),i.parent().attr("title","")))},this.add_contact=function(e){return e&&this.http_post("addcontact",{_address:e}),!0},this.qsearch=function(e){if(""!=e||$(this.gui_objects.qsearchbox).val()||$(this.gui_objects.search_interval).val()){var t,s=this.set_busy(!0,"searching"),i=this.search_params(e),n="compose"==this.env.action&&this.contact_list?"search-contacts":"search";return this.message_list?this.clear_message_list():this.contact_list&&this.list_contacts_clear(),this.env.source&&(i._source=this.env.source),this.env.group&&(i._gid=this.env.group),this.env.current_page=1,t=this.http_request(n,i,s),this.env.qsearch={lock:s,request:t},this.enable_command("set-listmode",this.env.threads&&"base"==(this.env.search_scope||"base")),!0}return!1},this.continue_search=function(e){var t=this.set_busy(!0,"stillsearching");setTimeout((function(){var s=ref.search_params();s._continue=e,ref.env.qsearch={lock:t,request:ref.http_request("search",s,t)}}),100)},this.search_params=function(e,t){var s,i={},n=[],a=this.env.search_mods,r=this.env.search_scope||"base",o="all"==r?"*":this.env.mailbox;if(!t&&this.gui_objects.search_filter&&(t=this.gui_objects.search_filter.value),!e&&this.gui_objects.qsearchbox&&(e=this.gui_objects.qsearchbox.value),t&&(i._filter=t),this.gui_objects.search_interval&&(i._interval=$(this.gui_objects.search_interval).val()),e&&(i._q=e,a&&this.message_list&&(a=a[o]||a["*"]),a)){for(s in a)n.push(s);i._headers=n.join(",")}return r&&(i._scope=r),o&&"all"!=r&&(i._mbox=o),i},this.reset_search_filter=function(){this.filter_disabled=!0,this.gui_objects.search_filter&&$(this.gui_objects.search_filter).val("ALL").change(),this.filter_disabled=!1},this.reset_qsearch=function(e){this.gui_objects.qsearchbox&&(this.gui_objects.qsearchbox.value=""),this.gui_objects.search_interval&&$(this.gui_objects.search_interval).val(""),this.env.qsearch&&this.abort_request(this.env.qsearch),e&&(this.env.search_scope="base",this.reset_search_filter()),this.env.qsearch=null,this.env.search_request=null,this.env.search_id=null,this.select_all_mode=!1,this.enable_command("set-listmode",this.env.threads)},this.set_searchscope=function(e){var t=this.env.search_scope;this.env.search_scope=e,e!=t&&this.env.search_request&&(!this.qsearch(this.gui_objects.qsearchbox.value)&&this.env.search_filter&&"ALL"!=this.env.search_filter&&this.filter_mailbox(this.env.search_filter),"all"!=e&&this.select_folder(this.env.mailbox,"",!0))},this.set_searchinterval=function(e){var t=this.env.search_interval;this.env.search_interval=e,e!=t&&this.env.search_request&&(!this.qsearch(this.gui_objects.qsearchbox.value)&&this.env.search_filter&&"ALL"!=this.env.search_filter&&this.filter_mailbox(this.env.search_filter),e&&this.select_folder(this.env.mailbox,"",!0))},this.set_searchmods=function(e){var t=this.env.mailbox;"all"==(this.env.search_scope||"base")&&(t="*"),this.env.search_mods||(this.env.search_mods={}),t&&(this.env.search_mods[t]=e)},this.is_multifolder_listing=function(){return void 0!==this.env.multifolder_listing?this.env.multifolder_listing:this.env.search_request&&"base"!=(this.env.search_scope||"base")},this.sent_successfully=function(e,t,s,i){if(this.display_message(t,e),this.compose_skip_unsavedcheck=!0,this.env.extwin){i||this.lock_form(this.gui_objects.messageform);var n={task:"mail",action:""},a=this.opener(!1,n)||this.opener(!0,n);a&&(a.display_message(t,e),s&&$.inArray(a.env.mailbox,s)>=0&&a.command("checkmail")),i||setTimeout((function(){window.close()}),1e3)}else i||setTimeout((function(){ref.list_mailbox()}),500);i&&(this.env.is_sent=!0)},this.ksearch_keydown=function(e,t,s){this.ksearch_timer&&clearTimeout(this.ksearch_timer);var i=rcube_event.get_keycode(e);switch(i){case 38:case 40:if(!this.ksearch_visible())return;var n=38==i?1:0,a=document.getElementById("rcmkSearchItem"+this.ksearch_selected);return a||(a=this.ksearch_pane.__ul.firstChild),a&&this.ksearch_select(n?a.previousSibling:a.nextSibling),rcube_event.cancel(e);case 9:if(rcube_event.get_modifier(e)==SHIFT_KEY||!this.ksearch_visible())return void this.ksearch_hide();case 13:return!!this.ksearch_visible()&&(this.insert_recipient(this.ksearch_selected),this.ksearch_hide(),9==i?null:rcube_event.cancel(e));case 27:return void this.ksearch_hide();case 37:case 39:return}return this.ksearch_timer=setTimeout((function(){ref.ksearch_get_results(s)}),200),this.ksearch_input=t,!0},this.ksearch_visible=function(){return null!==this.ksearch_selected&&void 0!==this.ksearch_selected&&this.ksearch_value},this.ksearch_select=function(e){this.ksearch_pane&&e&&this.ksearch_pane.find("li.selected").removeClass("selected").removeAttr("aria-selected"),e&&($(e).addClass("selected").attr("aria-selected","true"),this.ksearch_selected=e._rcm_id,$(this.ksearch_input).attr("aria-activedescendant","rcmkSearchItem"+this.ksearch_selected))},this.insert_recipient=function(e){if(null!==e&&this.env.contacts[e]&&this.ksearch_input){var t=this.ksearch_input.value,s=this.get_caret_pos(this.ksearch_input),i=t.lastIndexOf(this.ksearch_value,s),n=!1,a="",r=t.substring(0,i),o=t.substring(i+this.ksearch_value.length,t.length);this.ksearch_destroy(),"object"!=typeof this.env.contacts[e]||"group"!=this.env.contacts[e].type||this.env.contacts[e].email?"object"==typeof this.env.contacts[e]&&this.env.contacts[e].name?(a=this.env.contacts[e].name+this.env.recipients_delimiter,n=!0):"string"==typeof this.env.contacts[e]&&(a=this.env.contacts[e]+this.env.recipients_delimiter,n=!0):(a+=this.env.contacts[e].name+this.env.recipients_delimiter,this.group2expand[this.env.contacts[e].id]=$.extend({input:this.ksearch_input},this.env.contacts[e]),this.http_request("mail/group-expand",{_source:this.env.contacts[e].source,_gid:this.env.contacts[e].id},!1)),this.ksearch_input.value=r+a+o,this.set_caret_pos(this.ksearch_input,i+a.length),n&&(this.triggerEvent("autocomplete_insert",{field:this.ksearch_input,insert:a,data:this.env.contacts[e],search:this.ksearch_value_last,result_type:"person"}),this.ksearch_value_last=null,this.compose_type_activity++)}},this.replace_group_recipients=function(e,t){this.group2expand[e]&&(this.group2expand[e].input.value=this.group2expand[e].input.value.replace(this.group2expand[e].name,t),this.triggerEvent("autocomplete_insert",{field:this.group2expand[e].input,insert:t,data:this.group2expand[e],search:this.ksearch_value_last,result_type:"group"}),this.ksearch_value_last=null,this.group2expand[e]=null,this.compose_type_activity++)},this.ksearch_get_results=function(e){var t=this.ksearch_input?this.ksearch_input.value:null;if(null!==t){this.ksearch_pane&&this.ksearch_pane.is(":visible")&&this.ksearch_pane.hide();var s=this.get_caret_pos(this.ksearch_input),i=t.lastIndexOf(this.env.recipients_separator,s-1),n=t.substring(i+1,s),a=this.env.autocomplete_min_length,r=this.ksearch_data;if((n=$.trim(n))!=this.ksearch_value)if(this.ksearch_destroy(),n.length&&n.length<a)this.ksearch_info||(this.ksearch_info=this.display_message(this.get_label("autocompletechars").replace("$min",a)));else{var o=this.ksearch_value;if(this.ksearch_value=n,this.ksearch_value_last=n,n.length&&(!(o&&o.length&&n.startsWith(o)&&(!r||r.num<=0)&&this.env.contacts)||this.env.contacts.length)){var l=e&&e.sources?e.sources:[""],c=this.multi_thread_http_request({items:l,threads:e&&e.threads?e.threads:1,action:e&&e.action?e.action:"mail/autocomplete",postdata:{_search:n,_source:"%s"},lock:this.display_message(this.get_label("searching"),"loading")});this.ksearch_data={id:c,sources:l.slice(),num:l.length}}}}},this.ksearch_query_results=function(e,t,s){if(this.multi_thread_http_response(e,s),this.ksearch_value&&(!this.ksearch_input||t==this.ksearch_value)){var i,n,a,r,o,l,c=this.ksearch_value,h=this.env.autocomplete_max?this.env.autocomplete_max:15;if(this.ksearch_pane||(r=$("<ul>"),this.ksearch_pane=$("<div>").attr("id","rcmKSearchpane").attr("role","listbox").css({position:"absolute","z-index":3e4}).append(r).appendTo(document.body),this.ksearch_pane.__ul=r[0]),r=this.ksearch_pane.__ul,s&&this.ksearch_pane.data("reqid")==s)h-=r.childNodes.length;else{this.ksearch_pane.data("reqid",s),1,r.innerHTML="",this.env.contacts=[];var d=$(this.ksearch_input).offset();this.ksearch_pane.css({left:d.left+"px",top:d.top+this.ksearch_input.offsetHeight+"px",display:"none"})}if(e&&(a=e.length))for(i=0;i<a&&h>0;i++)o="object"==typeof e[i]?e[i].display||e[i].name:e[i],l="object"==typeof e[i]?e[i].type:"",n=i+this.env.contacts.length,$("<li>").attr("id","rcmkSearchItem"+n).attr("role","option").html('<i class="icon"></i>'+this.quote_html(o.replace(new RegExp("("+RegExp.escape(c)+")","ig"),"##$1%%")).replace(/##([^%]+)%%/g,"<b>$1</b>")).addClass(l||"").appendTo(r).mouseover((function(){ref.ksearch_select(this)})).mouseup((function(){ref.ksearch_click(this)})).get(0)._rcm_id=n,h-=1;r.childNodes.length&&($(this.ksearch_input).attr("aria-haspopup","true").attr("aria-expanded","true").attr("aria-owns","rcmKSearchpane"),this.ksearch_pane.show(),this.env.contacts.length||this.ksearch_select($("li:first",r).get(0))),a&&(this.env.contacts=this.env.contacts.concat(e)),this.ksearch_data.id==s&&this.ksearch_data.num--}},this.ksearch_click=function(e){this.ksearch_input&&this.ksearch_input.focus(),this.insert_recipient(e._rcm_id),this.ksearch_hide()},this.ksearch_blur=function(){this.ksearch_timer&&clearTimeout(this.ksearch_timer),this.ksearch_input=null,this.ksearch_hide()},this.ksearch_hide=function(){this.ksearch_selected=null,this.ksearch_value="",this.ksearch_pane&&this.ksearch_pane.hide(),$(this.ksearch_input).attr("aria-haspopup","false").attr("aria-expanded","false").removeAttr("aria-activedescendant").removeAttr("aria-owns"),this.ksearch_destroy()},this.ksearch_destroy=function(){this.ksearch_data&&this.multi_thread_request_abort(this.ksearch_data.id),this.ksearch_info&&this.hide_message(this.ksearch_info),this.ksearch_msg&&this.hide_message(this.ksearch_msg),this.ksearch_data=null,this.ksearch_info=null,this.ksearch_msg=null},this.contactlist_keypress=function(e){e.key_pressed==e.DELETE_KEY&&this.command("delete")},this.contactlist_select=function(e){this.preview_timer&&clearTimeout(this.preview_timer);var t,s,i,n,a=!1,r=e.selection.length,o=this.env.source?this.env.address_sources[this.env.source]:null;if(this.env.contentframe&&!e.multi_selecting&&(s=e.get_single_selection())?this.preview_timer=setTimeout((function(){ref.load_contact(s,"show")}),this.preview_delay_click):this.env.contentframe&&this.show_contentframe(!1),r){for(t in e.draggable=!1,this.env.selection_sources=[],o&&this.env.selection_sources.push(this.env.source),e.selection)n=e.data[e.selection[t]],o?a=a||!o.readonly&&!n.readonly:(i=String(e.selection[t]).replace(/^[^-]+-/,""))&&this.env.address_sources[i]&&(a=a||!this.env.address_sources[i].readonly&&!n.readonly,this.env.selection_sources.push(i)),"group"!=n._type&&(e.draggable=!0);this.env.selection_sources=$.unique(this.env.selection_sources)}return this.enable_command("group-remove-selected",this.env.group&&r&&a),this.enable_command("compose",this.env.group||r),this.enable_command("print",1==r),this.enable_command("export-selected","copy",r>0),this.enable_command("edit",s&&a),this.enable_command("delete","move",r&&a),!1},this.list_contacts=function(e,t,s,i){var n,a,r=-1,o={},l=void 0===e&&void 0===t&&void 0===s,c=window;e||(e=this.env.source),l&&(t=this.env.group),e!=this.env.source?(s=this.env.current_page=1,this.reset_qsearch()):l||t==this.env.group||(s=this.env.current_page=1),this.env.search_id?a="S"+this.env.search_id:this.env.search_request||(a=t?"G"+e+t:e),this.env.source=e,this.env.group=t,$.each(this.env.address_group_stack,(function(e,t){if(ref.env.group==t.id)return r=e,!1})),this.env.address_group_stack=r<0?[]:this.env.address_group_stack.slice(0,r),this.env.group?(i||(i={}),i.id=this.env.group,this.env.address_group_stack.push(i),a="G"+e+this.env.address_group_stack[0].id):this.gui_objects.addresslist_title&&$(this.gui_objects.addresslist_title).text(this.get_label("contacts")),this.env.search_id||this.select_folder(a,"",!0),this.gui_objects.contactslist?this.list_contacts_remote(e,t,s):((n=this.get_frame_window(this.env.contentframe))&&(c=n,o._framed=1),t&&(o._gid=t),s&&(o._page=s),e&&(o._source=e),this.env.search_request&&(o._search=this.env.search_request),this.set_busy(!0,"loading"),this.location_href(o,c))},this.list_contacts_remote=function(e,t,s){this.list_contacts_clear();var i={},n=this.set_busy(!0,"loading");e&&(i._source=e),s&&(i._page=s),t&&(i._gid=t),this.env.source=e,this.env.group=t,this.env.search_request&&(i._search=this.env.search_request),this.http_request("mail"==this.env.task?"list-contacts":"list",i,n),"mail"!=this.env.task&&this.update_state({_source:e,_page:s&&s>1?s:null,_gid:t})},this.list_contacts_clear=function(){this.contact_list.data={},this.contact_list.clear(!0),this.show_contentframe(!1),this.enable_command("delete","move","copy","print",!1),this.enable_command("compose",this.env.group)},this.set_group_prop=function(e){if(this.gui_objects.addresslist_title){var t=$(this.gui_objects.addresslist_title).html("");(this.env.address_group_stack.length>1||1==this.env.address_group_stack.length&&this.env.address_group_stack[0].search_request)&&($('<a href="#list">...</a>').attr("title",this.get_label("uponelevel")).addClass("poplink").appendTo(t).click((function(e){return ref.command("popgroup","",this)})),t.append("&nbsp;&raquo;&nbsp;")),t.append($("<span>").text(e?e.name:this.get_label("contacts")))}},this.load_contact=function(e,t,s){var i,n={},a=window,r=this.contact_list?this.contact_list.data[e]:null;if(i=this.get_frame_window(this.env.contentframe))n._framed=1,a=i,this.show_contentframe(!0),e||this.contact_list.clear_selection(),this.enable_command("compose",r&&r.email),this.enable_command("export-selected","print",r&&"group"!=r._type);else if(s)return!1;return!t||!e&&"add"!=t||this.drag_active||(this.env.group&&(n._gid=this.env.group),this.env.search_request&&(n._search=this.env.search_request),n._action=t,n._source=this.env.source,n._cid=e,this.location_href(n,a,!0)),!0},this.group_member_change=function(e,t,s,i){"add"!=e&&(e="del");var n=this.get_label("add"==e?"addingmember":"removingmember"),a=this.display_message(n,"loading"),r={_cid:t,_source:s,_gid:i};this.http_post("group-"+e+"members",r,a)},this.contacts_drag_menu=function(e,t){var s="group"==t.type?t.source:t.id,i=this.env.source;if(!this.env.address_sources[s]||this.env.address_sources[s].readonly)return!0;if(""==i&&1==this.env.selection_sources.length&&(i=this.env.selection_sources[0]),"group"==t.type&&s==i){var n=this.contact_list.get_selection().join(",");return this.group_member_change("add",n,s,t.id),!0}return this.commands.move||rcube_event.get_modifier(e)==SHIFT_KEY?this.drag_menu(e,t):(this.copy_contacts(t),!0)},this.copy_contacts=function(e){var t="group"==e.type?e.source:e.id,s=this.env.source,i=this.env.group?this.env.group:"",n=this.contact_list.get_selection().join(",");if(n&&this.env.address_sources[t]&&!this.env.address_sources[t].readonly)if(""==s&&1==this.env.selection_sources.length&&(s=this.env.selection_sources[0]),"group"==e.type){if(t==s)return;var a=this.display_message(this.get_label("copyingcontact"),"loading"),r={_cid:n,_source:this.env.source,_to:t,_togid:e.id,_gid:i};this.http_post("copy",r,a)}else if(e.id!=s){a=this.display_message(this.get_label("copyingcontact"),"loading"),r={_cid:n,_source:this.env.source,_to:e.id,_gid:i};this.http_post("copy",r,a)}},this.move_contacts=function(e){var t="group"==e.type?e.source:e.id,s=this.env.source;this.env.group&&this.env.group;if(this.env.address_sources[t]&&!this.env.address_sources[t].readonly)if(""==s&&1==this.env.selection_sources.length&&(s=this.env.selection_sources[0]),"group"==e.type){if(t==s)return;this._with_selected_contacts("move",{_to:t,_togid:e.id})}else e.id!=s&&this._with_selected_contacts("move",{_to:e.id})},this.delete_contacts=function(){if(this.env.source&&this.env.address_sources[this.env.source].undelete||confirm(this.get_label("deletecontactconfirm")))return this._with_selected_contacts("delete")},this._with_selected_contacts=function(e,t){var s=this.contact_list?this.contact_list.get_selection():[];if(s.length||this.env.cid){var i,n=[],a="delete"==e?"contactdeleting":"movingcontact",r=this.display_message(this.get_label(a),"loading");if(this.env.cid)n.push(this.env.cid);else{for(i=0;i<s.length;i++)id=s[i],n.push(id),this.contact_list.remove_row(id,i==s.length-1);1==s.length&&this.show_contentframe(!1)}return t||(t={}),t._source=this.env.source,t._from=this.env.action,t._cid=n.join(","),this.env.group&&(t._gid=this.env.group),this.env.search_request&&(t._search=this.env.search_request),this.http_post(e,t,r),!0}},this.update_contact_row=function(e,t,s,i,n){var a=this.contact_list;e=this.html_identifier(e),a.rows[e]||(e=e+"-"+i,s&&(s=s+"-"+i)),a.update_row(e,t,s,!0),a.data[e]=n},this.add_contact_row=function(e,t,s,i){if(!this.gui_objects.contactslist)return!1;var n,a,r=this.contact_list,o={cols:[]};for(n in o.id="rcmrow"+this.html_identifier(e),o.className="contact "+(s||""),r.in_selection(e)&&(o.className+=" selected"),t)(a={}).className=String(n).toLowerCase(),a.innerHTML=t[n],o.cols.push(a);r.data[e]=i,r.insert_row(o),this.enable_command("export",r.rowcount>0)},this.init_contact_form=function(){var e;if(this.env.coltypes)for(e in this.set_photo_actions($("#ff_photo").val()),this.env.coltypes)this.init_edit_field(e,null);$(".contactfieldgroup .row a.deletebutton").click((function(){return ref.delete_edit_field(this),!1})),$("select.addfieldmenu").change((function(){ref.insert_edit_field($(this).val(),$(this).attr("rel"),this),this.selectedIndex=0})),$.datepicker&&this.env.date_format&&($.datepicker.setDefaults({dateFormat:this.env.date_format,changeMonth:!0,changeYear:!0,yearRange:"-120:+10",showOtherMonths:!0,selectOtherMonths:!0}),$("input.datepicker").datepicker()),"search"==this.env.action&&$(this.gui_objects.editform).append($('<input type="submit">').hide()).submit((function(){return $("input.mainaction").click(),!1}))},this.group_create=function(){var e=$("<input>").attr("type","text"),t=$("<label>").text(this.get_label("namex")).append(e),s=this.env.source;this.simple_dialog(t,"newgroup",(function(){var t;if(t=e.val())return ref.http_post("group-create",{_source:s,_name:t},ref.set_busy(!0,"loading")),!0}))},this.group_rename=function(){if(this.env.group){var e=this.env.contactgroups["G"+this.env.source+this.env.group].name,t=$("<input>").attr("type","text").val(e),s=$("<label>").text(this.get_label("namex")).append(t),i=this.env.source,n=this.env.group;this.simple_dialog(s,"grouprename",(function(){var s;if((s=t.val())&&s!=e)return ref.http_post("group-rename",{_source:i,_gid:n,_name:s},ref.set_busy(!0,"loading")),!0}),{open:function(){t.select()}})}},this.group_delete=function(){if(this.env.group&&confirm(this.get_label("deletegroupconfirm"))){var e=this.set_busy(!0,"groupdeleting");this.http_post("group-delete",{_source:this.env.source,_gid:this.env.group},e)}},this.remove_group_item=function(e){var t="G"+e.source+e.id;this.treelist.remove(t)&&(this.triggerEvent("group_delete",{source:e.source,id:e.id}),delete this.env.contactfolders[t],delete this.env.contactgroups[t]),e.source==this.env.source&&e.id==this.env.group&&this.list_contacts(e.source,0)},this.group_remove_selected=function(){this.http_post("group-delmembers",{_cid:this.contact_list.selection,_source:this.env.source,_gid:this.env.group})},this.remove_group_contacts=function(e){if(void 0!==this.env.group&&this.env.group===e.gid){var t,s=this.contact_list.get_selection();for(t=0;t<s.length;t++)id=s[t],this.contact_list.remove_row(id,t==s.length-1)}},this.insert_contact_group=function(e){e.type="group";var t="G"+e.source+e.id,s=$("<a>").attr("href","#").attr("rel",e.source+":"+e.id).click((function(){return ref.command("listgroup",e,this)})).html(e.name);this.env.contactfolders[t]=this.env.contactgroups[t]=e,this.treelist.insert({id:t,html:s,classes:["contactgroup"]},e.source,"contactgroup"),this.triggerEvent("group_insert",{id:e.id,source:e.source,name:e.name,li:this.treelist.get_item(t)})},this.update_contact_group=function(e){var t="G"+e.source+e.id,s={};if(e.newid){var i="G"+e.source+e.newid,n=$.extend({},e);this.env.contactfolders[i]=this.env.contactfolders[t],this.env.contactfolders[i].id=e.newid,this.env.group=e.newid,delete this.env.contactfolders[t],delete this.env.contactgroups[t],n.id=e.newid,n.type="group",s.id=i,s.html=$("<a>").attr("href","#").attr("rel",e.source+":"+e.newid).click((function(){return ref.command("listgroup",n,this)})).html(e.name)}else $(this.treelist.get_item(t)).children().first().html(e.name),this.env.contactfolders[t].name=this.env.contactgroups[t].name=e.name,e.source==this.env.source&&e.id==this.env.group&&this.set_group_prop(e);this.treelist.update(t,s,!0),this.triggerEvent("group_update",{id:e.id,source:e.source,name:e.name,li:this.treelist.get_item(t),newid:e.newid})},this.update_group_commands=function(){var e=""!=this.env.source?this.env.address_sources[this.env.source]:null,t=e&&e.groups&&!e.readonly;this.enable_command("group-create",t),this.enable_command("group-rename","group-delete",t&&this.env.group)},this.init_edit_field=function(e,t){var s=this.env.coltypes[e].label;t||(t=$(".ff_"+e)),s&&t.placeholder(s)},this.insert_edit_field=function(e,t,s){var i=$("#ff_"+e);if(i.length)i.show().focus(),$(s).children('option[value="'+e+'"]').prop("disabled",!0);else{$(".ff_"+e);var n=$("#contactsection"+t+" .contactcontroller"+e);if(!n.length){var a=$("#contactsection"+t),r=$(".contactfieldgroup",a).last();n=$("<fieldset>").addClass("contactfieldgroup contactcontroller"+e),r.length?n.insertAfter(r):a.prepend(n)}if(n.length&&"FIELDSET"==n.get(0).nodeName){var o,l=this.env.coltypes[e],c="ff_"+e+(l.count||0),h=$("<div>").addClass("row"),d=$("<div>").addClass("contactfieldcontent data"),_=$("<div>").addClass("contactfieldlabel label");l.subtypes_select?_.html(l.subtypes_select):_.html('<label for="'+c+'">'+l.label+"</label>");var u=1!=l.limit?"[]":"";if("text"==l.type||"date"==l.type)o=$("<input>").addClass("ff_"+e).attr({type:"text",name:"_"+e+u,size:l.size,id:c}).appendTo(d),this.init_edit_field(e,o),"date"==l.type&&$.datepicker&&o.datepicker();else if("textarea"==l.type)o=$("<textarea>").addClass("ff_"+e).attr({name:"_"+e+u,cols:l.size,rows:l.rows,id:c}).appendTo(d),this.init_edit_field(e,o);else if("composite"==l.type){var m,p,f,g,v,b=[],w=[];if(v=this.env[e+"_template"])for(m=0;m<v.length;m++)b.push(v[m][1]),w.push(v[m][2]);else for(p in l.childs)b.push(p);for(m=0;m<b.length;m++)p=b[m],f=l.childs[p],o=$("<input>").addClass("ff_"+p).attr({type:"text",name:"_"+p+u,size:f.size}).appendTo(d),d.append(w[m]||" "),this.init_edit_field(p,o),g||(g=o);o=g}else if("select"==l.type){var y=(o=$("<select>").addClass("ff_"+e).attr({name:"_"+e+u,id:c}).appendTo(d)).attr("options");y[y.length]=new Option("---",""),l.options&&$.each(l.options,(function(e,t){y[y.length]=new Option(t,e)}))}if(o){$('<a href="#del"></a>').addClass("contactfieldbutton deletebutton").attr({title:this.get_label("delete"),rel:e}).html(this.env.delbutton).click((function(){return ref.delete_edit_field(this),!1})).appendTo(d);h.append(_).append(d).appendTo(n.show()),o.first().focus(),l.count||(l.count=0),++l.count==l.limit&&l.limit&&$(s).children('option[value="'+e+'"]').prop("disabled",!0)}}}},this.delete_edit_field=function(e){var t=$(e).attr("rel"),s=this.env.coltypes[t],i=$(e).parents("fieldset.contactfieldgroup"),n=i.parent().find("select.addfieldmenu");if(--s.count<=0&&s.visible?$(e).parent().children("input").val("").blur():($(e).parents("div.row").remove(),i.children("div.row").length||i.hide()),n.length){var a=n.children('option[value="'+t+'"]');a.length?a.prop("disabled",!1):a=$("<option>").attr("value",t).html(s.label).appendTo(n),n.show()}},this.upload_contact_photo=function(e){e&&e.elements._photo.value&&(this.async_upload_form(e,"upload-photo",(function(e){ref.set_busy(!1,null,ref.file_upload_id)})),this.file_upload_id=this.set_busy(!0,"uploading"))},this.replace_contact_photo=function(e){var t="-del-"==e?this.env.photo_placeholder:this.env.comm_path+"&_action=photo&_source="+this.env.source+"&_cid="+(this.env.cid||0)+"&_photo="+e;this.set_photo_actions(e),$(this.gui_objects.contactphoto).children("img").attr("src",t)},this.photo_upload_end=function(){this.set_busy(!1,null,this.file_upload_id),delete this.file_upload_id},this.set_photo_actions=function(e){var t,s=this.buttons["upload-photo"];for(t=0;s&&t<s.length;t++)$("a#"+s[t].id).html(this.get_label("-del-"==e?"addphoto":"replacephoto"));$("#ff_photo").val(e),this.enable_command("upload-photo",!!this.env.coltypes.photo),this.enable_command("delete-photo",this.env.coltypes.photo&&"-del-"!=e)},this.advanced_search=function(){var e,t={_form:1,_action:"search"},s=window;return(e=this.get_frame_window(this.env.contentframe))&&(t._framed=1,s=e,this.contact_list.clear_selection()),this.location_href(t,s,!0),!0},this.unselect_directory=function(){this.select_folder(""),this.enable_command("search-delete",!1)},this.insert_saved_search=function(e,t){var s="S"+t,i=$("<a>").attr("href","#").attr("rel",t).click((function(){return ref.command("listsearch",t,this)})).html(e),n={name:e,id:t};this.savedsearchlist.insert({id:s,html:i,classes:["contactsearch"]},null,"contactsearch"),this.select_folder(s,"",!0),this.enable_command("search-delete",!0),this.env.search_id=t,this.triggerEvent("abook_search_insert",n)},this.search_create=function(){var e=$("<input>").attr("type","text"),t=$("<label>").text(this.get_label("namex")).append(e);this.simple_dialog(t,"searchsave",(function(){var t;if(t=e.val())return ref.http_post("search-create",{_search:ref.env.search_request,_name:t},ref.set_busy(!0,"loading")),!0}))},this.search_delete=function(){if(this.env.search_request){var e=this.set_busy(!0,"savedsearchdeleting");this.http_post("search-delete",{_sid:this.env.search_id},e)}},this.remove_search_item=function(e){var t="S"+e;this.savedsearchlist.remove(t)&&this.triggerEvent("search_delete",{id:e,li:void 0}),this.env.search_id=null,this.env.search_request=null,this.list_contacts_clear(),this.reset_qsearch(),this.enable_command("search-delete","search-create",!1)},this.listsearch=function(e){var t=this.set_busy(!0,"searching");this.contact_list&&this.list_contacts_clear(),this.reset_qsearch(),this.savedsearchlist?(this.treelist.select(""),this.savedsearchlist.select("S"+e)):this.select_folder("S"+e,"",!0),this.env.current_page=1,this.http_request("search",{_sid:e},t)},this.qrcode=function(){var e=this.get_label("qrcode"),t=[{text:this.get_label("close"),class:"mainaction",click:function(){(ref.is_framed()?parent.$:$)(this).dialog("destroy")}}],s=new Image(300,300);return s.src=this.url("addressbook/qrcode",{_source:this.env.source,_cid:this.env.cid}),this.show_popup_dialog(s,e,t,{width:310,height:410})},this.section_select=function(e){var t,s=e.get_single_selection(),i=window,n={_action:"edit-prefs",_section:s};return s&&((t=this.get_frame_window(this.env.contentframe))&&(n._framed=1,i=t),this.location_href(n,i,!0)),!0},this.identity_select=function(e){var t;(t=e.get_single_selection())&&(this.enable_command("delete",e.rowcount>1&&this.env.identities_level<2),this.load_identity(t,"edit-identity"))},this.load_identity=function(e,t){if("edit-identity"==t&&(!e||e==this.env.iid))return!1;var s,i=window,n={_action:t,_iid:e};return(s=this.get_frame_window(this.env.contentframe))&&(n._framed=1,i=s),(e||"add-identity"==t)&&this.location_href(n,i,!0),!0},this.delete_identity=function(e){var t=this.identity_list.get_selection();(t.length||this.env.iid)&&(e||(e=this.env.iid?this.env.iid:t[0]),e&&confirm(this.get_label("deleteidentityconfirm"))&&this.http_post("settings/delete-identity",{_iid:e},!0))},this.update_identity_row=function(e,t,s){var i=this.identity_list,n=this.html_identifier(e);s?(i.insert_row({id:"rcmrow"+n,cols:[{className:"mail",innerHTML:t}]}),i.select(n)):i.update_row(n,[t])},this.update_response_row=function(e,t){var s=this.responses_list;s&&t?s.update_row(t,[e.name],e.key,!0):s&&(s.insert_row({id:"rcmrow"+e.key,cols:[{className:"name",innerHTML:e.name}]}),s.select(e.key))},this.remove_response=function(e){var t;this.env.textresponses&&delete this.env.textresponses[e],this.responses_list&&(this.responses_list.remove_row(e),(t=this.get_frame_window(this.env.contentframe))&&(t.location.href=this.env.blankpage)),this.enable_command("delete",!1)},this.remove_identity=function(e){var t,s=this.identity_list,i=this.html_identifier(e);s&&e&&(s.remove_row(i),(t=this.get_frame_window(this.env.contentframe))&&(t.location.href=this.env.blankpage)),this.enable_command("delete",!1)},this.init_subscription_list=function(){var e=RegExp.escape(this.env.delimiter);this.last_sub_rx=RegExp("["+e+"]?[^"+e+"]+$"),this.subscription_list=new rcube_treelist_widget(this.gui_objects.subscriptionlist,{selectable:!0,tabexit:!1,parent_focus:!0,id_prefix:"rcmli",id_encode:this.html_identifier_encode,id_decode:this.html_identifier_decode,searchbox:"#foldersearch"}),this.subscription_list.addEventListener("select",(function(e){ref.subscription_select(e.id)})).addEventListener("collapse",(function(e){ref.folder_collapsed(e)})).addEventListener("expand",(function(e){ref.folder_collapsed(e)})).addEventListener("search",(function(e){e.query&&ref.subscription_select()})).draggable({cancel:"li.mailbox.root,input,div.treetoggle"}).droppable({accept:function(e){if(!$(e).is(".mailbox"))return!1;var t=ref.folder_id2name($(e).attr("id")),s=ref.folder_id2name(this.id),i=ref.env.subscriptionrows[t];ref.env.subscriptionrows[s];return i&&!i[2]&&s!=t.replace(ref.last_sub_rx,"")&&!s.startsWith(t+ref.env.delimiter)},drop:function(e,t){var s=ref.folder_id2name(t.draggable.attr("id")),i=ref.folder_id2name(this.id);ref.subscription_move_folder(s,i)}})},this.folder_id2name=function(e){return e?ref.html_identifier_decode(e.replace(/^rcmli/,"")):null},this.subscription_select=function(e){var t;e&&"*"!=e&&(t=this.env.subscriptionrows[e])?(this.env.mailbox=e,this.show_folder(e),this.enable_command("delete-folder",!t[2])):(this.env.mailbox=null,this.show_contentframe(!1),this.enable_command("delete-folder","purge",!1))},this.subscription_move_folder=function(e,t){if(e&&null!==t&&e!=t&&t!=e.replace(this.last_sub_rx,"")){var s=e.split(this.env.delimiter).pop(),i=""===t||"*"===t?s:t+this.env.delimiter+s;i!=e&&this.http_post("rename-folder",{_folder_oldname:e,_folder_newname:i},this.set_busy(!0,"foldermoving"))}},this.create_folder=function(){this.show_folder("",this.env.mailbox)},this.delete_folder=function(e){e||(e=this.env.mailbox),e&&confirm(this.get_label("deletefolderconfirm"))&&this.http_post("delete-folder",{_mbox:e},this.set_busy(!0,"folderdeleting"))},this.add_folder_row=function(e,t,s,i,n,a,r,o){if(!this.gui_objects.subscriptionlist)return!1;this.subscription_list.is_search()&&(this.subscription_select(),this.subscription_list.reset_search()),this.subscription_list.draggable("destroy").droppable("destroy");var l,c,h,d,_,u,m,p,f="",g=[],v=[],b=[],w=$(this.gui_objects.subscriptionlist);if(!(l=r||$($("li",w).get(1)).clone(!0)).length)return this.goto_url("folders"),!1;l.attr({id:"rcmli"+this.html_identifier_encode(e),class:a}),r&&r.length||($("ul,div.treetoggle",l).remove(),l.removeData("filtered")),$("a:first",l).text(s),$('input[name="_subscribed[]"]:first',l).val(e).prop({checked:!!n,disabled:!!i}),this.env.subscriptionrows[e]=[t,s,!1],$.each(this.env.subscriptionrows,(function(e,t){t[3]=e,g.push(t)}));try{u=new Intl.Collator(this.env.locale.replace("_","-"))}catch(e){}for(c in g.sort((function(e,t){var s,i,n,a=e[0].split(ref.env.delimiter),r=t[0].split(ref.env.delimiter),o=a.length;for(s=0;s<o;s++){if((i=a[s])!==(n=r[s]))return void 0===n?1:u?u.compare(i,n):i<n?-1:1;if(s==o-1)return-1}})),g)if(p=g[c][3],g[c][2]){if((d=p+this.env.delimiter)==this.env.prefix_ns)continue;b.push(p),h=d}else h&&p.startsWith(h)?b.push(p):(v.push(p),h=null);for(c=0;c<b.length;c++)e.startsWith(b[c]+this.env.delimiter)&&(_=b[c]);for(c=0;!_&&c<v.length;c++)c&&v[c]==e&&(_=v[c-1]);if(_&&(c=this.subscription_list.get_item(_,!0)))if((m=e.lastIndexOf(this.env.delimiter))&&(f=e.substring(0,m),f=this.subscription_list.get_item(f,!0),$("div.treetoggle",f).length||$("<div>&nbsp;</div>").addClass("treetoggle collapsed").appendTo(f),$("ul",f).length||$("<ul>").css("display","none").appendTo(f)),f&&c==f)$("ul:first",f).append(l);else{for(;(p=$(c).parent().parent().get(0))&&(!f||p!=f)&&$(p).is("li.mailbox");)c=p;$(c).after(l)}else w.append(l);return $.extend(this.env.subscriptionrows,o||{}),this.subscription_list.reset(!0),this.subscription_select(),f&&this.subscription_list.expand(this.folder_id2name(f.id)),(l=l.show().get(0)).scrollIntoView&&l.scrollIntoView(),l},this.replace_folder_row=function(e,t,s,i,n,a){if(!this.gui_objects.subscriptionlist)return!!this.is_framed()&&window.parent.rcmail.replace_folder_row(e,t,s,i,n,a);this.subscription_list.is_search()&&(this.subscription_select(),this.subscription_list.reset_search());var r={},o=this.subscription_list.get_item(e,!0),l=$(o).parent(),c=this.env.subscriptionrows[e],h=e.length,d=c[0].length,_=$('input[name="_subscribed[]"]:first',o).prop("checked");e!=t?($("li",o).each((function(){var e=ref.folder_id2name(this.id),i=ref.env.subscriptionrows[e],n=t+e.slice(h);this.id="rcmli"+ref.html_identifier_encode(n),$('input[name="_subscribed[]"]:first',this).val(n),i[0]=s+i[0].slice(d),r[n]=i,delete ref.env.subscriptionrows[e]})),o=$(o).detach(),delete this.env.subscriptionrows[e],l.get(0)==this.gui_objects.subscriptionlist||$("li",l).length||$("ul,div.treetoggle",l.parent()).remove(),this.add_folder_row(t,s,i,n,_,a,o,r)):$(o).attr("class",a||"")},this.remove_folder_row=function(e){this.subscription_list.is_search()&&(this.subscription_select(),this.subscription_list.reset_search());var t=[],s=this.subscription_list.get_item(e,!0);$("li",s).each((function(){t.push(ref.folder_id2name(this.id))})),this.subscription_list.remove(e),t.push(e),$.each(t,(function(e,t){delete ref.env.subscriptionrows[t]}))},this.subscribe=function(e){if(e){var t=this.display_message(this.get_label("foldersubscribing"),"loading");this.http_post("subscribe",{_mbox:e},t)}},this.unsubscribe=function(e){if(e){var t=this.display_message(this.get_label("folderunsubscribing"),"loading");this.http_post("unsubscribe",{_mbox:e},t)}},this.show_folder=function(e,t,s){var i,n=window,a="&_action=edit-folder&_mbox="+urlencode(e);t&&(a+="&_path="+urlencode(t)),(i=this.get_frame_window(this.env.contentframe))&&(n=i,a+="&_framed=1"),String(n.location.href).indexOf(a)>=0&&!s?this.show_contentframe(!0):this.location_href(this.env.comm_path+a,n,!0)},this.disable_subscription=function(e){var t=this.subscription_list.get_item(e,!0);t&&$('input[name="_subscribed[]"]:first',t).prop("disabled",!0)},this.reset_subscription=function(e,t){var s=this.subscription_list.get_item(e,!0);s&&$('input[name="_subscribed[]"]:first',s).prop("checked",t)},this.folder_size=function(e){var t=this.set_busy(!0,"loading");this.http_post("folder-size",{_mbox:e},t)},this.folder_size_update=function(e){$("#folder-size").replaceWith(e)},this.folder_filter=function(e){this.subscription_list.reset_search(),this.subscription_list.container.children("li").each((function(){var t,s=ref.folder_id2name(this.id);if("---"==e);else if(e){if(s!==e)return void $(this).data("filtered",!0).hide()}else for(t in ref.env.ns_roots)if(s===ref.env.ns_roots[t])return void $(this).data("filtered",!0).hide();$(this).removeData("filtered").show()}))};var init_button=function(e,t){var s=document.getElementById(t.id);if(s){var i=!1;"image"==t.type&&(s=s.parentNode,i=!0),s._command=e,s._id=t.id,t.sel&&(s.onmousedown=function(e){return ref.button_sel(this._command,this._id)},s.onmouseup=function(e){return ref.button_out(this._command,this._id)},i&&((new Image).src=t.sel)),t.over&&(s.onmouseover=function(e){return ref.button_over(this._command,this._id)},s.onmouseout=function(e){return ref.button_out(this._command,this._id)},i&&((new Image).src=t.over))}};this.init_buttons=function(){for(var e in this.buttons)if("string"==typeof e)for(var t=0;t<this.buttons[e].length;t++)init_button(e,this.buttons[e][t])},this.set_button=function(e,t){var s,i,n,a,r=this.buttons[e],o=r?r.length:0;for(s=0;s<o;s++)i=r[s],(n=document.getElementById(i.id))&&i.status!==t&&("image"!=i.type||i.status?i.status||(i.pas=String(n.className)):(i.pas=n._original_src?n._original_src:n.src,n.runtimeStyle&&n.runtimeStyle.filter&&n.runtimeStyle.filter.match(/src=['"]([^'"]+)['"]/)&&(i.pas=RegExp.$1)),i.status=t,"image"==i.type&&i[t]?n.src=i[t]:void 0!==i[t]&&(n.className=i[t]),"input"==i.type?n.disabled="pas"==t:"uibutton"==i.type?(i.status=t,$(n).button("option","disabled","pas"==t)):(a=$(n)).attr("tabindex","pas"==t||"sel"==t?"-1":a.attr("data-tabindex")||"0").attr("aria-disabled","pas"==t||"sel"==t?"true":"false"))},this.set_alttext=function(e,t){var s,i,n,a,r=this.buttons[e],o=r?r.length:0;for(s=0;s<o;s++)i=r[s],n=document.getElementById(i.id),"image"==i.type&&n?(n.setAttribute("alt",this.get_label(t)),(a=n.parentNode)&&"a"==a.tagName.toLowerCase()&&a.setAttribute("title",this.get_label(t))):n&&n.setAttribute("title",this.get_label(t))},this.button_over=function(e,t){this.button_event(e,t,"over")},this.button_sel=function(e,t){this.button_event(e,t,"sel")},this.button_out=function(e,t){this.button_event(e,t,"act")},this.button_event=function(e,t,s){var i,n,a,r=this.buttons[e],o=r?r.length:0;for(i=0;i<o;i++)(n=r[i]).id==t&&"act"==n.status&&(n[s]&&(a=document.getElementById(n.id))&&(a["image"==n.type?"src":"className"]=n[s]),"sel"==s&&(this.buttons_sel[t]=e))},this.set_pagetitle=function(e){e&&document.title&&(document.title=e)},this.display_message=function(e,t,s,i){if(this.is_framed())return parent.rcmail.display_message(e,t,s);if(!this.gui_objects.message)return"loading"!=t&&(this.pending_message=[e,t,s,i]),1;t||(t="notice"),i||(i=this.html_identifier(e));var n=new Date,a=t+n.getTime();if(!s)switch(t){case"error":case"warning":s=2*this.message_time;break;case"uploading":s=0;break;default:s=this.message_time}if("loading"==t&&(i="loading",s=1e3*this.env.request_timeout,e||(e=this.get_label("loading"))),this.messages[i])return this.messages[i].obj&&this.messages[i].obj.html(e),"loading"==t&&this.messages[i].labels.push({id:a,msg:e}),this.messages[i].elements.push(a),setTimeout((function(){ref.hide_message(a,"loading"==t)}),s),a;var r=$("<div>").addClass(t).html(e).data("key",i);$(this.gui_objects.message).append(r).show();return this.messages[i]={obj:r,elements:[a]},"loading"==t?this.messages[i].labels=[{id:a,msg:e}]:"uploading"!=t&&r.click((function(){return ref.hide_message(r)})).attr("role","alert"),this.triggerEvent("message",{message:e,type:t,timeout:s,object:r}),s>0&&setTimeout((function(){ref.hide_message(a,"loading"!=t)}),s),a},this.hide_message=function(e,t){if(this.is_framed())return parent.rcmail.hide_message(e,t);if(this.gui_objects.message){var s,i,n,a,r=this.messages;if("object"==typeof e)s=(a=$(e)).data("key"),this.hide_message_object(a,t),r[s]&&delete r[s];else for(s in r)for(i in r[s].elements)if(r[s]&&r[s].elements[i]==e)if(r[s].elements.splice(i,1),r[s].elements.length){if("loading"==s)for(n in r[s].labels)r[s].labels[n].id==e?delete r[s].labels[n]:(a=r[s].labels[n].msg,r[s].obj.html(a))}else this.hide_message_object(r[s].obj,t),delete r[s]}},this.hide_message_object=function(e,t){t?e.fadeOut(600,(function(){$(this).remove()})):e.hide().remove()},this.clear_messages=function(){if(this.is_framed())return parent.rcmail.clear_messages();var e,t,s=this.messages;for(e in s)for(t in s[e].elements)s[e].obj&&this.hide_message_object(s[e].obj);this.messages={}},this.display_progress=function(e){if(e&&e.name){var t=this.messages["progress"+e.name];e.label||(e.label=this.get_label("uploadingmany")),t?!e.total||e.percent>=100?this.hide_message(t.obj):(e.text&&(e.label+=" "+e.text),t.obj.text(e.label)):(!e.percent||e.percent<100)&&this.display_message(e.label,"uploading",0,"progress"+e.name)}},this.show_popup_dialog=function(e,t,s,i){if(this.is_framed())return parent.rcmail.show_popup_dialog(e,t,s,i);var n=$('<div class="popup">');"object"==typeof e?n.append(e):n.html(e),i=$.extend({title:t,buttons:s,modal:!0,resizable:!0,width:500,close:function(e,t){$(this).remove()}},i||{}),n.dialog(i);var a=$(window),r=a.width(),o=a.height(),l=n.width(),c=n.height();return n.dialog("option",{height:Math.min(o-40,c+75+(s?50:0)),width:Math.min(r-20,l+36)}),$.each(i.button_classes||[],(function(e,t){t&&$($(".ui-dialog-buttonpane button.ui-button",n.parent()).get(e)).addClass(t)})),n},this.simple_dialog=function(e,t,s,i){t=this.get_label(t);var n=[{text:this.get_label((i||{}).button||"save"),class:"mainaction",click:function(){s()&&$(this).dialog("close")}},{text:ref.get_label("cancel"),click:function(){$(this).dialog("close")}}];return this.show_popup_dialog(e,t,n,i)},this.set_page_buttons=function(){this.enable_command("nextpage","lastpage",this.env.pagecount>this.env.current_page),this.enable_command("previouspage","firstpage",this.env.current_page>1),this.update_pagejumper()},this.select_folder=function(e,t,s){this.savedsearchlist&&this.savedsearchlist.select(""),this.treelist?this.treelist.select(e):this.gui_objects.folderlist&&($("li.selected",this.gui_objects.folderlist).removeClass("selected"),$(this.get_folder_li(e,t,s)).addClass("selected"),this.triggerEvent("selectfolder",{folder:e,prefix:t}))},this.mark_folder=function(e,t,s,i){$(this.get_folder_li(e,s,i)).addClass(t),this.triggerEvent("markfolder",{folder:e,mark:t,status:!0})},this.unmark_folder=function(e,t,s,i){$(this.get_folder_li(e,s,i)).removeClass(t),this.triggerEvent("markfolder",{folder:e,mark:t,status:!1})},this.get_folder_li=function(e,t,s){if(t||(t="rcmli"),this.gui_objects.folderlist)return e=this.html_identifier(e,s),document.getElementById(t+e)},this.set_message_coltypes=function(e,t,s){var i,n,a,r,o,l=this.message_list,h=l?l.thead:null;if(this.env.listcols=e,this.env.coltypes||(this.env.coltypes={}),h){if(t){for(h.innerHTML="",o=document.createElement("tr"),c=0,r=t.length;c<r;c++)(i=document.createElement("th")).innerHTML=t[c].html||"",t[c].id&&(i.id=t[c].id),t[c].className&&(i.className=t[c].className),o.appendChild(i);h.appendChild(o)}for(a=0,r=this.env.listcols.length;a<r;a++)n=this.env.listcols[a],!(i=h.rows[0].cells[a])||"from"!=n&&"to"!=n&&"fromto"!=n||$(i).attr("rel",n).find("span,a").text(this.get_label("fromto"==n?s:n))}this.env.subject_col=null,this.env.flagged_col=null,this.env.status_col=null,this.env.coltypes.folder&&(this.env.coltypes.folder.hidden=!(this.env.search_request||this.env.search_id)||"base"==this.env.search_scope),(a=$.inArray("subject",this.env.listcols))>=0&&(this.env.subject_col=a,l&&(l.subject_col=a)),(a=$.inArray("flag",this.env.listcols))>=0&&(this.env.flagged_col=a),(a=$.inArray("status",this.env.listcols))>=0&&(this.env.status_col=a),l&&(l.hide_column("folder",this.env.coltypes.folder&&this.env.coltypes.folder.hidden||$.inArray("folder",this.env.listcols)<0),l.init_header())},this.set_rowcount=function(e,t){if(t&&t!=this.env.mailbox)return!1;$(this.gui_objects.countdisplay).html(e),this.set_page_buttons()},this.set_mailboxname=function(e){this.gui_objects.mailboxname&&e&&(this.gui_objects.mailboxname.innerHTML=e)},this.set_quota=function(e){this.gui_objects.quotadisplay&&e&&"text"==e.type&&$(this.gui_objects.quotadisplay).text((e.percent||0)+"%").attr("title",e.title),this.triggerEvent("setquota",e),this.env.quota_content=e},this.set_trash_count=function(e){this[(e?"un":"")+"mark_folder"](this.env.trash_mailbox,"empty","",!0)},this.set_unread_count=function(e,t,s,i){if(!this.gui_objects.mailboxlist)return!1;this.env.unread_counts[e]=t,this.set_unread_count_display(e,s),i?this.mark_folder(e,i,"",!0):t||this.unmark_folder(e,"recent","",!0),this.mark_all_read_state()},this.set_unread_count_display=function(e,t){var s,i,n,a,r,o,l;if(a=this.get_folder_li(e,"",!0)){if(r=this.env.unread_counts[e]?this.env.unread_counts[e]:0,!(n=(i=$(a).children("a").eq(0)).children("span.unreadcount")).length&&r&&(n=$("<span>").addClass("unreadcount").appendTo(i)),s=/\s+\([0-9]+\)$/i,o=0,(l=a.getElementsByTagName("div")[0])&&l.className.match(/collapsed/))for(var c in this.env.unread_counts)c.startsWith(e+this.env.delimiter)&&(o+=this.env.unread_counts[c]);r&&n.length?n.html(this.env.unreadwrap.replace(/%[sd]/,r)):n.length&&n.remove(),s=new RegExp(RegExp.escape(this.env.delimiter)+"[^"+RegExp.escape(this.env.delimiter)+"]+$"),e.match(s)&&this.set_unread_count_display(e.replace(s,""),!1),r+o>0?$(a).addClass("unread"):$(a).removeClass("unread")}if(s=/^\([0-9]+\)\s+/i,t&&document.title){var h="",d=String(document.title);h=r&&d.match(s)?d.replace(s,"("+r+") "):r?"("+r+") "+d:d.replace(s,""),this.set_pagetitle(h)}},this.set_headers=function(e){this.gui_objects.all_headers_row&&this.gui_objects.all_headers_box&&e&&$(this.gui_objects.all_headers_box).html(e).show()},this.show_headers=function(e,t){this.gui_objects.all_headers_row&&this.gui_objects.all_headers_box&&this.env.uid&&($(t).removeClass("show-headers").addClass("hide-headers"),$(this.gui_objects.all_headers_row).show(),t.onclick=function(){ref.command("hide-headers","",t)},this.gui_objects.all_headers_box.innerHTML||this.http_post("headers",{_uid:this.env.uid,_mbox:this.env.mailbox},this.display_message(this.get_label("loading"),"loading")))},this.hide_headers=function(e,t){this.gui_objects.all_headers_row&&this.gui_objects.all_headers_box&&($(t).removeClass("hide-headers").addClass("show-headers"),$(this.gui_objects.all_headers_row).hide(),t.onclick=function(){ref.command("show-headers","",t)})},this.folder_selector=function(e,t){var s=this.folder_selector_element;if(!s){var i=[],n=this.env.delimiter,a=$('<ul class="toolbarmenu">'),r=document.createElement("a");s=$('<div id="folder-selector" class="popupmenu"></div>'),r.href="#",r.className="icon",$.each(this.env.mailboxes_list,(function(){var e=0,t=0,s=ref.env.mailboxes[this],a=s.id,o=$(r.cloneNode(!1)),l=$("<li>");for(s.virtual?o.addClass("virtual").attr("aria-disabled","true").attr("tabindex","-1"):o.addClass("active").data("id",s.id),s.class&&o.addClass(s.class);(t=a.indexOf(n,t))>=0;)e++,t++;o.css("padding-left",e?16*e+"px":0),o.append($("<span>").text(s.name)),l.append(o),i.push(l)})),a.append(i).appendTo(s),s.css({left:"-1000px",top:"-1000px"}).appendTo($("body")).show(),i.length>10&&s.css("max-height",10*$("li",s)[0].offsetHeight+9),s.on("click","a.active",(function(e){return s.data("callback")($(this).data("id")),!1})),this.folder_selector_element=s}s.data("callback",t),this.show_menu("folder-selector",!0,e)},this.show_menu=function(e,t,s){var i="object"==typeof e?e.menu:e,n=$("#"+i),a=s&&s.target?$(s.target):$(n.attr("rel")||"#"+i+"link"),r=rcube_event.is_keyboard(s),o=n.attr("data-align")||"",l=!1;if("A"!=a.get(0).tagName&&a.closest("a").length&&(a=a.closest("a")),"string"==typeof e&&(e={menu:i}),n.length||(n=this.triggerEvent("menu-get",{name:i,props:e,originalEvent:s})),!n||!n.length)return this.triggerEvent(!1===t?"menu-close":"menu-open",{name:i,props:e,originalEvent:s});if(n.appendTo(document.body),void 0===t&&(t=!n.is(":visible")),t&&a.length){var c=$(window),h=a.offset(),d=o.indexOf("bottom")>=0;l="menuitem"==a.attr("role")||a.closest("[role=menuitem]").length>0,a.offsetWidth=a.outerWidth(),a.offsetHeight=a.outerHeight(),!d&&h.top+a.offsetHeight+n.height()>c.height()&&(d=!0),o.indexOf("right")>=0?h.left=h.left+a.outerWidth()-n.width():l&&(h.left=h.left+a.offsetWidth-5,h.top-=a.offsetHeight),h.left+n.width()>c.width()&&(h.left=c.width()-n.width()-12),h.top=Math.max(0,h.top+(d?-n.height():a.offsetHeight)),n.css({left:h.left+"px",top:h.top+"px"})}if(t){for(var _=this.menu_stack.length-1;l&&_>=0;_--)$(a).parents("#"+this.menu_stack[_]).length||"menuitem"==$(s.target).parent().attr("role")||this.hide_menu(this.menu_stack[_],s);l&&this.menu_stack.length?(n.data("parent",$.last(this.menu_stack)),n.css("z-index",($("#"+$.last(this.menu_stack)).css("z-index")||0)+1)):!l&&this.menu_stack.length&&this.hide_menu(this.menu_stack[0],s),n.show().attr("aria-hidden","false").data("opener",a.attr("aria-expanded","true").get(0)),this.triggerEvent("menu-open",{name:i,obj:n,props:e,originalEvent:s}),this.menu_stack.push(i),this.menu_keyboard_active=t&&r,this.menu_keyboard_active&&(this.focused_menu=i,n.find("a,input:not(:disabled)").not("[aria-disabled=true]").first().focus())}else this.hide_menu(i,s);return t},this.hide_menu=function(e,t){if(this.menu_stack.length){for(var s,i=rcube_event.is_keyboard(t),n=this.menu_stack.length-1;n>=0;n--)s=$("#"+this.menu_stack[n]).hide().attr("aria-hidden","true").data("parent",!1),this.triggerEvent("menu-close",{name:this.menu_stack[n],obj:s,props:{menu:this.menu_stack[n]},originalEvent:t}),this.menu_stack[n]==e&&(n=-1,s.data("opener")&&($(s.data("opener")).attr("aria-expanded","false"),i&&s.data("opener").focus())),this.menu_stack.pop();this.menu_stack.length&&i?(this.menu_keyboard_active=!0,this.focused_menu=$.last(this.menu_stack),s&&s.data("opener")||$("#"+this.focused_menu).find("a,input:not(:disabled)").not("[aria-disabled=true]").first().focus()):(this.focused_menu=null,this.menu_keyboard_active=!1)}else this.triggerEvent("menu-close",{name:e,props:{menu:e},originalEvent:t})},this.element_position=function(e,t){t=$(t);var s=$(window),i=t.outerWidth(),n=t.outerHeight(),a=t.data("menu-pos"),r=s.height(),o=$(e).height(),l=$(e).width(),c=t.offset(),h=c.top,d=c.left+i;"bottom"==a?(h+=n,d-=i):d-=5,h+o>r&&(h-=o-n)<0&&(h=Math.max(0,(r-o)/2)),d+l>s.width()&&(d-=l+i),e.css({left:d+"px",top:h+"px"})},this.editor_init=function(e,t){this.editor=new rcube_text_editor(e,t)},this.html2plain=function(e,t){return this.format_converter(e,"html",t)},this.plain2html=function(e,t){return this.format_converter(e,"plain",t)},this.format_converter=function(e,t,s){if(!e||"html"==t&&!e.replace(/<[^>]+>|&nbsp;|\xC2\xA0|\s/g,"").length||"html"!=t&&!e.replace(/\xC2\xA0|\s/g,"").length)return s&&setTimeout((function(){s("")}),50),!0;var i=this.env.editor_warned||confirm(this.get_label("editorwarning"));if(this.env.editor_warned=!0,!i)return!1;var n="?_task=utils&_action="+("html"==t?"html2text":"text2html"),a=this.set_busy(!0,"converting");return $.ajax({type:"POST",url:n,data:e,contentType:"application/octet-stream",error:function(e,t,s){ref.http_error(e,t,s,a)},success:function(e){ref.set_busy(!1,null,a),s&&s(e)}}),!0},this.url=function(e,t){var s="string"==typeof t?t:"";"string"!=typeof e?t=e:t&&"object"==typeof t||(t={}),e?t._action=e:this.env.action&&(t._action=this.env.action);var i,n=this.env.comm_path,a={};for(i in e&&e.match(/([a-z0-9_-]+)\/([a-z0-9-_.]+)/)&&(t._action=RegExp.$2,n=n.replace(/\_task=[a-z0-9_-]+/,"_task="+RegExp.$1)),t)void 0!==t[i]&&null!==t[i]&&(a[i]=t[i]);return(a=$.param(a))&&(n+=(n.indexOf("?")>-1?"&":"?")+a),s&&(n+=(n.indexOf("?")>-1?"&":"?")+s),n},this.redirect=function(e,t){(t||null===t)&&this.set_busy(!0),this.is_framed()?parent.rcmail.redirect(e,t):(this.env.extwin&&("string"==typeof e?e+=(e.indexOf("?")<0?"?":"&")+"_extwin=1":e._extwin=1),this.location_href(e,window))},this.goto_url=function(e,t,s,i){var n=this.url(e,t);i&&(n=this.secure_url(n)),this.redirect(n,s)},this.location_href=function(e,t,s){s&&this.lock_frame(),"object"==typeof e&&(e=this.env.comm_path+"&"+$.param(e)),bw.ie&&t==window?$("<a>").attr("href",e).appendTo(document.body).get(0).click():t.location.href=e,this.start_keepalive()},this.update_state=function(e){if(window.history.replaceState)try{window.history.replaceState({},document.title,rcmail.url("",e))}catch(e){}},this.http_request=function(e,t,s,i){"POST"!=i&&(i="GET"),"object"!=typeof t&&(t=rcube_parse_query(t)),t._remote=1,t._unlock=s||0;var n=this.triggerEvent("request"+e,t);if(t._status){var a={status:t._status};this.set_env({mailimportitip:a})}if(!1===n)return t._unlock&&this.set_busy(!1,null,t._unlock),!1;void 0!==n&&(t=n)._action&&(e=t._action,delete t._action);var r=this.url(e);return this.start_keepalive(),$.ajax({type:i,url:r,data:t,dataType:"json",success:function(e){ref.http_response(e)},error:function(t,i,n){ref.http_error(t,i,n,s,e)}})},this.http_get=this.http_request,this.http_post=function(e,t,s){return this.http_request(e,t,s,"POST")},this.abort_request=function(e){e.request&&e.request.abort(),e.lock&&this.set_busy(!1,null,e.lock)},this.http_response=function(response){if(response){var i;if(response.unlock&&this.set_busy(!1),this.triggerEvent("responsebefore",{response:response}),this.triggerEvent("responsebefore"+response.action,{response:response}),response.env&&this.set_env(response.env),"object"==typeof response.texts)for(i in response.texts)"string"==typeof response.texts[i]&&this.add_label(i,response.texts[i]);if(response.exec&&eval(response.exec),response.callbacks&&response.callbacks.length)for(i=0;i<response.callbacks.length;i++)this.triggerEvent(response.callbacks[i][0],response.callbacks[i][1]);switch(response.action){case"mark":"show"!=this.env.action&&"preview"!=this.env.action||"SEEN"!=this.env.last_flag||this.set_unread_message(this.env.uid,this.env.mailbox);break;case"delete":if("addressbook"==this.task){var sid,uid=this.contact_list.get_selection(),writable=!1;uid&&this.contact_list.rows[uid]&&(""==this.env.source?(sid=String(uid).replace(/^[^-]+-/,""),writable=sid&&this.env.address_sources[sid]&&!this.env.address_sources[sid].readonly):writable=!this.env.address_sources[this.env.source].readonly),this.enable_command("compose",uid&&this.contact_list.rows[uid]),this.enable_command("delete","edit",writable),this.enable_command("export",this.contact_list&&this.contact_list.rowcount>0),this.enable_command("export-selected","print",!1)}case"move":"show"==this.env.action?(this.enable_command(this.env.message_commands,!0),this.env.list_post||this.enable_command("reply-list",!1)):"addressbook"==this.task&&this.triggerEvent("listupdate",{folder:this.env.source,rowcount:this.contact_list.rowcount});case"purge":case"expunge":"mail"==this.task&&(this.env.exists||(this.env.contentframe&&this.show_contentframe(!1),this.enable_command(this.env.message_commands,"purge","expunge","select-all","select-none","expand-all","expand-unread","collapse-all",!1)),this.message_list&&this.triggerEvent("listupdate",{folder:this.env.mailbox,rowcount:this.message_list.rowcount}));break;case"refresh":case"check-recent":$.each(this.env.recent_flags||{},(function(e,t){ref.set_message(e,"deleted",t.deleted),ref.set_message(e,"replied",t.answered),ref.set_message(e,"unread",!t.seen),ref.set_message(e,"forwarded",t.forwarded),ref.set_message(e,"flagged",t.flagged)})),delete this.env.recent_flags;case"getunread":case"search":this.env.qsearch=null;case"list":if("mail"==this.task){var is_multifolder=this.is_multifolder_listing(),list=this.message_list,uid=this.env.list_uid;this.enable_command("show","select-all","select-none",this.env.messagecount>0),this.enable_command("expunge",this.env.exists&&!is_multifolder),this.enable_command("purge",this.purge_mailbox_test()&&!is_multifolder),this.enable_command("import-messages",!is_multifolder),this.enable_command("expand-all","expand-unread","collapse-all",this.env.threading&&this.env.messagecount&&!is_multifolder),list&&("list"!=response.action&&"search"!=response.action||(uid&&(list.rows[uid]||(uid+="-"+this.env.mailbox),list.rows[uid]&&list.select(uid),delete this.env.list_uid),this.enable_command("set-listmode",this.env.threads&&!is_multifolder),list.rowcount>0&&!$(document.activeElement).is("input,textarea")&&list.focus(),list.triggerEvent("select")),"getunread"!=response.action&&this.triggerEvent("listupdate",{folder:this.env.mailbox,rowcount:list.rowcount}))}else"addressbook"==this.task&&(this.enable_command("export",this.contact_list&&this.contact_list.rowcount>0),"list"!=response.action&&"search"!=response.action||(this.enable_command("search-create",""==this.env.source),this.enable_command("search-delete",this.env.search_id),this.update_group_commands(),this.contact_list.rowcount>0&&!$(document.activeElement).is("input,textarea")&&this.contact_list.focus(),this.triggerEvent("listupdate",{folder:this.env.source,rowcount:this.contact_list.rowcount})));break;case"list-contacts":case"search-contacts":this.contact_list&&this.contact_list.rowcount>0&&this.contact_list.focus()}response.unlock&&this.hide_message(response.unlock),void 0!==this.env.mailimportitip&&(response.mailimportitip=this.env.mailimportitip,this.set_env({mailimportitip:void 0})),this.triggerEvent("responseafter",{response:response}),this.triggerEvent("responseafter"+response.action,{response:response}),this.start_keepalive()}},this.http_error=function(e,t,s,i,n){var a=e.statusText;if(this.set_busy(!1,null,i),e.abort(),!this.unload){e.status&&a?this.display_message(this.get_label("servererror")+" ("+a+")","error"):"timeout"==t?this.display_message(this.get_label("requesttimedout"),"error"):0==e.status&&"abort"!=t&&this.display_message(this.get_label("connerror"),"error");var r=e.getResponseHeader("Location");r&&"compose"!=this.env.action&&this.redirect(r),403!=e.status?"keep-alive"==n&&setTimeout((function(){ref.keep_alive(),ref.start_keepalive()}),3e4):(this.is_framed()?parent:window).location.reload()}},this.session_error=function(e){this.env.server_error=401,"compose"==this.env.action?(this.save_compose_form_local(),this.compose_skip_unsavedcheck=!0,this.env.session_lifetime=0,this._keepalive&&clearInterval(this._keepalive),this._refresh&&clearInterval(this._refresh)):e&&setTimeout((function(){ref.redirect(e,!0)}),2e3)},this.iframe_loaded=function(e){this.set_busy(!1,null,e),this.submit_timer&&clearTimeout(this.submit_timer)},this.multi_thread_http_request=function(e){var t,s,i=(new Date).getTime(),n=e.threads||1;for(e.reqid=i,e.running=0,e.requests=[],e.result=[],e._items=$.extend([],e.items),e.lock||(e.lock=this.display_message(this.get_label("loading"),"loading")),this.http_request_jobs[i]=e,t=0;t<n&&void 0!==(s=e._items.shift());t++)e.running++,e.requests.push(this.multi_thread_send_request(e,s));return i},this.multi_thread_send_request=function(e,t){var s,i,n;if(e.postdata){for(s in i={},e.postdata)i[s]=String(e.postdata[s]).replace("%s",t);i._reqid=e.reqid}else if("string"==typeof e.query)n=e.query.replace("%s",t),n+="&_reqid="+e.reqid;else if("object"==typeof e.query&&e.query){for(s in n={},e.query)n[s]=String(e.query[s]).replace("%s",t);n._reqid=e.reqid}return i?this.http_post(e.action,i):this.http_request(e.action,n)},this.multi_thread_http_response=function(e,t){var s=this.http_request_jobs[t];if(!(!s||s.running<=0||s.cancelled)){s.running--,s.onresponse&&"function"==typeof s.onresponse&&s.onresponse(e),s.result=$.extend(s.result,e);var i=s._items.shift();void 0!==i?(s.running++,s.requests.push(this.multi_thread_send_request(s,i))):0==s.running&&(s.whendone&&"function"==typeof s.whendone&&s.whendone(s.result),this.set_busy(!1,"",s.lock),delete this.http_request_jobs[t])}},this.multi_thread_request_abort=function(e){var t=this.http_request_jobs[e];if(t){for(var s=0;t.running>0&&s<t.requests.length;s++)t.requests[s].abort&&t.requests[s].abort();t.running=0,t.cancelled=!0,this.set_busy(!1,"",t.lock)}},this.async_upload_form=function(e,t,s){var i=(new Date).getTime(),n="rcmupload"+i,a=this.async_upload_form_frame(n);if(this.env.upload_progress_name){var r=this.env.upload_progress_name,o=$("input[name="+r+"]",e);o.length||(o=$("<input>").attr({type:"hidden",name:r})).prependTo(e),o.val(i)}return a.on("load",{ts:i},s),$(e).attr({target:n,action:this.url(t,{_id:this.env.compose_id||"",_uploadid:i,_from:this.env.action}),method:"POST"}).attr(e.encoding?"encoding":"enctype","multipart/form-data").submit(),n},this.async_upload_form_frame=function(e){return $("<iframe>").attr({name:e,style:"border: none; width: 0; height: 0; visibility: hidden"}).appendTo(document.body)},this.document_drag_hover=function(e,t){$(this.gui_objects.filedrop)[t?"addClass":"removeClass"]("active")},this.file_drag_hover=function(e,t){e.preventDefault(),e.stopPropagation(),$(this.gui_objects.filedrop)[t?"addClass":"removeClass"]("hover")},this.file_dropped=function(e){this.file_drag_hover(e,!1);var t,s=0,i=0,n=e.target.files||e.dataTransfer.files,a=window.FormData?new FormData:null,r=(this.env.filedrop.fieldname||"_file")+(this.env.filedrop.single?"":"[]"),o="------multipartformboundary"+(new Date).getTime(),l="--"+o+"\r\n",c={_id:this.env.compose_id||this.env.cid||"",_remote:1,_from:this.env.action};if(n&&n.length){for(var h,d=function(){if(ref.env.max_filesize&&ref.env.filesizeerror&&s>ref.env.max_filesize)ref.display_message(ref.env.filesizeerror,"error");else if(ref.env.max_filecount&&ref.env.filecounterror&&i>ref.env.max_filecount)ref.display_message(ref.env.filecounterror,"error");else{var e=n.length>1,t=(new Date).getTime(),r=$("<span>").text(e?ref.get_label("uploadingmany"):n[0].name).html();ref.add2attachment_list(t,{name:"",html:r,classname:"uploading",complete:!1})||(ref.file_upload_id=ref.set_busy(!0,"uploading")),l+="--"+o+"--\r\n",c._uploadid=t,$.ajax({type:"POST",dataType:"json",url:ref.url(ref.env.filedrop.action||"upload",c),contentType:!a&&"multipart/form-data; boundary="+o,processData:!1,timeout:0,data:a||l,headers:{"X-Roundcube-Request":ref.env.request_token},xhr:function(){var e=jQuery.ajaxSettings.xhr();return!a&&e.sendAsBinary&&(e.send=e.sendAsBinary),e},success:function(e){ref.http_response(e)},error:function(e,t,s){ref.http_error(e,t,s,null,"attachment")}})}},_=this.env.filedrop.single?0:n.length-1,u=0,m=0;u<=_&&(h=n[m]);m++)if(h.name||(h.name=h.fileName),h.size||(h.size=h.fileSize),h.type||(h.type="application/octet-stream"),!a&&/[^\x20-\x7E]/.test(h.name)&&(h.name_bin=unescape(encodeURIComponent(h.name))),!this.env.filedrop.filter||h.type.match(new RegExp(this.env.filedrop.filter))){if(s+=h.size,i++,a){if(a.append(r,h),u==_)return d()}else if(window.FileReader){var p=new FileReader;p.onload=function(e,t){return function(s){if(l+='Content-Disposition: form-data; name="'+r+'"',l+='; filename="'+(h.name_bin||e.name)+'"\r\n',l+="Content-Length: "+e.size+"\r\n",l+="Content-Type: "+e.type+"\r\n\r\n",l+=p.result+"\r\n",l+="--"+o+"\r\n",t==_)return d()}}(h,u),p.readAsBinaryString(h)}else if(h.getAsBinary&&(l+='Content-Disposition: form-data; name="'+r+'"',l+='; filename="'+(h.name_bin||h.name)+'"\r\n',l+="Content-Length: "+h.size+"\r\n",l+="Content-Type: "+h.type+"\r\n\r\n",l+=h.getAsBinary()+"\r\n",l+="--"+o+"\r\n",u==_))return d();u++}}else if(t=e.dataTransfer.getData("roundcube-uri")){var f=(new Date).getTime(),g=$("<span>").text(e.dataTransfer.getData("roundcube-name")||this.get_label("attaching")).html();c._uri=t,c._uploadid=f,this.add2attachment_list(f,{name:"",html:g,classname:"uploading",complete:!1})||(this.file_upload_id=this.set_busy(!0,"attaching")),this.http_post(this.env.filedrop.action||"upload",c)}},this.start_keepalive=function(){if(this.env.session_lifetime&&!this.env.framed&&!this.env.extwin&&"login"!=this.task&&"print"!=this.env.action){this._keepalive&&clearInterval(this._keepalive);var e=.5*Math.min(1800,this.env.session_lifetime)*1e3;this._keepalive=setInterval((function(){ref.keep_alive()}),e<3e4?3e4:e)}},this.start_refresh=function(){!this.env.refresh_interval||this.env.framed||this.env.extwin||"login"==this.task||"print"==this.env.action||(this._refresh&&clearInterval(this._refresh),this._refresh=setInterval((function(){ref.refresh()}),1e3*this.env.refresh_interval))},this.keep_alive=function(){this.busy||this.http_request("keep-alive")},this.refresh=function(){if(this.busy)setTimeout((function(){ref.refresh(),ref.start_refresh()}),1e4);else{var e={},t=this.set_busy(!0,"refreshing");"mail"==this.task&&this.gui_objects.mailboxlist&&(e=this.check_recent_params()),e._last=Math.floor(this.env.lastrefresh.getTime()/1e3),this.env.lastrefresh=new Date,this.http_post("refresh",e,t)}},this.check_recent_params=function(){var e={_mbox:this.env.mailbox};return this.gui_objects.mailboxlist&&(e._folderlist=1),this.gui_objects.quotadisplay&&(e._quota=1),this.env.search_request&&(e._search=this.env.search_request),this.gui_objects.messagelist&&(e._list=1,e._uids=$.map(this.message_list.rows,(function(e,t){return t})).join(",")),e},this.quote_html=function(e){return String(e).replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},this.opener=function(e,t){var s,i=window.opener;try{if(i&&!i.closed){if(e&&(!i.rcmail||i.rcmail.env.framed)&&i.parent&&i.parent.rcmail&&(i=i.parent),i.rcmail&&t)for(s in t)if(i.rcmail.env[s]!=t[s])return;return i.rcmail}}catch(e){}},this.get_single_uid=function(){var e=this.env.uid||(this.message_list?this.message_list.get_single_selection():null);return ref.triggerEvent("get_single_uid",{uid:e})||e},this.get_single_cid=function(){var e=this.env.cid||(this.contact_list?this.contact_list.get_single_selection():null);return ref.triggerEvent("get_single_cid",{cid:e})||e},this.get_message_mailbox=function(e){var t;return this.env.messages&&e&&(t=this.env.messages[e])&&t.mbox?t.mbox:/^[0-9]+-(.*)$/.test(e)?RegExp.$1:this.env.mailbox},this.params_from_uid=function(e,t){return t||(t={}),t._uid=String(e).split("-")[0],t._mbox=this.get_message_mailbox(e),t},this.get_caret_pos=function(e){return void 0!==e.selectionEnd?e.selectionEnd:e.value.length},this.set_caret_pos=function(e,t){try{e.setSelectionRange&&e.setSelectionRange(t,t)}catch(e){}},this.get_input_selection=function(e){var t=0,s=0,i="";return"number"==typeof e.selectionStart&&"number"==typeof e.selectionEnd&&(i=e.value,t=e.selectionStart,s=e.selectionEnd),{start:t,end:s,text:i.substr(t,s-t)}},this.lock_form=function(e,t){var s,i,n;if(e&&e.elements)for(t&&(this.disabled_form_elements=[]),s=0,i=e.elements.length;s<i;s++)"hidden"!=(n=e.elements[s]).type&&(t&&n.disabled?this.disabled_form_elements.push(n):(t||$.inArray(n,this.disabled_form_elements)<0)&&(n.disabled=t))},this.mailto_handler_uri=function(){return location.href.split("?")[0]+"?_task=mail&_action=compose&_to=%s"},this.register_protocol_handler=function(e){try{window.navigator.registerProtocolHandler("mailto",this.mailto_handler_uri(),e)}catch(e){this.display_message(String(e),"error")}},this.check_protocol_handler=function(e,t){var s=window.navigator;if(s&&"function"==typeof s.registerProtocolHandler)if("function"==typeof s.isProtocolHandlerRegistered){var i=s.isProtocolHandlerRegistered("mailto",this.mailto_handler_uri());i&&$(t).parent().find(".mailtoprotohandler-status").html(i)}else $(t).click((function(){return ref.register_protocol_handler(e),!1}));else $(t).addClass("disabled").click((function(){return!1}))},this.browser_capabilities_check=function(){this.env.browser_capabilities||(this.env.browser_capabilities={}),$.each(["pdf","flash","tiff","webp"],(function(){void 0===ref.env.browser_capabilities[this]&&(ref.env.browser_capabilities[this]=ref[this+"_support_check"]())}))},this.browser_capabilities=function(){if(!this.env.browser_capabilities)return"";var e,t=[];for(e in this.env.browser_capabilities)t.push(e+"="+this.env.browser_capabilities[e]);return t.join()},this.tiff_support_check=function(){return this.image_support_check("tiff"),0},this.webp_support_check=function(){return this.image_support_check("webp"),0},this.image_support_check=function(e){window.setTimeout((function(){var t=new Image;t.onload=function(){ref.env.browser_capabilities[e]=1},t.onerror=function(){ref.env.browser_capabilities[e]=0},t.src=ref.assets_path("program/resources/blank."+e)}),10)},this.pdf_support_check=function(){var e,t=navigator.mimeTypes?navigator.mimeTypes["application/pdf"]:{},s=navigator.plugins,i=s.length,n=/Adobe Reader|PDF|Acrobat/i;if(t&&t.enabledPlugin)return 1;if("ActiveXObject"in window){try{if(t=new ActiveXObject("AcroPDF.PDF"))return 1}catch(e){}try{if(t=new ActiveXObject("PDF.PdfCtrl"))return 1}catch(e){}}for(e=0;e<i;e++)if("String"==typeof(t=s[e])){if(n.test(t))return 1}else if(t.name&&n.test(t.name))return 1;return window.setTimeout((function(){$("<object>").attr({data:ref.assets_path("program/resources/dummy.pdf"),type:"application/pdf",style:'position: "absolute"; top: -1000px; height: 1px; width: 1px'}).on("load error",(function(e){ref.env.browser_capabilities.pdf="load"==e.type?1:0,$(this).remove()})).appendTo($("body"))}),10),0},this.flash_support_check=function(){var e=navigator.mimeTypes?navigator.mimeTypes["application/x-shockwave-flash"]:{};if(e&&e.enabledPlugin)return 1;if("ActiveXObject"in window)try{if(e=new ActiveXObject("ShockwaveFlash.ShockwaveFlash"))return 1}catch(e){}return 0},this.assets_path=function(e){return this.env.assets_path&&!e.startsWith(this.env.assets_path)&&(e=this.env.assets_path+e),e},this.set_cookie=function(e,t,s){setCookie(e,t,s,this.env.cookie_path,this.env.cookie_domain,this.env.cookie_secure)},this.get_local_storage_prefix=function(){return this.local_storage_prefix||(this.local_storage_prefix="roundcube."+(this.env.user_id||"anonymous")+"."),this.local_storage_prefix},this.local_storage_get_item=function(e,t,s){var i,n;try{i=localStorage.getItem(this.get_local_storage_prefix()+e),n=JSON.parse(i)}catch(e){}return n||t||null},this.local_storage_set_item=function(e,t,s){try{return localStorage.setItem(this.get_local_storage_prefix()+e,JSON.stringify(t)),!0}catch(e){return!1}},this.local_storage_remove_item=function(e){try{return localStorage.removeItem(this.get_local_storage_prefix()+e),!0}catch(e){return!1}},this.print_dialog=function(){bw.safari?setTimeout("window.print()",10):window.print()}}rcube_webmail.long_subject_title=function(e,t){if(!e.title){var s=$(e);s.width()+15*(t||0)>s.parent().width()&&(e.title=rcube_webmail.subject_text(e))}},rcube_webmail.long_subject_title_ex=function(e){if(!e.title){var t=$(e),s=$.trim(t.text()),i=$("<span>").text(s).css({position:"absolute",float:"left",visibility:"hidden","font-size":t.css("font-size"),"font-weight":t.css("font-weight")}).appendTo($("body")),n=i.width();i.remove(),n+15*$("span.branch",t).width()>t.width()&&(e.title=rcube_webmail.subject_text(e))}},rcube_webmail.subject_text=function(e){var t=$(e).clone();return t.find(".skip-on-drag,.skip-content,.voice").remove(),t.text()},rcube_webmail.set_iframe_events=function(e){$("iframe").each((function(){var t=$(this);$.each(e,(function(e,s){t.on("load",(function(t){try{$(this).contents().on(e,s)}catch(t){}}));try{t.contents().on(e,s)}catch(e){}}))}))},rcube_webmail.prototype.get_cookie=getCookie,rcube_webmail.prototype.addEventListener=rcube_event_engine.prototype.addEventListener,rcube_webmail.prototype.removeEventListener=rcube_event_engine.prototype.removeEventListener,rcube_webmail.prototype.triggerEvent=rcube_event_engine.prototype.triggerEvent;