2 +-----------------------------------------------------------------------+
3 | RoundCube Webmail Client Script |
5 | This file is part of the RoundCube Webmail client |
6 | Copyright (C) 2005, RoundCube Dev, - Switzerland |
7 | Licensed under the GNU GPL |
9 +-----------------------------------------------------------------------+
10 | Authors: Thomas Bruederli <roundcube@gmail.com> |
11 | Charles McNulty <charles@charlesmcnulty.com> |
12 +-----------------------------------------------------------------------+
14 $Id: app.js 431 2006-12-23 10:44:16Z thomasb $
20 var CONTROL_SHIFT_KEY = 3;
22 var rcube_webmail_client;
24 function rcube_webmail()
26 this.env = new Object();
27 this.labels = new Object();
28 this.buttons = new Object();
29 this.gui_objects = new Object();
30 this.commands = new Object();
31 this.selection = new Array();
32 this.last_selected = 0;
33 this.in_message_list = false;
35 // create public reference to myself
36 rcube_webmail_client = this;
37 this.ref = 'rcube_webmail_client';
39 // webmail client settings
40 this.dblclick_time = 600;
41 this.message_time = 5000;
43 this.mbox_expression = new RegExp('[^0-9a-z\-_]', 'gi');
45 // mimetypes supported by the browser (default settings)
46 this.mimetypes = new Array('text/plain', 'text/html', 'text/xml',
47 'image/jpeg', 'image/gif', 'image/png',
48 'application/x-javascript', 'application/pdf',
49 'application/x-shockwave-flash');
51 // default environment vars
52 this.env.keep_alive = 60; // seconds
53 this.env.request_timeout = 180; // seconds
54 this.env.draft_autosave = 300; // seconds
57 // set environment variable
58 this.set_env = function(name, value)
60 this.env[name] = value;
64 // add a localized label to the client environment
65 this.add_label = function(key, value)
67 this.labels[key] = value;
71 // add a button to the button list
72 this.register_button = function(command, id, type, act, sel, over)
74 if (!this.buttons[command])
75 this.buttons[command] = new Array();
77 var button_prop = {id:id, type:type};
78 if (act) button_prop.act = act;
79 if (sel) button_prop.sel = sel;
80 if (over) button_prop.over = over;
82 this.buttons[command][this.buttons[command].length] = button_prop;
86 // register a specific gui object
87 this.gui_object = function(name, id)
89 this.gui_objects[name] = id;
93 // initialize webmail client
94 this.init = function()
96 this.task = this.env.task;
99 if (!bw.dom || !bw.xmlhttp_test())
101 location.href = this.env.comm_path+'&_action=error&_code=0x199';
105 // find all registered gui objects
106 for (var n in this.gui_objects)
107 this.gui_objects[n] = rcube_find_object(this.gui_objects[n]);
109 // tell parent window that this frame is loaded
110 if (this.env.framed && parent.rcmail && parent.rcmail.set_busy)
111 parent.rcmail.set_busy(false);
113 // enable general commands
114 this.enable_command('logout', 'mail', 'addressbook', 'settings', true);
119 var msg_list_frame = this.gui_objects.mailcontframe;
120 var msg_list = this.gui_objects.messagelist;
123 msg_list_frame.onmousedown = function(e){return rcube_webmail_client.click_on_list(e);};
124 this.init_messagelist(msg_list);
125 this.enable_command('toggle_status', true);
128 // enable mail commands
129 this.enable_command('list', 'checkmail', 'compose', 'add-contact', 'search', 'reset-search', true);
131 if (this.env.action=='show')
133 this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'delete', 'viewsource', 'print', 'load-attachment', true);
134 if (this.env.next_uid)
135 this.enable_command('nextmessage', true);
136 if (this.env.prev_uid)
137 this.enable_command('previousmessage', true);
140 if (this.env.action=='show' && this.env.blockedobjects)
142 if (this.gui_objects.remoteobjectsmsg)
143 this.gui_objects.remoteobjectsmsg.style.display = 'block';
144 this.enable_command('load-images', true);
147 if (this.env.action=='compose')
149 this.enable_command('add-attachment', 'send-attachment', 'remove-attachment', 'send', true);
150 if (this.env.spellcheck)
151 this.enable_command('spellcheck', true);
152 if (this.env.drafts_mailbox)
153 this.enable_command('savedraft', true);
156 if (this.env.messagecount)
157 this.enable_command('select-all', 'select-none', 'sort', 'expunge', true);
159 if (this.env.messagecount && (this.env.mailbox==this.env.trash_mailbox || this.env.mailbox==this.env.junk_mailbox))
160 this.enable_command('purge', true);
162 this.set_page_buttons();
167 // init message compose form
168 if (this.env.action=='compose')
169 this.init_messageform();
171 // show printing dialog
172 if (this.env.action=='print')
175 // get unread count for each mailbox
176 if (this.gui_objects.mailboxlist)
177 this.http_request('getunread', '');
183 var contacts_list = this.gui_objects.contactslist;
184 var ldap_contacts_list = this.gui_objects.ldapcontactslist;
187 this.init_contactslist(contacts_list);
189 if (ldap_contacts_list)
190 this.init_ldapsearchlist(ldap_contacts_list);
192 this.set_page_buttons();
195 this.enable_command('show', 'edit', true);
197 if ((this.env.action=='add' || this.env.action=='edit') && this.gui_objects.editform)
198 this.enable_command('save', true);
200 this.enable_command('list', 'add', true);
202 this.enable_command('ldappublicsearch', this.env.ldappublicsearch);
208 this.enable_command('preferences', 'identities', 'save', 'folders', true);
210 if (this.env.action=='identities' || this.env.action=='edit-identity' || this.env.action=='add-identity')
211 this.enable_command('edit', 'add', 'delete', true);
213 if (this.env.action=='edit-identity' || this.env.action=='add-identity')
214 this.enable_command('save', true);
216 if (this.env.action=='folders')
217 this.enable_command('subscribe', 'unsubscribe', 'create-folder', 'rename-folder', 'delete-folder', true);
219 var identities_list = this.gui_objects.identitieslist;
221 this.init_identitieslist(identities_list);
226 var input_user = rcube_find_object('_user');
227 var input_pass = rcube_find_object('_pass');
228 if (input_user && input_user.value=='')
233 this.enable_command('login', true);
241 // enable basic commands
242 this.enable_command('logout', true);
244 // disable browser's contextmenus
245 // document.oncontextmenu = function(){ return false; }
247 // load body click event
248 document.onmousedown = function(){ return rcube_webmail_client.reset_click(); };
249 document.onkeydown = function(e){ return rcube_webmail_client.key_pressed(e, msg_list_frame); };
251 // flag object as complete
255 if (this.pending_message)
256 this.display_message(this.pending_message[0], this.pending_message[1]);
258 // start keep-alive interval
259 this.start_keepalive();
263 // start interval for keep-alive/recent_check signal
264 this.start_keepalive = function()
266 if (this.env.keep_alive && this.task=='mail' && this.gui_objects.messagelist)
267 this._int = setInterval(this.ref+'.check_for_recent()', this.env.keep_alive * 1000);
268 else if (this.env.keep_alive && this.task!='login')
269 this._int = setInterval(this.ref+'.send_keep_alive()', this.env.keep_alive * 1000);
273 // reset last clicked if user clicks on anything other than the message table
274 this.reset_click = function()
277 this.in_message_list = false;
278 for (var n=0; n<this.selection.length; n++)
280 id = this.selection[n];
281 if (this.list_rows[id] && this.list_rows[id].obj)
283 this.set_classname(this.list_rows[id].obj, 'selected', false);
284 this.set_classname(this.list_rows[id].obj, 'unfocused', true);
289 this.click_on_list = function(e)
294 for (var n=0; n<this.selection.length; n++)
296 id = this.selection[n];
297 if (this.list_rows[id].obj)
299 this.set_classname(this.list_rows[id].obj, 'selected', true);
300 this.set_classname(this.list_rows[id].obj, 'unfocused', false);
305 if (mbox_li = this.get_mailbox_li())
306 this.set_classname(mbox_li, 'unfocused', true);
308 this.in_message_list = true;
309 e.cancelBubble = true;
312 this.key_pressed = function(e, msg_list_frame) {
313 if (this.in_message_list != true)
315 var keyCode = document.layers ? e.which : document.all ? event.keyCode : document.getElementById ? e.keyCode : 0;
316 var mod_key = this.get_modifier(e);
319 this.command('show','',this);
323 return this.use_arrow_key(keyCode, mod_key, msg_list_frame);
326 return this.use_delete_key(keyCode, mod_key, msg_list_frame);
334 this.use_arrow_key = function(keyCode, mod_key, msg_list_frame) {
336 if (keyCode == 40) { // down arrow key pressed
337 new_row = this.get_next_row();
338 if (!new_row) return false;
339 scroll_to = (Number(new_row.offsetTop) + Number(new_row.offsetHeight)) - Number(msg_list_frame.offsetHeight);
340 } else if (keyCode == 38) { // up arrow key pressed
341 new_row = this.get_prev_row();
342 if (!new_row) return false;
343 scroll_to = new_row.offsetTop;
344 } else {return true;}
346 this.select_row(new_row.uid,mod_key,true);
348 if (((Number(new_row.offsetTop)) < (Number(msg_list_frame.scrollTop))) ||
349 ((Number(new_row.offsetTop) + Number(new_row.offsetHeight)) > (Number(msg_list_frame.scrollTop) + Number(msg_list_frame.offsetHeight)))) {
350 msg_list_frame.scrollTop = scroll_to;
355 this.use_delete_key = function(keyCode, mod_key, msg_list_frame){
356 this.command('delete','',this);
360 // get all message rows from HTML table and init each row
361 this.init_messagelist = function(msg_list)
363 if (msg_list && msg_list.tBodies[0])
366 this.message_rows = new Array();
369 for(var r=0; r<msg_list.tBodies[0].childNodes.length; r++)
371 row = msg_list.tBodies[0].childNodes[r];
372 while (row && (row.nodeType != 1 || row.style.display == 'none')) {
373 row = row.nextSibling;
376 //row = msg_list.tBodies[0].rows[r];
377 if (row) this.init_message_row(row);
381 // alias to common rows array
382 this.list_rows = this.message_rows;
386 // make references in internal array and set event handlers
387 this.init_message_row = function(row)
391 if (String(row.id).match(/rcmrow([0-9]+)/))
396 this.message_rows[uid] = {id:row.id, obj:row,
397 classname:row.className,
398 deleted:this.env.messages[uid] ? this.env.messages[uid].deleted : null,
399 unread:this.env.messages[uid] ? this.env.messages[uid].unread : null,
400 replied:this.env.messages[uid] ? this.env.messages[uid].replied : null};
402 // set eventhandlers to table row
403 row.onmousedown = function(e){ return rcube_webmail_client.drag_row(e, this.uid); };
404 row.onmouseup = function(e){ return rcube_webmail_client.click_row(e, this.uid); };
407 row.onselectstart = function() { return false; };
409 // set eventhandler to message icon
410 if ((msg_icon = row.cells[0].childNodes[0]) && row.cells[0].childNodes[0].nodeName=='IMG')
412 msg_icon.id = 'msgicn_'+uid;
414 msg_icon.onmousedown = function(e) { rcube_webmail_client.command('toggle_status', this); };
416 // get message icon and save original icon src
417 this.message_rows[uid].icon = msg_icon;
423 // init message compose form: set focus and eventhandlers
424 this.init_messageform = function()
426 if (!this.gui_objects.messageform)
429 //this.messageform = this.gui_objects.messageform;
430 var input_from = rcube_find_object('_from');
431 var input_to = rcube_find_object('_to');
432 var input_cc = rcube_find_object('_cc');
433 var input_bcc = rcube_find_object('_bcc');
434 var input_replyto = rcube_find_object('_replyto');
435 var input_subject = rcube_find_object('_subject');
436 var input_message = rcube_find_object('_message');
438 // init live search events
440 this.init_address_input_events(input_to);
442 this.init_address_input_events(input_cc);
444 this.init_address_input_events(input_bcc);
446 // add signature according to selected identity
447 if (input_from && input_from.type=='select-one')
448 this.change_identity(input_from);
450 if (input_to && input_to.value=='')
452 else if (input_subject && input_subject.value=='')
453 input_subject.focus();
454 else if (input_message)
455 this.set_caret2start(input_message); // input_message.focus();
457 // get summary of all field values
458 this.cmp_hash = this.compose_field_hash();
460 // start the auto-save timer
461 this.auto_save_start();
464 this.init_address_input_events = function(obj)
466 var handler = function(e){ return rcube_webmail_client.ksearch_keypress(e,this); };
467 var handler2 = function(e){ return rcube_webmail_client.ksearch_blur(e,this); };
471 obj.addEventListener('keydown', handler, false);
472 // obj.addEventListener('blur', handler2, false);
476 obj.addEventListener('keypress', handler, false);
477 obj.addEventListener('blur', handler2, false);
481 obj.onkeydown = handler;
482 //obj.attachEvent('onkeydown', handler);
483 // obj.attachEvent('onblur', handler2, false);
486 obj.setAttribute('autocomplete', 'off');
491 // get all contact rows from HTML table and init each row
492 this.init_contactslist = function(contacts_list)
494 if (contacts_list && contacts_list.tBodies[0])
496 this.contact_rows = new Array();
499 for(var r=0; r<contacts_list.tBodies[0].childNodes.length; r++)
501 row = contacts_list.tBodies[0].childNodes[r];
502 this.init_table_row(row, 'contact_rows');
506 // alias to common rows array
507 this.list_rows = this.contact_rows;
510 this.highlight_row(this.env.cid);
514 // get all contact rows from HTML table and init each row
515 this.init_ldapsearchlist = function(ldap_contacts_list)
517 if (ldap_contacts_list && ldap_contacts_list.tBodies[0])
519 this.ldap_contact_rows = new Array();
522 for(var r=0; r<ldap_contacts_list.tBodies[0].childNodes.length; r++)
524 row = ldap_contacts_list.tBodies[0].childNodes[r];
525 this.init_table_row(row, 'ldap_contact_rows');
529 // alias to common rows array
530 this.list_rows = this.ldap_contact_rows;
534 // make references in internal array and set event handlers
535 this.init_table_row = function(row, array_name)
539 if (String(row.id).match(/rcmrow([0-9]+)/))
544 this[array_name][cid] = {id:row.id,
546 classname:row.className};
548 // set eventhandlers to table row
549 row.onmousedown = function(e) { rcube_webmail_client.in_selection_before=this.cid; return false; }; // fake for drag handler
550 row.onmouseup = function(e){ return rcube_webmail_client.click_row(e, this.cid); };
555 // get all contact rows from HTML table and init each row
556 this.init_identitieslist = function(identities_list)
558 if (identities_list && identities_list.tBodies[0])
560 this.identity_rows = new Array();
563 for(var r=0; r<identities_list.tBodies[0].childNodes.length; r++)
565 row = identities_list.tBodies[0].childNodes[r];
566 this.init_table_row(row, 'identity_rows');
570 // alias to common rows array
571 this.list_rows = this.identity_rows;
574 this.highlight_row(this.env.iid);
579 /*********************************************************/
580 /********* client command interface *********/
581 /*********************************************************/
584 // execute a specific command on the web client
585 this.command = function(command, props, obj)
593 // command not supported or allowed
594 if (!this.commands[command])
596 // pass command to parent window
597 if (this.env.framed && parent.rcmail && parent.rcmail.command)
598 parent.rcmail.command(command, props);
604 // check input before leaving compose step
605 if (this.task=='mail' && this.env.action=='compose' && (command=='list' || command=='mail' || command=='addressbook' || command=='settings'))
607 if (this.cmp_hash != this.compose_field_hash() && !confirm(this.get_label('notsentwarning')))
616 if (this.gui_objects.loginform)
617 this.gui_objects.loginform.submit();
621 location.href = this.env.comm_path+'&_action=logout';
624 // commands to switch task
628 this.switch_task(command);
632 // misc list commands
634 if (this.task=='mail')
636 if (this.env.search_request<0 || (this.env.search_request && props != this.env.mailbox))
637 this.reset_qsearch();
639 // Reset message list header, unless returning from compose/read/etc
640 // don't know what this is good for (thomasb, 2006/07/25)
641 //if (this.env.mailbox != props && this.message_rows)
642 // this.clear_message_list_header();
644 this.list_mailbox(props);
646 else if (this.task=='addressbook')
647 this.list_contacts();
652 // get the type of sorting
653 var a_sort = props.split('_');
654 var sort_col = a_sort[0];
655 var sort_order = a_sort[1] ? a_sort[1].toUpperCase() : null;
658 // no sort order specified: toggle
659 if (sort_order==null)
661 if (this.env.sort_col==sort_col)
662 sort_order = this.env.sort_order=='ASC' ? 'DESC' : 'ASC';
664 sort_order = this.env.sort_order;
667 if (this.env.sort_col==sort_col && this.env.sort_order==sort_order)
670 // set table header class
671 if (header = document.getElementById('rcmHead'+this.env.sort_col))
672 this.set_classname(header, 'sorted'+(this.env.sort_order.toUpperCase()), false);
673 if (header = document.getElementById('rcmHead'+sort_col))
674 this.set_classname(header, 'sorted'+sort_order, true);
676 // save new sort properties
677 this.env.sort_col = sort_col;
678 this.env.sort_order = sort_order;
680 // reload message list
681 this.list_mailbox('', '', sort_col+'_'+sort_order);
685 this.list_page('next');
689 this.list_page('prev');
693 if (this.env.messagecount)
694 this.expunge_mailbox(this.env.mailbox);
698 case 'empty-mailbox':
699 if (this.env.messagecount)
700 this.purge_mailbox(this.env.mailbox);
704 // common commands used in multiple tasks
706 if (this.task=='mail')
708 var uid = this.get_single_uid();
709 if (uid && (!this.env.uid || uid != this.env.uid))
711 if (this.env.mailbox==this.env.drafts_mailbox)
714 location.href = this.env.comm_path+'&_action=compose&_draft_uid='+uid+'&_mbox='+escape(this.env.mailbox);
717 this.show_message(uid);
720 else if (this.task=='addressbook')
722 var cid = props ? props : this.get_single_cid();
723 if (cid && !(this.env.action=='show' && cid==this.env.cid))
724 this.load_contact(cid, 'show');
729 if (this.task=='addressbook')
730 if (!window.frames[this.env.contentframe].rcmail)
731 this.load_contact(0, 'add');
734 if (window.frames[this.env.contentframe].rcmail.selection.length)
735 this.add_ldap_contacts();
737 this.load_contact(0, 'add');
739 else if (this.task=='settings')
741 this.clear_selection();
742 this.load_identity(0, 'add-identity');
748 if (this.task=='addressbook' && (cid = this.get_single_cid()))
749 this.load_contact(cid, 'edit');
750 else if (this.task=='settings' && props)
751 this.load_identity(props, 'edit-identity');
754 case 'save-identity':
756 if (this.gui_objects.editform)
758 var input_pagesize = rcube_find_object('_pagesize');
759 var input_name = rcube_find_object('_name');
760 var input_email = rcube_find_object('_email');
763 if (input_pagesize && isNaN(input_pagesize.value))
765 alert(this.get_label('nopagesizewarning'));
766 input_pagesize.focus();
769 // contacts/identities
772 if (input_name && input_name.value == '')
774 alert(this.get_label('nonamewarning'));
778 else if (input_email && !rcube_check_email(input_email.value))
780 alert(this.get_label('noemailwarning'));
786 this.gui_objects.editform.submit();
792 if (this.task=='mail')
793 this.delete_messages();
795 else if (this.task=='addressbook')
796 this.delete_contacts();
797 // user settings task
798 else if (this.task=='settings')
799 this.delete_identity();
803 // mail task commands
806 this.move_messages(props);
809 case 'toggle_status':
810 if (props && !props._row)
818 uid = props._row.uid;
819 this.dont_select = true;
820 // toggle read/unread
821 if (this.message_rows[uid].deleted) {
823 } else if (!this.message_rows[uid].unread)
827 this.mark_message(flag, uid);
832 this.show_message(this.env.uid, true);
835 case 'load-attachment':
836 var url = this.env.comm_path+'&_action=get&_mbox='+this.env.mailbox+'&_uid='+this.env.uid+'&_part='+props.part;
838 // open attachment in frame if it's of a supported mimetype
839 if (this.env.uid && props.mimetype && find_in_array(props.mimetype, this.mimetypes)>=0)
841 this.attachment_win = window.open(url+'&_frame=1', 'rcubemailattachment');
842 if (this.attachment_win)
844 setTimeout(this.ref+'.attachment_win.focus()', 10);
853 this.select_all(props);
857 this.clear_selection();
861 if (this.env.next_uid)
862 this.show_message(this.env.next_uid);
863 //location.href = this.env.comm_path+'&_action=show&_uid='+this.env.next_uid+'&_mbox='+this.env.mailbox;
866 case 'previousmessage':
867 if (this.env.prev_uid)
868 this.show_message(this.env.prev_uid);
869 //location.href = this.env.comm_path+'&_action=show&_uid='+this.env.prev_uid+'&_mbox='+this.env.mailbox;
873 this.check_for_recent();
877 var url = this.env.comm_path+'&_action=compose';
879 if (this.task=='mail' && this.env.mailbox==this.env.drafts_mailbox)
882 if (uid = this.get_single_uid())
883 url += '&_draft_uid='+uid+'&_mbox='+escape(this.env.mailbox);
885 // modify url if we're in addressbook
886 else if (this.task=='addressbook')
888 url = this.get_task_url('mail', url);
889 var a_cids = new Array();
891 // use contact_id passed as command parameter
893 a_cids[a_cids.length] = props;
895 // get selected contacts
898 if (!window.frames[this.env.contentframe].rcmail.selection.length)
900 for (var n=0; n<this.selection.length; n++)
901 a_cids[a_cids.length] = this.selection[n];
905 var frameRcmail = window.frames[this.env.contentframe].rcmail;
906 // get the email address(es)
907 for (var n=0; n<frameRcmail.selection.length; n++)
908 a_cids[a_cids.length] = frameRcmail.ldap_contact_rows[frameRcmail.selection[n]].obj.cells[1].innerHTML;
912 url += '&_to='+a_cids.join(',');
918 url += '&_to='+encodeURIComponent(props);
920 // don't know if this is necessary...
921 url = url.replace(/&_framed=1/, "");
925 // need parent in case we are coming from the contact frame
927 parent.location.href = url;
933 if (this.env.spellcheck && this.env.spellcheck.spellCheck)
934 this.env.spellcheck.spellCheck(this.env.spellcheck.check_link);
938 // Reset the auto-save timer
939 self.clearTimeout(this.save_timer);
941 if (!this.gui_objects.messageform)
944 // if saving Drafts is disabled in main.inc.php
945 if (!this.env.drafts_mailbox)
948 this.set_busy(true, 'savingmessage');
949 var form = this.gui_objects.messageform;
950 form.target = "savetarget";
955 if (!this.gui_objects.messageform)
958 if (!this.check_compose_input())
961 // Reset the auto-save timer
962 self.clearTimeout(this.save_timer);
964 // all checks passed, send message
965 this.set_busy(true, 'sendingmessage');
966 var form = this.gui_objects.messageform;
967 form.target = "savetarget";
968 form._draft.value = '';
971 // clear timeout (sending could take longer)
972 clearTimeout(this.request_timer);
975 case 'add-attachment':
976 this.show_attachment_form(true);
978 case 'send-attachment':
979 // Reset the auto-save timer
980 self.clearTimeout(this.save_timer);
982 this.upload_file(props)
985 case 'remove-attachment':
986 this.remove_attachment(props);
992 if (uid = this.get_single_uid())
995 location.href = this.env.comm_path+'&_action=compose&_reply_uid='+uid+'&_mbox='+escape(this.env.mailbox)+(command=='reply-all' ? '&_all=1' : '');
1001 if (uid = this.get_single_uid())
1003 this.set_busy(true);
1004 location.href = this.env.comm_path+'&_action=compose&_forward_uid='+uid+'&_mbox='+escape(this.env.mailbox);
1010 if (uid = this.get_single_uid())
1012 this.printwin = window.open(this.env.comm_path+'&_action=print&_uid='+uid+'&_mbox='+escape(this.env.mailbox)+(this.env.safemode ? '&_safe=1' : ''));
1014 setTimeout(this.ref+'.printwin.focus()', 20);
1020 if (uid = this.get_single_uid())
1022 this.sourcewin = window.open(this.env.comm_path+'&_action=viewsource&_uid='+this.env.uid+'&_mbox='+escape(this.env.mailbox));
1024 setTimeout(this.ref+'.sourcewin.focus()', 20);
1029 this.add_contact(props);
1034 if (!props && this.gui_objects.qsearchbox)
1035 props = this.gui_objects.qsearchbox.value;
1037 this.qsearch(escape(props), this.env.mailbox);
1040 // reset quicksearch
1041 case 'reset-search':
1042 var s = this.env.search_request;
1043 this.reset_qsearch();
1046 this.list_mailbox(this.env.mailbox);
1050 case 'ldappublicsearch':
1051 if (this.gui_objects.ldappublicsearchform)
1052 this.gui_objects.ldappublicsearchform.submit();
1054 this.ldappublicsearch(command);
1058 // user settings commands
1060 location.href = this.env.comm_path;
1064 location.href = this.env.comm_path+'&_action=identities';
1067 case 'delete-identity':
1068 this.delete_identity();
1071 location.href = this.env.comm_path+'&_action=folders';
1075 this.subscribe_folder(props);
1079 this.unsubscribe_folder(props);
1082 case 'create-folder':
1083 this.create_folder(props);
1086 case 'rename-folder':
1087 this.rename_folder(props);
1090 case 'delete-folder':
1091 if (confirm(this.get_label('deletefolderconfirm')))
1092 this.delete_folder(props);
1097 return obj ? false : true;
1101 // set command enabled or disabled
1102 this.enable_command = function()
1104 var args = arguments;
1105 if(!args.length) return -1;
1108 var enable = args[args.length-1];
1110 for(var n=0; n<args.length-1; n++)
1113 this.commands[command] = enable;
1114 this.set_button(command, (enable ? 'act' : 'pas'));
1120 // lock/unlock interface
1121 this.set_busy = function(a, message)
1125 var msg = this.get_label(message);
1129 this.display_message(msg, 'loading', true);
1131 else if (!a && this.busy)
1132 this.hide_message();
1135 //document.body.style.cursor = a ? 'wait' : 'default';
1137 if (this.gui_objects.editform)
1138 this.lock_form(this.gui_objects.editform, a);
1140 // clear pending timer
1141 if (this.request_timer)
1142 clearTimeout(this.request_timer);
1144 // set timer for requests
1145 if (a && this.env.request_timeout)
1146 this.request_timer = setTimeout(this.ref+'.request_timed_out()', this.env.request_timeout * 1000);
1150 // return a localized string
1151 this.get_label = function(name)
1153 if (this.labels[name])
1154 return this.labels[name];
1160 // switch to another application task
1161 this.switch_task = function(task)
1163 if (this.task===task && task!='mail')
1166 var url = this.get_task_url(task);
1168 url += '&_mbox=INBOX';
1170 this.set_busy(true);
1171 location.href = url;
1175 this.get_task_url = function(task, url)
1178 url = this.env.comm_path;
1180 return url.replace(/_task=[a-z]+/, '_task='+task);
1184 // called when a request timed out
1185 this.request_timed_out = function()
1187 this.set_busy(false);
1188 this.display_message('Request timed out!', 'error');
1192 /*********************************************************/
1193 /********* event handling methods *********/
1194 /*********************************************************/
1197 // onmouseup handler for mailboxlist item
1198 this.mbox_mouse_up = function(mbox)
1200 if (this.drag_active)
1202 this.unfocus_mailbox(mbox);
1203 this.command('moveto', mbox);
1206 this.command('list', mbox);
1212 // onmousedown-handler of message list row
1213 this.drag_row = function(e, id)
1215 this.in_selection_before = this.in_selection(id) ? id : false;
1217 // don't do anything (another action processed before)
1218 if (this.dont_select)
1221 // selects currently unselected row
1222 if (!this.in_selection_before && !this.list_rows[id].clicked)
1224 var mod_key = this.get_modifier(e);
1225 this.select_row(id,mod_key,false);
1228 if (this.selection.length)
1230 this.drag_start = true;
1231 document.onmousemove = function(e){ return rcube_webmail_client.drag_mouse_move(e); };
1232 document.onmouseup = function(e){ return rcube_webmail_client.drag_mouse_up(e); };
1239 // onmouseup-handler of message list row
1240 this.click_row = function(e, id)
1242 var mod_key = this.get_modifier(e);
1244 // don't do anything (another action processed before)
1245 if (this.dont_select)
1247 this.dont_select = false;
1251 // unselects currently selected row
1252 if (!this.drag_active && this.in_selection_before==id && !this.list_rows[id].clicked)
1253 this.select_row(id,mod_key,false);
1255 this.drag_start = false;
1256 this.in_selection_before = false;
1258 // row was double clicked
1259 if (this.task=='mail' && this.list_rows && this.list_rows[id].clicked && this.in_selection(id))
1261 if (this.env.mailbox==this.env.drafts_mailbox)
1263 this.set_busy(true);
1264 location.href = this.env.comm_path+'&_action=compose&_draft_uid='+id+'&_mbox='+escape(this.env.mailbox);
1268 this.show_message(id);
1272 else if (this.task=='addressbook')
1274 if (this.contact_rows && this.selection.length==1)
1276 this.load_contact(this.selection[0], 'show', true);
1277 // change the text for the add contact button
1278 var links = parent.document.getElementById('abooktoolbar').getElementsByTagName('A');
1279 for (i = 0; i < links.length; i++)
1281 var onclickstring = new String(links[i].onclick);
1282 if (onclickstring.search('\"add\"') != -1)
1283 links[i].title = this.env.newcontact;
1286 else if (this.contact_rows && this.contact_rows[id].clicked)
1288 this.load_contact(id, 'show');
1291 else if (this.ldap_contact_rows && !this.ldap_contact_rows[id].clicked)
1294 parent.rcmail.clear_selection();
1297 parent.rcmail.set_button('delete', 'pas');
1299 // change the text for the add contact button
1300 var links = parent.document.getElementById('abooktoolbar').getElementsByTagName('A');
1301 for (i = 0; i < links.length; i++)
1303 var onclickstring = new String(links[i].onclick);
1304 if (onclickstring.search('\"add\"') != -1)
1305 links[i].title = this.env.addcontact;
1308 // handle double click event
1309 else if (this.ldap_contact_rows && this.selection.length==1 && this.ldap_contact_rows[id].clicked)
1310 this.command('compose', this.ldap_contact_rows[id].obj.cells[1].innerHTML);
1311 else if (this.env.contentframe)
1313 var elm = document.getElementById(this.env.contentframe);
1314 elm.style.visibility = 'hidden';
1317 else if (this.task=='settings')
1319 if (this.selection.length==1)
1320 this.command('edit', this.selection[0]);
1323 this.list_rows[id].clicked = true;
1324 setTimeout(this.ref+'.list_rows['+id+'].clicked=false;', this.dblclick_time);
1331 /*********************************************************/
1332 /********* (message) list functionality *********/
1333 /*********************************************************/
1335 // get next and previous rows that are not hidden
1336 this.get_next_row = function(){
1337 if (!this.list_rows) return false;
1338 var last_selected_row = this.list_rows[this.last_selected];
1339 var new_row = last_selected_row.obj.nextSibling;
1340 while (new_row && (new_row.nodeType != 1 || new_row.style.display == 'none')) {
1341 new_row = new_row.nextSibling;
1346 this.get_prev_row = function(){
1347 if (!this.list_rows) return false;
1348 var last_selected_row = this.list_rows[this.last_selected];
1349 var new_row = last_selected_row.obj.previousSibling;
1350 while (new_row && (new_row.nodeType != 1 || new_row.style.display == 'none')) {
1351 new_row = new_row.previousSibling;
1356 // highlight/unhighlight a row
1357 this.highlight_row = function(id, multiple)
1359 var selected = false
1361 if (this.list_rows[id] && !multiple)
1363 this.clear_selection();
1364 this.selection[0] = id;
1365 this.list_rows[id].obj.className += ' selected';
1369 else if (this.list_rows[id])
1371 if (!this.in_selection(id)) // select row
1373 this.selection[this.selection.length] = id;
1374 this.set_classname(this.list_rows[id].obj, 'selected', true);
1376 else // unselect row
1378 var p = find_in_array(id, this.selection);
1379 var a_pre = this.selection.slice(0, p);
1380 var a_post = this.selection.slice(p+1, this.selection.length);
1381 this.selection = a_pre.concat(a_post);
1382 this.set_classname(this.list_rows[id].obj, 'selected', false);
1383 this.set_classname(this.list_rows[id].obj, 'unfocused', false);
1385 selected = (this.selection.length==1);
1388 // enable/disable commands for message
1389 if (this.task=='mail')
1391 if (this.env.mailbox==this.env.drafts_mailbox)
1393 this.enable_command('show', selected);
1394 this.enable_command('delete', 'moveto', this.selection.length>0 ? true : false);
1398 this.enable_command('show', 'reply', 'reply-all', 'forward', 'print', selected);
1399 this.enable_command('delete', 'moveto', this.selection.length>0 ? true : false);
1402 else if (this.task=='addressbook')
1404 this.enable_command('edit', /*'print',*/ selected);
1405 this.enable_command('delete', 'compose', this.selection.length>0 ? true : false);
1410 // selects or unselects the proper row depending on the modifier key pressed
1411 this.select_row = function(id,mod_key,with_mouse) {
1413 this.shift_start = id;
1414 this.highlight_row(id, false);
1418 this.shift_select(id,false);
1421 this.shift_start = id;
1423 this.highlight_row(id, true);
1426 case CONTROL_SHIFT_KEY: {
1427 this.shift_select(id,true);
1431 this.highlight_row(id, false);
1436 if (this.last_selected != 0 && this.list_rows[this.last_selected])
1437 this.set_classname(this.list_rows[this.last_selected].obj, 'focused', false);
1439 this.last_selected = id;
1440 this.set_classname(this.list_rows[id].obj, 'focused', true);
1443 this.shift_select = function(id, control) {
1444 var from_rowIndex = this.list_rows[this.shift_start].obj.rowIndex;
1445 var to_rowIndex = this.list_rows[id].obj.rowIndex;
1447 var i = ((from_rowIndex < to_rowIndex)? from_rowIndex : to_rowIndex);
1448 var j = ((from_rowIndex > to_rowIndex)? from_rowIndex : to_rowIndex);
1450 // iterate through the entire message list
1451 for (var n in this.list_rows) {
1452 if ((this.list_rows[n].obj.rowIndex >= i) && (this.list_rows[n].obj.rowIndex <= j)) {
1453 if (!this.in_selection(n))
1454 this.highlight_row(n, true);
1456 if (this.in_selection(n) && !control)
1457 this.highlight_row(n, true);
1463 this.clear_selection = function()
1465 for(var n=0; n<this.selection.length; n++)
1466 if (this.list_rows[this.selection[n]]) {
1467 this.set_classname(this.list_rows[this.selection[n]].obj, 'selected', false);
1468 this.set_classname(this.list_rows[this.selection[n]].obj, 'unfocused', false);
1470 this.selection = new Array();
1474 // check if given id is part of the current selection
1475 this.in_selection = function(id)
1477 for(var n in this.selection)
1478 if (this.selection[n]==id)
1485 // select each row in list
1486 this.select_all = function(filter)
1488 if (!this.list_rows || !this.list_rows.length)
1491 // reset selection first
1492 this.clear_selection();
1494 for (var n in this.list_rows)
1496 if (!filter || this.list_rows[n][filter]==true)
1498 this.last_selected = n;
1499 this.highlight_row(n, true);
1507 // when user doble-clicks on a row
1508 this.show_message = function(id, safe)
1511 var target = window;
1512 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe])
1514 target = window.frames[this.env.contentframe];
1515 add_url = '&_framed=1';
1519 add_url = '&_safe=1';
1523 this.set_busy(true, 'loading');
1524 target.location.href = this.env.comm_path+'&_action=show&_uid='+id+'&_mbox='+escape(this.env.mailbox)+add_url;
1530 // list a specific page
1531 this.list_page = function(page)
1534 page = this.env.current_page+1;
1535 if (page=='prev' && this.env.current_page>1)
1536 page = this.env.current_page-1;
1538 if (page > 0 && page <= this.env.pagecount)
1540 this.env.current_page = page;
1542 if (this.task=='mail')
1543 this.list_mailbox(this.env.mailbox, page);
1544 else if (this.task=='addressbook')
1545 this.list_contacts(page);
1550 // list messages of a specific mailbox
1551 this.list_mailbox = function(mbox, page, sort)
1553 this.last_selected = 0;
1555 var target = window;
1558 mbox = this.env.mailbox;
1560 // add sort to url if set
1562 add_url += '&_sort=' + sort;
1564 // set page=1 if changeing to another mailbox
1565 if (!page && mbox != this.env.mailbox)
1568 add_url += '&_refresh=1';
1569 this.env.current_page = page;
1570 this.clear_selection();
1573 // also send search request to get the right messages
1574 if (this.env.search_request)
1575 add_url += '&_search='+this.env.search_request;
1577 this.select_mailbox(mbox);
1579 // load message list remotely
1580 if (this.gui_objects.messagelist)
1582 this.list_mailbox_remote(mbox, page, add_url);
1586 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe])
1588 target = window.frames[this.env.contentframe];
1589 add_url += '&_framed=1';
1592 // load message list to target frame/window
1595 this.set_busy(true, 'loading');
1596 target.location.href = this.env.comm_path+'&_mbox='+escape(mbox)+(page ? '&_page='+page : '')+add_url;
1601 // send remote request to load message list
1602 this.list_mailbox_remote = function(mbox, page, add_url)
1604 // clear message list first
1605 this.clear_message_list();
1607 // send request to server
1608 var url = '_mbox='+escape(mbox)+(page ? '&_page='+page : '');
1609 this.set_busy(true, 'loading');
1610 this.http_request('list', url+add_url, true);
1614 this.clear_message_list = function()
1616 var table = this.gui_objects.messagelist;
1618 var tbody = document.createElement('TBODY');
1619 table.insertBefore(tbody, table.tBodies[0]);
1620 table.removeChild(table.tBodies[1]);
1622 this.message_rows = new Array();
1623 this.list_rows = this.message_rows;
1628 this.clear_message_list_header = function()
1631 if (table = this.gui_objects.messagelist)
1634 table.removeChild(table.colgroup);
1636 table.removeChild(table.tHead);
1638 var colgroup = document.createElement('COLGROUP');
1639 var thead = document.createElement('THEAD');
1640 table.insertBefore(colgroup, table.tBodies[0]);
1641 table.insertBefore(thead, table.tBodies[0]);
1646 this.expunge_mailbox = function(mbox)
1651 // lock interface if it's the active mailbox
1652 if (mbox == this.env.mailbox)
1655 this.set_busy(true, 'loading');
1656 add_url = '&_reload=1';
1659 // send request to server
1660 var url = '_mbox='+escape(mbox);
1661 this.http_request('expunge', url+add_url, lock);
1665 this.purge_mailbox = function(mbox)
1670 if (!confirm(this.get_label('purgefolderconfirm')))
1673 // lock interface if it's the active mailbox
1674 if (mbox == this.env.mailbox)
1677 this.set_busy(true, 'loading');
1678 add_url = '&_reload=1';
1681 // send request to server
1682 var url = '_mbox='+escape(mbox);
1683 this.http_request('purge', url+add_url, lock);
1687 this.focus_mailbox = function(mbox)
1690 if (this.drag_active && mbox != this.env.mailbox && (mbox_li = this.get_mailbox_li(mbox)))
1691 this.set_classname(mbox_li, 'droptarget', true);
1694 this.unfocus_mailbox = function(mbox)
1697 if (this.drag_active && (mbox_li = this.get_mailbox_li(mbox)))
1698 this.set_classname(mbox_li, 'droptarget', false);
1701 // move selected messages to the specified mailbox
1702 this.move_messages = function(mbox)
1704 // exit if no mailbox specified or if selection is empty
1705 if (!mbox || !(this.selection.length || this.env.uid) || mbox==this.env.mailbox)
1708 var a_uids = new Array();
1711 a_uids[a_uids.length] = this.env.uid;
1715 for (var n=0; n<this.selection.length; n++)
1717 id = this.selection[n];
1718 a_uids[a_uids.length] = id;
1720 // 'remove' message row from list (just hide it)
1721 if (this.message_rows[id].obj)
1722 this.message_rows[id].obj.style.display = 'none';
1724 next_row = this.get_next_row();
1725 prev_row = this.get_prev_row();
1726 new_row = (next_row) ? next_row : prev_row;
1727 if (new_row) this.select_row(new_row.uid,false,false);
1732 // show wait message
1733 if (this.env.action=='show')
1736 this.set_busy(true, 'movingmessage');
1738 // send request to server
1739 this.http_request('moveto', '_uid='+a_uids.join(',')+'&_mbox='+escape(this.env.mailbox)+'&_target_mbox='+escape(mbox)+'&_from='+(this.env.action ? this.env.action : ''), lock);
1742 this.permanently_remove_messages = function() {
1743 // exit if no mailbox specified or if selection is empty
1744 if (!(this.selection.length || this.env.uid))
1747 var a_uids = new Array();
1750 a_uids[a_uids.length] = this.env.uid;
1754 for (var n=0; n<this.selection.length; n++)
1756 id = this.selection[n];
1757 a_uids[a_uids.length] = id;
1759 // 'remove' message row from list (just hide it)
1760 if (this.message_rows[id].obj)
1761 this.message_rows[id].obj.style.display = 'none';
1764 next_row = this.get_next_row();
1765 prev_row = this.get_prev_row();
1766 new_row = (next_row) ? next_row : prev_row;
1767 if (new_row) this.select_row(new_row.uid,false,false);
1769 // send request to server
1770 this.http_request('delete', '_uid='+a_uids.join(',')+'&_mbox='+escape(this.env.mailbox)+'&_from='+(this.env.action ? this.env.action : ''));
1774 // delete selected messages from the current mailbox
1775 this.delete_messages = function()
1777 // exit if no mailbox specified or if selection is empty
1778 if (!(this.selection.length || this.env.uid))
1780 // if there is a trash mailbox defined and we're not currently in it:
1781 if (this.env.trash_mailbox && String(this.env.mailbox).toLowerCase()!=String(this.env.trash_mailbox).toLowerCase())
1782 this.move_messages(this.env.trash_mailbox);
1783 // if there is a trash mailbox defined but we *are* in it:
1784 else if (this.env.trash_mailbox && String(this.env.mailbox).toLowerCase() == String(this.env.trash_mailbox).toLowerCase())
1785 this.permanently_remove_messages();
1786 // if there isn't a defined trash mailbox and the config is set to flag for deletion
1787 else if (!this.env.trash_mailbox && this.env.flag_for_deletion) {
1789 this.mark_message(flag);
1790 if(this.env.action=="show"){
1791 this.command('nextmessage','',this);
1792 } else if (this.selection.length == 1) {
1793 next_row = this.get_next_row();
1794 prev_row = this.get_prev_row();
1795 new_row = (next_row) ? next_row : prev_row;
1796 if (new_row) this.select_row(new_row.uid,false,false);
1798 // if there isn't a defined trash mailbox and the config is set NOT to flag for deletion
1799 }else if (!this.env.trash_mailbox && !this.env.flag_for_deletion) {
1800 this.permanently_remove_messages();
1806 // set a specific flag to one or more messages
1807 this.mark_message = function(flag, uid)
1809 var a_uids = new Array();
1813 else if (this.env.uid)
1814 a_uids[0] = this.env.uid;
1818 for (var n=0; n<this.selection.length; n++)
1820 id = this.selection[n];
1821 a_uids[a_uids.length] = id;
1827 this.toggle_read_status(flag,a_uids);
1831 this.toggle_delete_status(a_uids);
1836 // set class to read/unread
1837 this.toggle_read_status = function(flag, a_uids) {
1838 // mark all message rows as read/unread
1840 for (var i=0; i<a_uids.length; i++)
1843 if (this.message_rows[uid])
1845 this.message_rows[uid].unread = (flag=='unread' ? true : false);
1847 if (this.message_rows[uid].classname.indexOf('unread')<0 && this.message_rows[uid].unread)
1849 this.message_rows[uid].classname += ' unread';
1850 this.set_classname(this.message_rows[uid].obj, 'unread', true);
1852 if (this.env.unreadicon)
1853 icn_src = this.env.unreadicon;
1855 else if (!this.message_rows[uid].unread)
1857 this.message_rows[uid].classname = this.message_rows[uid].classname.replace(/\s*unread/, '');
1858 this.set_classname(this.message_rows[uid].obj, 'unread', false);
1860 if (this.message_rows[uid].replied && this.env.repliedicon)
1861 icn_src = this.env.repliedicon;
1862 else if (this.env.messageicon)
1863 icn_src = this.env.messageicon;
1866 if (this.message_rows[uid].icon && icn_src)
1867 this.message_rows[uid].icon.src = icn_src;
1870 this.http_request('mark', '_uid='+a_uids.join(',')+'&_flag='+flag);
1873 // mark all message rows as deleted/undeleted
1874 this.toggle_delete_status = function(a_uids) {
1875 if (this.env.read_when_deleted) {
1876 this.toggle_read_status('read',a_uids);
1878 // if deleting message from "view message" don't bother with delete icon
1879 if (this.env.action == "show")
1882 if (a_uids.length==1){
1883 if(this.message_rows[a_uids[0]].classname.indexOf('deleted') < 0 ){
1884 this.flag_as_deleted(a_uids)
1886 this.flag_as_undeleted(a_uids)
1891 var all_deleted = true;
1893 for (var i=0; i<a_uids.length; i++) {
1895 if (this.message_rows[uid]) {
1896 if (this.message_rows[uid].classname.indexOf('deleted')<0) {
1897 all_deleted = false;
1904 this.flag_as_undeleted(a_uids);
1906 this.flag_as_deleted(a_uids);
1911 this.flag_as_undeleted = function(a_uids){
1912 // if deleting message from "view message" don't bother with delete icon
1913 if (this.env.action == "show")
1918 for (var i=0; i<a_uids.length; i++) {
1920 if (this.message_rows[uid]) {
1921 this.message_rows[uid].deleted = false;
1923 if (this.message_rows[uid].classname.indexOf('deleted') > 0) {
1924 this.message_rows[uid].classname = this.message_rows[uid].classname.replace(/\s*deleted/, '');
1925 this.set_classname(this.message_rows[uid].obj, 'deleted', false);
1927 if (this.message_rows[uid].unread && this.env.unreadicon)
1928 icn_src = this.env.unreadicon;
1929 else if (this.message_rows[uid].replied && this.env.repliedicon)
1930 icn_src = this.env.repliedicon;
1931 else if (this.env.messageicon)
1932 icn_src = this.env.messageicon;
1933 if (this.message_rows[uid].icon && icn_src)
1934 this.message_rows[uid].icon.src = icn_src;
1937 this.http_request('mark', '_uid='+a_uids.join(',')+'&_flag=undelete');
1941 this.flag_as_deleted = function(a_uids) {
1942 // if deleting message from "view message" don't bother with delete icon
1943 if (this.env.action == "show")
1946 for (var i=0; i<a_uids.length; i++) {
1948 if (this.message_rows[uid]) {
1949 this.message_rows[uid].deleted = true;
1951 if (this.message_rows[uid].classname.indexOf('deleted')<0) {
1952 this.message_rows[uid].classname += ' deleted';
1953 this.set_classname(this.message_rows[uid].obj, 'deleted', true);
1955 if (this.message_rows[uid].icon && this.env.deletedicon)
1956 this.message_rows[uid].icon.src = this.env.deletedicon;
1959 this.http_request('mark', '_uid='+a_uids.join(',')+'&_flag=delete');
1964 this.get_mailbox_li = function(mbox)
1966 if (this.gui_objects.mailboxlist)
1968 mbox = String((mbox ? mbox : this.env.mailbox)).toLowerCase().replace(this.mbox_expression, '');
1969 return document.getElementById('rcmbx'+mbox);
1976 /*********************************************************/
1977 /********* message compose methods *********/
1978 /*********************************************************/
1981 // checks the input fields before sending a message
1982 this.check_compose_input = function()
1984 // check input fields
1985 var input_to = rcube_find_object('_to');
1986 var input_subject = rcube_find_object('_subject');
1987 var input_message = rcube_find_object('_message');
1989 // check for empty recipient
1990 if (input_to && !rcube_check_email(input_to.value, true))
1992 alert(this.get_label('norecipientwarning'));
1997 // display localized warning for missing subject
1998 if (input_subject && input_subject.value == '')
2000 var subject = prompt(this.get_label('nosubjectwarning'), this.get_label('nosubject'));
2002 // user hit cancel, so don't send
2003 if (!subject && subject !== '')
2005 input_subject.focus();
2010 input_subject.value = subject ? subject : this.get_label('nosubject');
2014 // check for empty body
2015 if (input_message.value=='')
2017 if (!confirm(this.get_label('nobodywarning')))
2019 input_message.focus();
2028 this.auto_save_start = function()
2030 if (this.env.draft_autosave)
2031 this.save_timer = self.setTimeout(this.ref+'.command("savedraft")', this.env.draft_autosave * 1000);
2035 this.compose_field_hash = function()
2037 // check input fields
2038 var input_to = rcube_find_object('_to');
2039 var input_cc = rcube_find_object('_to');
2040 var input_bcc = rcube_find_object('_to');
2041 var input_subject = rcube_find_object('_subject');
2042 var input_message = rcube_find_object('_message');
2045 if (input_to && input_to.value)
2046 str += input_to.value+':';
2047 if (input_cc && input_cc.value)
2048 str += input_cc.value+':';
2049 if (input_bcc && input_bcc.value)
2050 str += input_bcc.value+':';
2051 if (input_subject && input_subject.value)
2052 str += input_subject.value+':';
2053 if (input_message && input_message.value)
2054 str += input_message.value;
2060 this.change_identity = function(obj)
2062 if (!obj || !obj.options)
2065 var id = obj.options[obj.selectedIndex].value;
2066 var input_message = rcube_find_object('_message');
2067 var message = input_message ? input_message.value : '';
2070 if (!this.env.identity)
2071 this.env.identity = id
2073 // remove the 'old' signature
2074 if (this.env.identity && this.env.signatures && this.env.signatures[this.env.identity])
2076 sig = this.env.signatures[this.env.identity];
2077 if (sig.indexOf('--')!=0)
2080 p = message.lastIndexOf(sig);
2082 message = message.substring(0, p-1) + message.substring(p+sig.length, message.length);
2085 // add the new signature string
2086 if (this.env.signatures && this.env.signatures[id])
2088 sig = this.env.signatures[id];
2089 if (sig.indexOf('--')!=0)
2091 message += '\n'+sig;
2095 input_message.value = message;
2097 this.env.identity = id;
2102 this.show_attachment_form = function(a)
2104 if (!this.gui_objects.uploadbox)
2108 if (elm = this.gui_objects.uploadbox)
2110 if (a && (list = this.gui_objects.attachmentlist))
2112 var pos = rcube_get_object_pos(list);
2114 var top = pos.y + list.offsetHeight + 10;
2116 elm.style.top = top+'px';
2117 elm.style.left = left+'px';
2120 elm.style.visibility = a ? 'visible' : 'hidden';
2123 // clear upload form
2124 if (!a && this.gui_objects.attachmentform && this.gui_objects.attachmentform!=this.gui_objects.messageform)
2125 this.gui_objects.attachmentform.reset();
2131 // upload attachment file
2132 this.upload_file = function(form)
2138 // get file input fields
2140 for (var n=0; n<form.elements.length; n++)
2141 if (form.elements[n].type=='file' && form.elements[n].value)
2147 // create hidden iframe and post upload form
2150 var ts = new Date().getTime();
2151 var frame_name = 'rcmupload'+ts;
2153 // have to do it this way for IE
2154 // otherwise the form will be posted to a new window
2155 if(document.all && !window.opera)
2157 var html = '<iframe name="'+frame_name+'" src="program/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>';
2158 document.body.insertAdjacentHTML('BeforeEnd',html);
2160 else // for standards-compilant browsers
2162 var frame = document.createElement('IFRAME');
2163 frame.name = frame_name;
2166 frame.style.visibility = 'hidden';
2167 document.body.appendChild(frame);
2170 form.target = frame_name;
2171 form.action = this.env.comm_path+'&_action=upload';
2172 form.setAttribute('enctype', 'multipart/form-data');
2176 // set reference to the form object
2177 this.gui_objects.attachmentform = form;
2182 // add file name to attachment list
2183 // called from upload page
2184 this.add2attachment_list = function(name, content)
2186 if (!this.gui_objects.attachmentlist)
2189 var li = document.createElement('LI');
2191 li.innerHTML = content;
2192 this.gui_objects.attachmentlist.appendChild(li);
2196 this.remove_from_attachment_list = function(name)
2198 if (!this.gui_objects.attachmentlist)
2201 var list = this.gui_objects.attachmentlist.getElementsByTagName("li");
2202 for (i=0;i<list.length;i++)
2203 if (list[i].id == name)
2204 this.gui_objects.attachmentlist.removeChild(list[i]);
2207 this.remove_attachment = function(name)
2210 this.http_request('remove-attachment', '_file='+escape(name));
2215 // send remote request to add a new contact
2216 this.add_contact = function(value)
2219 this.http_request('addcontact', '_address='+value);
2224 // send remote request to search mail
2225 this.qsearch = function(value, mbox)
2229 this.clear_message_list();
2230 this.set_busy(true, 'searching');
2231 this.http_request('search', '_search='+value+'&_mbox='+mbox, true);
2236 // reset quick-search form
2237 this.reset_qsearch = function()
2239 if (this.gui_objects.qsearchbox)
2240 this.gui_objects.qsearchbox.value = '';
2242 this.env.search_request = null;
2247 this.sent_successfully = function(msg)
2249 this.list_mailbox();
2250 this.display_message(msg, 'confirmation', true);
2254 /*********************************************************/
2255 /********* keyboard live-search methods *********/
2256 /*********************************************************/
2259 // handler for keyboard events on address-fields
2260 this.ksearch_keypress = function(e, obj)
2262 if (typeof(this.env.contacts)!='object' || !this.env.contacts.length)
2265 if (this.ksearch_timer)
2266 clearTimeout(this.ksearch_timer);
2272 var key = e.keyCode ? e.keyCode : e.which;
2277 case 40: // key down
2278 if (!this.ksearch_pane)
2281 var dir = key==38 ? 1 : 0;
2284 highlight = document.getElementById('rcmksearchSelected');
2286 highlight = this.ksearch_pane.ul.firstChild;
2288 if (highlight && (next = dir ? highlight.previousSibling : highlight.nextSibling))
2290 highlight.removeAttribute('id');
2291 //highlight.removeAttribute('class');
2292 this.set_classname(highlight, 'selected', false);
2297 next.setAttribute('id', 'rcmksearchSelected');
2298 this.set_classname(next, 'selected', true);
2299 this.ksearch_selected = next._rcm_id;
2302 if (e.preventDefault)
2311 if (this.ksearch_selected===null || !this.ksearch_input || !this.ksearch_value)
2315 var inp_value = this.ksearch_input.value.toLowerCase();
2316 var cpos = this.get_caret_pos(this.ksearch_input);
2317 var p = inp_value.lastIndexOf(this.ksearch_value, cpos);
2319 // replace search string with full address
2320 var pre = this.ksearch_input.value.substring(0, p);
2321 var end = this.ksearch_input.value.substring(p+this.ksearch_value.length, this.ksearch_input.value.length);
2322 var insert = this.env.contacts[this.ksearch_selected]+', ';
2323 this.ksearch_input.value = pre + insert + end;
2325 //this.ksearch_input.value = this.ksearch_input.value.substring(0, p)+insert;
2327 // set caret to insert pos
2328 cpos = p+insert.length;
2329 if (this.ksearch_input.setSelectionRange)
2330 this.ksearch_input.setSelectionRange(cpos, cpos);
2332 // hide ksearch pane
2333 this.ksearch_hide();
2335 if (e.preventDefault)
2340 this.ksearch_hide();
2346 this.ksearch_timer = setTimeout(this.ref+'.ksearch_get_results()', 200);
2347 this.ksearch_input = obj;
2353 // address search processor
2354 this.ksearch_get_results = function()
2356 var inp_value = this.ksearch_input ? this.ksearch_input.value : null;
2357 if (inp_value===null)
2360 // get string from current cursor pos to last comma
2361 var cpos = this.get_caret_pos(this.ksearch_input);
2362 var p = inp_value.lastIndexOf(',', cpos-1);
2363 var q = inp_value.substring(p+1, cpos);
2365 // trim query string
2366 q = q.replace(/(^\s+|\s+$)/g, '').toLowerCase();
2368 if (!q.length || q==this.ksearch_value)
2370 if (!q.length && this.ksearch_pane && this.ksearch_pane.visible)
2371 this.ksearch_pane.show(0);
2376 this.ksearch_value = q;
2378 // start searching the contact list
2379 var a_results = new Array();
2380 var a_result_ids = new Array();
2382 for (var i=0; i<this.env.contacts.length; i++)
2384 if (this.env.contacts[i].toLowerCase().indexOf(q)>=0)
2386 a_results[c] = this.env.contacts[i];
2387 a_result_ids[c++] = i;
2389 if (c==15) // limit search results
2394 // display search results
2395 if (c && a_results.length)
2399 // create results pane if not present
2400 if (!this.ksearch_pane)
2402 ul = document.createElement('UL');
2403 this.ksearch_pane = new rcube_layer('rcmKSearchpane', {vis:0, zindex:30000});
2404 this.ksearch_pane.elm.appendChild(ul);
2405 this.ksearch_pane.ul = ul;
2408 ul = this.ksearch_pane.ul;
2410 // remove all search results
2413 // add each result line to list
2414 for (i=0; i<a_results.length; i++)
2416 li = document.createElement('LI');
2417 li.innerHTML = a_results[i].replace(/</, '<').replace(/>/, '>');
2418 li._rcm_id = a_result_ids[i];
2422 // check if last selected item is still in result list
2423 if (this.ksearch_selected!==null)
2425 p = find_in_array(this.ksearch_selected, a_result_ids);
2426 if (p>=0 && ul.childNodes)
2428 ul.childNodes[p].setAttribute('id', 'rcmksearchSelected');
2429 this.set_classname(ul.childNodes[p], 'selected', true);
2432 this.ksearch_selected = null;
2435 // if no item selected, select the first one
2436 if (this.ksearch_selected===null)
2438 ul.firstChild.setAttribute('id', 'rcmksearchSelected');
2439 this.set_classname(ul.firstChild, 'selected', true);
2440 this.ksearch_selected = a_result_ids[0];
2443 // resize the containing layer to fit the list
2444 //this.ksearch_pane.resize(ul.offsetWidth, ul.offsetHeight);
2446 // move the results pane right under the input box and make it visible
2447 var pos = rcube_get_object_pos(this.ksearch_input);
2448 this.ksearch_pane.move(pos.x, pos.y+this.ksearch_input.offsetHeight);
2449 this.ksearch_pane.show(1);
2451 // hide results pane
2453 this.ksearch_hide();
2457 this.ksearch_blur = function(e, obj)
2459 if (this.ksearch_timer)
2460 clearTimeout(this.ksearch_timer);
2462 this.ksearch_value = '';
2463 this.ksearch_input = null;
2465 this.ksearch_hide();
2469 this.ksearch_hide = function()
2471 this.ksearch_selected = null;
2473 if (this.ksearch_pane)
2474 this.ksearch_pane.show(0);
2479 /*********************************************************/
2480 /********* address book methods *********/
2481 /*********************************************************/
2484 this.list_contacts = function(page)
2487 var target = window;
2489 if (page && this.current_page==page)
2492 // load contacts remotely
2493 if (this.gui_objects.contactslist)
2495 this.list_contacts_remote(page);
2499 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe])
2501 target = window.frames[this.env.contentframe];
2502 add_url = '&_framed=1';
2505 this.set_busy(true, 'loading');
2506 location.href = this.env.comm_path+(page ? '&_page='+page : '')+add_url;
2510 // send remote request to load contacts list
2511 this.list_contacts_remote = function(page)
2514 var table = this.gui_objects.contactslist;
2515 var tbody = document.createElement('TBODY');
2516 table.insertBefore(tbody, table.tBodies[0]);
2517 table.tBodies[1].style.display = 'none';
2519 this.contact_rows = new Array();
2520 this.list_rows = this.contact_rows;
2522 // send request to server
2523 var url = page ? '&_page='+page : '';
2524 this.set_busy(true, 'loading');
2525 this.http_request('list', url, true);
2529 // load contact record
2530 this.load_contact = function(cid, action, framed)
2533 var target = window;
2534 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe])
2536 add_url = '&_framed=1';
2537 target = window.frames[this.env.contentframe];
2538 document.getElementById(this.env.contentframe).style.visibility = 'inherit';
2543 //if (this.env.framed && add_url=='')
2545 // add_url = '&_framed=1';
2547 if (action && (cid || action=='add'))
2549 this.set_busy(true);
2550 target.location.href = this.env.comm_path+'&_action='+action+'&_cid='+cid+add_url;
2556 this.delete_contacts = function()
2558 // exit if no mailbox specified or if selection is empty
2559 if (!(this.selection.length || this.env.cid) || !confirm(this.get_label('deletecontactconfirm')))
2562 var a_cids = new Array();
2565 a_cids[a_cids.length] = this.env.cid;
2569 for (var n=0; n<this.selection.length; n++)
2571 id = this.selection[n];
2572 a_cids[a_cids.length] = id;
2574 // 'remove' row from list (just hide it)
2575 if (this.contact_rows[id].obj)
2576 this.contact_rows[id].obj.style.display = 'none';
2579 // hide content frame if we delete the currently displayed contact
2580 if (this.selection.length==1 && this.env.contentframe)
2582 var elm = document.getElementById(this.env.contentframe);
2583 elm.style.visibility = 'hidden';
2587 // send request to server
2588 this.http_request('delete', '_cid='+a_cids.join(',')+'&_from='+(this.env.action ? this.env.action : ''));
2593 // update a contact record in the list
2594 this.update_contact_row = function(cid, cols_arr)
2596 if (!this.contact_rows[cid] || !this.contact_rows[cid].obj)
2599 var row = this.contact_rows[cid].obj;
2600 for (var c=0; c<cols_arr.length; c++){
2602 row.cells[c].innerHTML = cols_arr[c];
2608 // load ldap search form
2609 this.ldappublicsearch = function(action)
2612 var target = window;
2613 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe])
2615 add_url = '&_framed=1';
2616 target = window.frames[this.env.contentframe];
2617 document.getElementById(this.env.contentframe).style.visibility = 'inherit';
2623 if (action == 'ldappublicsearch')
2624 target.location.href = this.env.comm_path+'&_action='+action+add_url;
2629 // add ldap contacts to address book
2630 this.add_ldap_contacts = function()
2632 if (window.frames[this.env.contentframe].rcmail)
2634 var frame = window.frames[this.env.contentframe];
2637 var url = '&_framed=1';
2638 var emails = '&_emails=';
2639 var names = '&_names=';
2641 for (var n=0; n<frame.rcmail.selection.length; n++)
2643 end = n < frame.rcmail.selection.length - 1 ? ',' : '';
2644 emails += frame.rcmail.ldap_contact_rows[frame.rcmail.selection[n]].obj.cells[1].innerHTML + end;
2645 names += frame.rcmail.ldap_contact_rows[frame.rcmail.selection[n]].obj.cells[0].innerHTML + end;
2648 frame.location.href = this.env.comm_path + '&_action=save&_framed=1' + emails + names;
2655 /*********************************************************/
2656 /********* user settings methods *********/
2657 /*********************************************************/
2660 // load contact record
2661 this.load_identity = function(id, action)
2663 if (action=='edit-identity' && (!id || id==this.env.iid))
2667 var target = window;
2668 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe])
2670 add_url = '&_framed=1';
2671 target = window.frames[this.env.contentframe];
2672 document.getElementById(this.env.contentframe).style.visibility = 'inherit';
2675 if (action && (id || action=='add-identity'))
2677 this.set_busy(true);
2678 target.location.href = this.env.comm_path+'&_action='+action+'&_iid='+id+add_url;
2685 this.delete_identity = function(id)
2687 // exit if no mailbox specified or if selection is empty
2688 if (!(this.selection.length || this.env.iid))
2692 id = this.env.iid ? this.env.iid : this.selection[0];
2695 // 'remove' row from list (just hide it)
2696 if (this.identity_rows && this.identity_rows[id].obj)
2698 this.clear_selection();
2699 this.identity_rows[id].obj.style.display = 'none';
2703 // if (this.env.framed && id)
2704 this.set_busy(true);
2705 location.href = this.env.comm_path+'&_action=delete-identity&_iid='+id;
2707 // this.http_request('delete-identity', '_iid='+id);
2712 // tell server to create and subscribe a new mailbox
2713 this.create_folder = function(name)
2715 if (this.edit_folder)
2716 this.reset_folder_rename();
2719 if ((form = this.gui_objects.editform) && form.elements['_folder_name'])
2720 name = form.elements['_folder_name'].value;
2723 this.http_request('create-folder', '_name='+escape(name), true);
2724 else if (form.elements['_folder_name'])
2725 form.elements['_folder_name'].focus();
2729 // entry point for folder renaming
2730 this.rename_folder = function(props)
2732 var form, oldname, newname;
2734 // rename a specific mailbox
2736 this.edit_foldername(props);
2738 // use a dropdown and input field (old behavior)
2739 else if ((form = this.gui_objects.editform) && form.elements['_folder_oldname'] && form.elements['_folder_newname'])
2741 oldname = form.elements['_folder_oldname'].value;
2742 newname = form.elements['_folder_newname'].value;
2745 if (oldname && newname)
2746 this.http_request('rename-folder', '_folder_oldname='+escape(oldname)+'&_folder_newname='+escape(newname));
2750 // start editing the mailbox name.
2751 // this will replace the name string with an input field
2752 this.edit_foldername = function(folder)
2754 var temp, row, form;
2755 var id = this.get_folder_row_id(folder);
2757 // reset current renaming
2758 if (temp = this.edit_folder)
2760 this.reset_folder_rename();
2765 if (id && (row = document.getElementById(id)))
2767 this.name_input = document.createElement('INPUT');
2768 this.name_input.value = this.env.subscriptionrows[id];
2769 this.name_input.style.width = '100%';
2770 this.name_input.onkeypress = function(e){ rcmail.name_input_keypress(e); };
2772 row.cells[0].replaceChild(this.name_input, row.cells[0].firstChild);
2773 this.edit_folder = id;
2774 this.name_input.select();
2776 if (form = this.gui_objects.editform)
2777 form.onsubmit = function(){ return false; };
2782 // remove the input field and write the current mailbox name to the table cell
2783 this.reset_folder_rename = function()
2785 var cell = this.name_input ? this.name_input.parentNode : null;
2786 if (cell && this.edit_folder)
2787 cell.innerHTML = this.env.subscriptionrows[this.edit_folder];
2789 this.edit_folder = null;
2793 // handler for keyboard events on the input field
2794 this.name_input_keypress = function(e)
2796 var key = document.all ? event.keyCode : document.getElementById ? e.keyCode : 0;
2801 var newname = this.name_input ? this.name_input.value : null;
2802 if (this.edit_folder && newname)
2803 this.http_request('rename-folder', '_folder_oldname='+escape(this.env.subscriptionrows[this.edit_folder])+'&_folder_newname='+escape(newname));
2807 this.reset_folder_rename();
2811 // delete a specific mailbox with all its messages
2812 this.delete_folder = function(folder)
2814 if (this.edit_folder)
2815 this.reset_folder_rename();
2818 this.http_request('delete-folder', '_mboxes='+escape(folder));
2822 // add a new folder to the subscription list by cloning a folder row
2823 this.add_folder_row = function(name, replace)
2825 name = name.replace('\\',"");
2826 if (!this.gui_objects.subscriptionlist)
2829 for (var refid in this.env.subscriptionrows)
2830 if (this.env.subscriptionrows[refid]!=null)
2834 var tbody = this.gui_objects.subscriptionlist.tBodies[0];
2835 var id = replace && replace.id ? replace.id : tbody.childNodes.length+1;
2837 if (!id || !(refrow = document.getElementById(refid)))
2839 // Refresh page if we don't have a table row to clone
2840 location.href = this.env.comm_path+'&_action=folders';
2844 // clone a table row if there are existing rows
2845 var row = this.clone_table_row(refrow);
2846 row.id = 'rcmrow'+id;
2848 tbody.replaceChild(row, replace);
2850 tbody.appendChild(row);
2853 // add to folder/row-ID map
2854 this.env.subscriptionrows[row.id] = name;
2857 row.cells[0].innerHTML = name;
2858 if (row.cells[1] && row.cells[1].firstChild.tagName=='INPUT')
2860 row.cells[1].firstChild.value = name;
2861 row.cells[1].firstChild.checked = true;
2864 if (row.cells[2] && row.cells[2].firstChild.tagName=='A')
2865 row.cells[2].firstChild.onclick = new Function(this.ref+".command('rename-folder','"+name.replace('\'','\\\'')+"')");
2866 if (row.cells[3] && row.cells[3].firstChild.tagName=='A')
2867 row.cells[3].firstChild.onclick = new Function(this.ref+".command('delete-folder','"+name.replace('\'','\\\'')+"')");
2869 // add new folder to rename-folder list and clear input field
2870 if (!replace && (form = this.gui_objects.editform))
2872 if (form.elements['_folder_oldname'])
2873 form.elements['_folder_oldname'].options[form.elements['_folder_oldname'].options.length] = new Option(name,name);
2874 if (form.elements['_folder_name'])
2875 form.elements['_folder_name'].value = '';
2881 // replace an existing table row with a new folder line
2882 this.replace_folder_row = function(newfolder, oldfolder)
2884 var id = this.get_folder_row_id(oldfolder);
2885 var row = document.getElementById(id);
2887 // replace an existing table row (if found)
2888 this.add_folder_row(newfolder, row);
2889 this.env.subscriptionrows[id] = null;
2891 // rename folder in rename-folder dropdown
2893 if ((form = this.gui_objects.editform) && (elm = form.elements['_folder_oldname']))
2895 for (var i=0;i<elm.options.length;i++)
2897 if (elm.options[i].value == oldfolder)
2899 elm.options[i].text = newfolder;
2900 elm.options[i].value = newfolder;
2905 form.elements['_folder_newname'].value = '';
2910 // remove the table row of a specific mailbox from the table
2911 // (the row will not be removed, just hidden)
2912 this.remove_folder_row = function(folder)
2915 var id = this.get_folder_row_id(folder);
2916 if (id && (row = document.getElementById(id)))
2917 row.style.display = 'none';
2919 // remove folder from rename-folder list
2921 if ((form = this.gui_objects.editform) && form.elements['_folder_oldname'])
2923 for (var i=0;i<form.elements['_folder_oldname'].options.length;i++)
2925 if (form.elements['_folder_oldname'].options[i].value == folder)
2927 form.elements['_folder_oldname'].options[i] = null;
2933 if (form && form.elements['_folder_newname'])
2934 form.elements['_folder_newname'].value = '';
2938 this.subscribe_folder = function(folder)
2941 if ((form = this.gui_objects.editform) && form.elements['_unsubscribed'])
2942 this.change_subscription('_unsubscribed', '_subscribed', 'subscribe');
2944 this.http_request('subscribe', '_mboxes='+escape(folder));
2948 this.unsubscribe_folder = function(folder)
2951 if ((form = this.gui_objects.editform) && form.elements['_subscribed'])
2952 this.change_subscription('_subscribed', '_unsubscribed', 'unsubscribe');
2954 this.http_request('unsubscribe', '_mboxes='+escape(folder));
2958 this.change_subscription = function(from, to, action)
2961 if (form = this.gui_objects.editform)
2963 var a_folders = new Array();
2964 var list_from = form.elements[from];
2966 for (var i=0; list_from && i<list_from.options.length; i++)
2968 if (list_from.options[i] && list_from.options[i].selected)
2970 a_folders[a_folders.length] = list_from.options[i].value;
2971 list_from[i] = null;
2976 // yes, we have some folders selected
2977 if (a_folders.length)
2979 var list_to = form.elements[to];
2982 for (var n=0; n<a_folders.length; n++)
2984 index = list_to.options.length;
2985 list_to[index] = new Option(a_folders[n]);
2988 this.http_request(action, '_mboxes='+escape(a_folders.join(',')));
2994 // helper method to find a specific mailbox row ID
2995 this.get_folder_row_id = function(folder)
2997 for (var id in this.env.subscriptionrows)
2998 if (this.env.subscriptionrows[id]==folder)
3004 // duplicate a specific table row
3005 this.clone_table_row = function(row)
3008 var new_row = document.createElement('TR');
3009 for(var n=0; n<row.childNodes.length; n++)
3011 cell = row.childNodes[n];
3012 td = document.createElement('TD');
3015 td.className = cell.className;
3017 td.setAttribute('align', cell.align);
3019 td.innerHTML = cell.innerHTML;
3020 new_row.appendChild(td);
3027 /*********************************************************/
3028 /********* GUI functionality *********/
3029 /*********************************************************/
3032 // eable/disable buttons for page shifting
3033 this.set_page_buttons = function()
3035 this.enable_command('nextpage', (this.env.pagecount > this.env.current_page));
3036 this.enable_command('previouspage', (this.env.current_page > 1));
3040 // set button to a specific state
3041 this.set_button = function(command, state)
3043 var a_buttons = this.buttons[command];
3046 if(!a_buttons || !a_buttons.length)
3049 for(var n=0; n<a_buttons.length; n++)
3051 button = a_buttons[n];
3052 obj = document.getElementById(button.id);
3054 // get default/passive setting of the button
3055 if (obj && button.type=='image' && !button.status)
3056 button.pas = obj._original_src ? obj._original_src : obj.src;
3057 else if (obj && !button.status)
3058 button.pas = String(obj.className);
3060 // set image according to button state
3061 if (obj && button.type=='image' && button[state])
3063 button.status = state;
3064 obj.src = button[state];
3066 // set class name according to button state
3067 else if (obj && typeof(button[state])!='undefined')
3069 button.status = state;
3070 obj.className = button[state];
3072 // disable/enable input buttons
3073 if (obj && button.type=='input')
3075 button.status = state;
3076 obj.disabled = !state;
3082 // mouse over button
3083 this.button_over = function(command, id)
3085 var a_buttons = this.buttons[command];
3088 if(!a_buttons || !a_buttons.length)
3091 for(var n=0; n<a_buttons.length; n++)
3093 button = a_buttons[n];
3094 if(button.id==id && button.status=='act')
3096 img = document.getElementById(button.id);
3097 if (img && button.over)
3098 img.src = button.over;
3103 // mouse down on button
3104 this.button_sel = function(command, id)
3106 var a_buttons = this.buttons[command];
3109 if(!a_buttons || !a_buttons.length)
3112 for(var n=0; n<a_buttons.length; n++)
3114 button = a_buttons[n];
3115 if(button.id==id && button.status=='act')
3117 img = document.getElementById(button.id);
3118 if (img && button.sel)
3119 img.src = button.sel;
3124 // mouse out of button
3125 this.button_out = function(command, id)
3127 var a_buttons = this.buttons[command];
3130 if(!a_buttons || !a_buttons.length)
3133 for(var n=0; n<a_buttons.length; n++)
3135 button = a_buttons[n];
3136 if(button.id==id && button.status=='act')
3138 img = document.getElementById(button.id);
3139 if (img && button.act)
3140 img.src = button.act;
3146 // set/unset a specific class name
3147 this.set_classname = function(obj, classname, set)
3149 var reg = new RegExp('\s*'+classname, 'i');
3150 if (!set && obj.className.match(reg))
3151 obj.className = obj.className.replace(reg, '');
3152 else if (set && !obj.className.match(reg))
3153 obj.className += ' '+classname;
3157 // display a specific alttext
3158 this.alttext = function(text)
3164 // display a system message
3165 this.display_message = function(msg, type, hold)
3167 this.set_busy(false);
3168 if (!this.loaded) // save message in order to display after page loaded
3170 this.pending_message = new Array(msg, type);
3174 if (!this.gui_objects.message)
3177 if (this.message_timer)
3178 clearTimeout(this.message_timer);
3182 cont = '<div class="'+type+'">'+cont+'</div>';
3184 this.gui_objects.message._rcube = this;
3185 this.gui_objects.message.innerHTML = cont;
3186 this.gui_objects.message.style.display = 'block';
3188 if (type!='loading')
3189 this.gui_objects.message.onmousedown = function(){ this._rcube.hide_message(); return true; };
3192 this.message_timer = setTimeout(this.ref+'.hide_message()', this.message_time);
3196 // make a message row disapear
3197 this.hide_message = function()
3199 if (this.gui_objects.message)
3201 this.gui_objects.message.style.display = 'none';
3202 this.gui_objects.message.onmousedown = null;
3207 // mark a mailbox as selected and set environment variable
3208 this.select_mailbox = function(mbox)
3210 if (this.gui_objects.mailboxlist )
3212 var item, reg, text_obj;
3213 var current_li = this.get_mailbox_li();
3214 var mbox_li = this.get_mailbox_li(mbox);
3218 this.set_classname(current_li, 'selected', false);
3219 this.set_classname(current_li, 'unfocused', false);
3222 if (mbox_li || this.env.mailbox == mbox)
3224 this.set_classname(mbox_li, 'unfocused', false);
3225 this.set_classname(mbox_li, 'selected', true);
3229 // also update mailbox name in window title
3232 var doc_title = String(document.title);
3233 var reg = new RegExp(this.env.mailbox.toLowerCase(), 'i');
3234 if (this.env.mailbox && doc_title.match(reg))
3235 document.title = doc_title.replace(reg, mbox).replace(/^\([0-9]+\)\s+/i, '');
3238 this.env.mailbox = mbox;
3242 // for reordering column array, Konqueror workaround
3243 this.set_message_coltypes = function(coltypes)
3245 this.coltypes = coltypes;
3247 // set correct list titles
3249 var thead = this.gui_objects.messagelist ? this.gui_objects.messagelist.tHead : null;
3250 for (var n=0; thead && n<this.coltypes.length; n++)
3252 col = this.coltypes[n];
3253 if ((cell = thead.rows[0].cells[n+1]) && (col=='from' || col=='to'))
3255 // if we have links for sorting, it's a bit more complicated...
3256 if (cell.firstChild && cell.firstChild.tagName=='A')
3258 cell.firstChild.innerHTML = this.get_label(this.coltypes[n]);
3259 cell.firstChild.onclick = function(){ return rcmail.command('sort', this.__col, this); };
3260 cell.firstChild.__col = col;
3263 cell.innerHTML = this.get_label(this.coltypes[n]);
3265 cell.id = 'rcmHead'+col;
3271 // create a table row in the message list
3272 this.add_message_row = function(uid, cols, flags, attachment, attop)
3274 if (!this.gui_objects.messagelist || !this.gui_objects.messagelist.tBodies[0])
3277 var tbody = this.gui_objects.messagelist.tBodies[0];
3278 var rowcount = tbody.rows.length;
3279 var even = rowcount%2;
3281 this.env.messages[uid] = {deleted:flags.deleted?1:0,
3282 replied:flags.replied?1:0,
3283 unread:flags.unread?1:0};
3285 var row = document.createElement('TR');
3286 row.id = 'rcmrow'+uid;
3287 row.className = 'message '+(even ? 'even' : 'odd')+(flags.unread ? ' unread' : '')+(flags.deleted ? ' deleted' : '');
3289 if (this.in_selection(uid))
3290 row.className += ' selected';
3292 var icon = flags.deleted && this.env.deletedicon ? this.env.deletedicon:
3293 (flags.unread && this.env.unreadicon ? this.env.unreadicon :
3294 (flags.replied && this.env.repliedicon ? this.env.repliedicon : this.env.messageicon));
3296 var col = document.createElement('TD');
3297 col.className = 'icon';
3298 col.innerHTML = icon ? '<img src="'+icon+'" alt="" border="0" />' : '';
3299 row.appendChild(col);
3301 // add each submitted col
3302 for (var n = 0; n < this.coltypes.length; n++)
3304 var c = this.coltypes[n];
3305 col = document.createElement('TD');
3306 col.className = String(c).toLowerCase();
3307 col.innerHTML = cols[c];
3308 row.appendChild(col);
3311 col = document.createElement('TD');
3312 col.className = 'icon';
3313 col.innerHTML = attachment && this.env.attachmenticon ? '<img src="'+this.env.attachmenticon+'" alt="" border="0" />' : '';
3314 row.appendChild(col);
3316 if (attop && tbody.rows.length)
3317 tbody.insertBefore(row, tbody.firstChild);
3319 tbody.appendChild(row);
3321 this.init_message_row(row);
3325 // replace content of row count display
3326 this.set_rowcount = function(text)
3328 if (this.gui_objects.countdisplay)
3329 this.gui_objects.countdisplay.innerHTML = text;
3331 // update page navigation buttons
3332 this.set_page_buttons();
3335 // replace content of quota display
3336 this.set_quota = function(text)
3338 if (this.gui_objects.quotadisplay)
3339 this.gui_objects.quotadisplay.innerHTML = text;
3343 // update the mailboxlist
3344 this.set_unread_count = function(mbox, count, set_title)
3346 if (!this.gui_objects.mailboxlist)
3349 if (mbox==this.env.mailbox)
3353 var item = this.get_mailbox_li(mbox);
3354 mbox = String(mbox).toLowerCase().replace(this.mbox_expression, '');
3356 if (item && item.className && item.className.indexOf('mailbox '+mbox)>=0)
3359 text_obj = item.firstChild;
3360 reg = /\s+\([0-9]+\)$/i;
3362 if (count && text_obj.innerHTML.match(reg))
3363 text_obj.innerHTML = text_obj.innerHTML.replace(reg, ' ('+count+')');
3365 text_obj.innerHTML += ' ('+count+')';
3367 text_obj.innerHTML = text_obj.innerHTML.replace(reg, '');
3369 // set the right classes
3370 this.set_classname(item, 'unread', count>0 ? true : false);
3373 // set unread count to window title
3374 reg = /^\([0-9]+\)\s+/i;
3375 if (set_title && document.title)
3377 var doc_title = String(document.title);
3379 if (count && doc_title.match(reg))
3380 document.title = doc_title.replace(reg, '('+count+') ');
3382 document.title = '('+count+') '+doc_title;
3384 document.title = doc_title.replace(reg, '');
3389 // add row to contacts list
3390 this.add_contact_row = function(cid, cols)
3392 if (!this.gui_objects.contactslist || !this.gui_objects.contactslist.tBodies[0])
3395 var tbody = this.gui_objects.contactslist.tBodies[0];
3396 var rowcount = tbody.rows.length;
3397 var even = rowcount%2;
3399 var row = document.createElement('TR');
3400 row.id = 'rcmrow'+cid;
3401 row.className = 'contact '+(even ? 'even' : 'odd');
3403 if (this.in_selection(cid))
3404 row.className += ' selected';
3406 // add each submitted col
3409 col = document.createElement('TD');
3410 col.className = String(c).toLowerCase();
3411 col.innerHTML = cols[c];
3412 row.appendChild(col);
3415 tbody.appendChild(row);
3416 this.init_table_row(row, 'contact_rows');
3421 /********************************************************/
3422 /********* drag & drop methods *********/
3423 /********************************************************/
3426 this.drag_mouse_move = function(e)
3428 if (this.drag_start)
3430 if (!this.draglayer)
3431 this.draglayer = new rcube_layer('rcmdraglayer', {x:0, y:0, width:300, vis:0, zindex:2000});
3433 // get subjects of selectedd messages
3435 var c, subject, obj;
3436 for(var n=0; n<this.selection.length; n++)
3438 if (n>12) // only show 12 lines
3444 if (this.message_rows[this.selection[n]].obj)
3446 obj = this.message_rows[this.selection[n]].obj;
3449 for(c=0; c<obj.childNodes.length; c++)
3450 if (!subject && obj.childNodes[c].nodeName=='TD' && obj.childNodes[c].firstChild && obj.childNodes[c].firstChild.nodeType==3)
3452 subject = obj.childNodes[c].firstChild.data;
3453 names += (subject.length > 50 ? subject.substring(0, 50)+'...' : subject) + '<br />';
3458 this.draglayer.write(names);
3459 this.draglayer.show(1);
3462 var pos = this.get_mouse_pos(e);
3463 this.draglayer.move(pos.x+20, pos.y-5);
3465 this.drag_start = false;
3466 this.drag_active = true;
3472 this.drag_mouse_up = function()
3474 document.onmousemove = null;
3476 if (this.draglayer && this.draglayer.visible)
3477 this.draglayer.show(0);
3479 this.drag_active = false;
3486 /********************************************************/
3487 /********* remote request methods *********/
3488 /********************************************************/
3491 this.http_sockets = new Array();
3493 // find a non-busy socket or create a new one
3494 this.get_request_obj = function()
3496 for (var n=0; n<this.http_sockets.length; n++)
3498 if (!this.http_sockets[n].busy)
3499 return this.http_sockets[n];
3502 // create a new XMLHTTP object
3503 var i = this.http_sockets.length;
3504 this.http_sockets[i] = new rcube_http_request();
3506 return this.http_sockets[i];
3510 // send a http request to the server
3511 this.http_request = function(action, querystring, lock)
3513 var request_obj = this.get_request_obj();
3514 querystring += '&_remote=1';
3516 // add timestamp to request url to avoid cacheing problems in Safari
3518 querystring += '&_ts='+(new Date().getTime());
3523 // prompt('request', this.env.comm_path+'&_action='+escape(action)+'&'+querystring);
3524 console('HTTP request: '+this.env.comm_path+'&_action='+escape(action)+'&'+querystring);
3527 this.set_busy(true);
3529 request_obj.__lock = lock ? true : false;
3530 request_obj.__action = action;
3531 request_obj.onerror = function(o){ rcube_webmail_client.http_error(o); };
3532 request_obj.oncomplete = function(o){ rcube_webmail_client.http_response(o); };
3533 request_obj.GET(this.env.comm_path+'&_action='+escape(action)+'&'+querystring);
3538 // handle HTTP response
3539 this.http_response = function(request_obj)
3541 var ctype = request_obj.get_header('Content-Type');
3543 ctype = String(ctype).toLowerCase();
3544 var ctype_array=ctype.split(";");
3545 ctype = ctype_array[0];
3548 this.set_busy(false);
3550 console(request_obj.get_text());
3552 // if we get javascript code from server -> execute it
3553 if (request_obj.get_text() && (ctype=='text/javascript' || ctype=='application/x-javascript'))
3554 eval(request_obj.get_text());
3556 // process the response data according to the sent action
3557 switch (request_obj.__action)
3561 if (this.env.action=='show')
3562 this.command('list');
3566 if (this.env.messagecount)
3567 this.enable_command('purge', (this.env.mailbox==this.env.trash_mailbox));
3570 this.enable_command('select-all', 'select-none', 'expunge', this.env.messagecount ? true : false);
3574 request_obj.reset();
3578 // handle HTTP request errors
3579 this.http_error = function(request_obj)
3581 //alert('Error sending request: '+request_obj.url);
3583 if (request_obj.__lock)
3584 this.set_busy(false);
3586 request_obj.reset();
3587 request_obj.__lock = false;
3591 // use an image to send a keep-alive siganl to the server
3592 this.send_keep_alive = function()
3595 this.http_request('keep-alive', '_t='+d.getTime());
3599 // send periodic request to check for recent messages
3600 this.check_for_recent = function()
3604 this.send_keep_alive();
3608 this.set_busy(true, 'checkingmail');
3610 this.http_request('check-recent', '_t='+d.getTime());
3614 /********************************************************/
3615 /********* helper methods *********/
3616 /********************************************************/
3618 // check if we're in show mode or if we have a unique selection
3619 // and return the message uid
3620 this.get_single_uid = function()
3622 return this.env.uid ? this.env.uid : (this.selection.length==1 ? this.selection[0] : null);
3625 // same as above but for contacts
3626 this.get_single_cid = function()
3628 return this.env.cid ? this.env.cid : (this.selection.length==1 ? this.selection[0] : null);
3632 /* deprecated methods
3634 // check if Shift-key is pressed on event
3635 this.check_shiftkey = function(e)
3637 if(!e && window.event)
3640 if(bw.linux && bw.ns4 && e.modifiers)
3642 else if((bw.ns4 && e.modifiers & Event.SHIFT_MASK) || (e && e.shiftKey))
3648 // check if Shift-key is pressed on event
3649 this.check_ctrlkey = function(e)
3651 if(!e && window.event)
3654 if(bw.linux && bw.ns4 && e.modifiers)
3657 return this.check_shiftkey(e);
3658 else if((bw.ns4 && e.modifiers & Event.CTRL_MASK) || (e && e.ctrlKey))
3665 // returns modifier key (constants defined at top of file)
3666 this.get_modifier = function(e)
3669 e = e || window.event;
3673 opcode += (e.metaKey && CONTROL_KEY) + (e.shiftKey && SHIFT_KEY);
3678 opcode += (e.ctrlKey && CONTROL_KEY) + (e.shiftKey && SHIFT_KEY);
3683 e.cancelBubble = true;
3684 e.returnValue = false;
3686 else if (e.preventDefault)
3691 this.get_mouse_pos = function(e)
3693 if(!e) e = window.event;
3694 var mX = (e.pageX) ? e.pageX : e.clientX;
3695 var mY = (e.pageY) ? e.pageY : e.clientY;
3697 if(document.body && document.all)
3699 mX += document.body.scrollLeft;
3700 mY += document.body.scrollTop;
3703 return { x:mX, y:mY };
3707 this.get_caret_pos = function(obj)
3709 if (typeof(obj.selectionEnd)!='undefined')
3710 return obj.selectionEnd;
3712 else if (document.selection && document.selection.createRange)
3714 var range = document.selection.createRange();
3715 if (range.parentElement()!=obj)
3718 var gm = range.duplicate();
3719 if (obj.tagName=='TEXTAREA')
3720 gm.moveToElementText(obj);
3722 gm.expand('textedit');
3724 gm.setEndPoint('EndToStart', range);
3725 var p = gm.text.length;
3727 return p<=obj.value.length ? p : -1;
3731 return obj.value.length;
3735 this.set_caret2start = function(obj)
3737 if (obj.createTextRange)
3739 var range = obj.createTextRange();
3740 range.collapse(true);
3743 else if (obj.setSelectionRange)
3744 obj.setSelectionRange(0,0);
3750 // set all fields of a form disabled
3751 this.lock_form = function(form, lock)
3753 if (!form || !form.elements)
3757 for (var n=0; n<form.elements.length; n++)
3759 type = form.elements[n];
3763 form.elements[n].disabled = lock;
3767 } // end object rcube_webmail
3771 // class for HTTP requests
3772 function rcube_http_request()
3776 this.xmlhttp = null;
3779 // reset object properties
3780 this.reset = function()
3782 // set unassigned event handlers
3783 this.onloading = function(){ };
3784 this.onloaded = function(){ };
3785 this.oninteractive = function(){ };
3786 this.oncomplete = function(){ };
3787 this.onabort = function(){ };
3788 this.onerror = function(){ };
3792 this.xmlhttp = null;
3796 // create HTMLHTTP object
3797 this.build = function()
3799 if (window.XMLHttpRequest)
3800 this.xmlhttp = new XMLHttpRequest();
3801 else if (window.ActiveXObject)
3802 this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
3810 this.GET = function(url)
3824 this.xmlhttp.onreadystatechange = function(){ ref.xmlhttp_onreadystatechange(); };
3825 this.xmlhttp.open('GET', url);
3826 this.xmlhttp.send(null);
3830 this.POST = function(url, a_param)
3832 // not implemented yet
3836 // handle onreadystatechange event
3837 this.xmlhttp_onreadystatechange = function()
3839 if(this.xmlhttp.readyState == 1)
3840 this.onloading(this);
3842 else if(this.xmlhttp.readyState == 2)
3843 this.onloaded(this);
3845 else if(this.xmlhttp.readyState == 3)
3846 this.oninteractive(this);
3848 else if(this.xmlhttp.readyState == 4)
3851 if (this.xmlhttp.status == 0)
3853 else if(this.xmlhttp.status == 200)
3854 this.oncomplete(this);
3868 // getter method for HTTP headers
3869 this.get_header = function(name)
3871 return this.xmlhttp.getResponseHeader(name);
3874 this.get_text = function()
3876 return this.xmlhttp.responseText;
3879 this.get_xml = function()
3881 return this.xmlhttp.responseXML;
3886 } // end class rcube_http_request
3890 function console(str)
3892 if (document.debugform && document.debugform.console)
3893 document.debugform.console.value += str+'\n--------------------------------------\n';
3897 // set onload handler
3898 window.onload = function(e)
3900 if (window.rcube_webmail_client)
3901 rcube_webmail_client.init();