2 +-----------------------------------------------------------------------+
3 | Roundcube Webmail Client Script |
5 | This file is part of the Roundcube Webmail client |
6 | Copyright (C) 2005-2010, Roundcube Dev, - Switzerland |
7 | Licensed under the GNU GPL |
9 +-----------------------------------------------------------------------+
10 | Authors: Thomas Bruederli <roundcube@gmail.com> |
11 | Aleksander 'A.L.E.C' Machniak <alec@alec.pl> |
12 | Charles McNulty <charles@charlesmcnulty.com> |
13 +-----------------------------------------------------------------------+
14 | Requires: jquery.js, common.js, list.js |
15 +-----------------------------------------------------------------------+
17 $Id: app.js 4763 2011-05-13 17:31:09Z alec $
21 function rcube_webmail()
26 this.buttons_sel = {};
27 this.gui_objects = {};
28 this.gui_containers = {};
30 this.command_handlers = {};
34 // create protected reference to myself
38 // webmail client settings
39 this.dblclick_time = 500;
40 this.message_time = 2000;
42 this.identifier_expr = new RegExp('[^0-9a-z\-_]', 'gi');
44 // mimetypes supported by the browser (default settings)
45 this.mimetypes = new Array('text/plain', 'text/html', 'text/xml',
46 'image/jpeg', 'image/gif', 'image/png',
47 'application/x-javascript', 'application/pdf', 'application/x-shockwave-flash');
49 // default environment vars
50 this.env.keep_alive = 60; // seconds
51 this.env.request_timeout = 180; // seconds
52 this.env.draft_autosave = 0; // seconds
53 this.env.comm_path = './';
54 this.env.blankpage = 'program/blank.gif';
56 // set jQuery ajax options
59 error:function(request, status, err){ ref.http_error(request, status, err); },
60 beforeSend:function(xmlhttp){ xmlhttp.setRequestHeader('X-Roundcube-Request', ref.env.request_token); }
63 // set environment variable(s)
64 this.set_env = function(p, value)
66 if (p != null && typeof(p) == 'object' && !value)
73 // add a localized label to the client environment
74 this.add_label = function(key, value)
76 this.labels[key] = value;
79 // add a button to the button list
80 this.register_button = function(command, id, type, act, sel, over)
82 if (!this.buttons[command])
83 this.buttons[command] = [];
85 var button_prop = {id:id, type:type};
86 if (act) button_prop.act = act;
87 if (sel) button_prop.sel = sel;
88 if (over) button_prop.over = over;
90 this.buttons[command].push(button_prop);
93 // register a specific gui object
94 this.gui_object = function(name, id)
96 this.gui_objects[name] = id;
99 // register a container object
100 this.gui_container = function(name, id)
102 this.gui_containers[name] = id;
105 // add a GUI element (html node) to a specified container
106 this.add_element = function(elm, container)
108 if (this.gui_containers[container] && this.gui_containers[container].jquery)
109 this.gui_containers[container].append(elm);
112 // register an external handler for a certain command
113 this.register_command = function(command, callback, enable)
115 this.command_handlers[command] = callback;
118 this.enable_command(command, true);
121 // execute the given script on load
122 this.add_onload = function(f)
124 this.onloads.push(f);
127 // initialize webmail client
128 this.init = function()
131 this.task = this.env.task;
134 if (!bw.dom || !bw.xmlhttp_test()) {
135 this.goto_url('error', '_code=0x199');
139 // find all registered gui containers
140 for (var n in this.gui_containers)
141 this.gui_containers[n] = $('#'+this.gui_containers[n]);
143 // find all registered gui objects
144 for (var n in this.gui_objects)
145 this.gui_objects[n] = rcube_find_object(this.gui_objects[n]);
147 // init registered buttons
150 // tell parent window that this frame is loaded
151 if (this.is_framed()) {
152 parent.rcmail.set_busy(false, null, parent.rcmail.env.frame_lock);
153 parent.rcmail.env.frame_lock = null;
156 // enable general commands
157 this.enable_command('logout', 'mail', 'addressbook', 'settings', true);
159 if (this.env.permaurl)
160 this.enable_command('permaurl', true);
165 // enable mail commands
166 this.enable_command('list', 'checkmail', 'compose', 'add-contact', 'search', 'reset-search', 'collapse-folder', true);
168 if (this.gui_objects.messagelist) {
170 this.message_list = new rcube_list_widget(this.gui_objects.messagelist, {
171 multiselect:true, multiexpand:true, draggable:true, keyboard:true,
172 column_movable:this.env.col_movable, dblclick_time:this.dblclick_time
174 this.message_list.row_init = function(o){ p.init_message_row(o); };
175 this.message_list.addEventListener('dblclick', function(o){ p.msglist_dbl_click(o); });
176 this.message_list.addEventListener('click', function(o){ p.msglist_click(o); });
177 this.message_list.addEventListener('keypress', function(o){ p.msglist_keypress(o); });
178 this.message_list.addEventListener('select', function(o){ p.msglist_select(o); });
179 this.message_list.addEventListener('dragstart', function(o){ p.drag_start(o); });
180 this.message_list.addEventListener('dragmove', function(e){ p.drag_move(e); });
181 this.message_list.addEventListener('dragend', function(e){ p.drag_end(e); });
182 this.message_list.addEventListener('expandcollapse', function(e){ p.msglist_expand(e); });
183 this.message_list.addEventListener('column_replace', function(e){ p.msglist_set_coltypes(e); });
185 document.onmouseup = function(e){ return p.doc_mouse_up(e); };
186 this.gui_objects.messagelist.parentNode.onmousedown = function(e){ return p.click_on_list(e); };
188 this.message_list.init();
189 this.enable_command('toggle_status', 'toggle_flag', 'menu-open', 'menu-save', true);
192 this.command('list');
195 if (this.gui_objects.qsearchbox) {
196 if (this.env.search_text != null) {
197 this.gui_objects.qsearchbox.value = this.env.search_text;
199 $(this.gui_objects.qsearchbox).focusin(function() { rcmail.message_list.blur(); });
202 if (this.env.trash_mailbox && this.env.mailbox != this.env.trash_mailbox)
203 this.set_alttext('delete', 'movemessagetotrash');
205 this.env.message_commands = ['show', 'reply', 'reply-all', 'reply-list', 'forward',
206 'moveto', 'copy', 'delete', 'open', 'mark', 'edit', 'viewsource', 'download',
207 'print', 'load-attachment', 'load-headers'];
209 if (this.env.action=='show' || this.env.action=='preview') {
210 this.enable_command(this.env.message_commands, this.env.uid);
211 this.enable_command('reply-list', this.env.list_post);
213 if (this.env.action == 'show') {
214 this.http_request('pagenav', '_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox),
215 this.display_message('', 'loading'));
218 if (this.env.blockedobjects) {
219 if (this.gui_objects.remoteobjectsmsg)
220 this.gui_objects.remoteobjectsmsg.style.display = 'block';
221 this.enable_command('load-images', 'always-load', true);
224 // make preview/message frame visible
225 if (this.env.action == 'preview' && this.is_framed()) {
226 this.enable_command('compose', 'add-contact', false);
227 parent.rcmail.show_contentframe(true);
230 else if (this.env.action == 'compose') {
231 this.env.compose_commands = ['send-attachment', 'remove-attachment', 'send', 'toggle-editor'];
233 if (this.env.drafts_mailbox)
234 this.env.compose_commands.push('savedraft')
236 this.enable_command(this.env.compose_commands, 'identities', true);
238 if (this.env.spellcheck) {
239 this.env.spellcheck.spelling_state_observer = function(s){ ref.set_spellcheck_state(s); };
240 this.env.compose_commands.push('spellcheck')
241 this.set_spellcheck_state('ready');
242 if ($("input[name='_is_html']").val() == '1')
243 this.display_spellcheck_controls(false);
246 document.onmouseup = function(e){ return p.doc_mouse_up(e); };
248 // init message compose form
249 this.init_messageform();
251 // show printing dialog
252 else if (this.env.action == 'print' && this.env.uid)
255 // get unread count for each mailbox
256 if (this.gui_objects.mailboxlist) {
257 this.env.unread_counts = {};
258 this.gui_objects.folderlist = this.gui_objects.mailboxlist;
259 this.http_request('getunread', '');
262 // ask user to send MDN
263 if (this.env.mdn_request && this.env.uid) {
264 var mdnurl = '_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox);
265 if (confirm(this.get_label('mdnrequest')))
266 this.http_post('sendmdn', mdnurl);
268 this.http_post('mark', mdnurl+'&_flag=mdnsent');
275 if (this.gui_objects.folderlist)
276 this.env.contactfolders = $.extend($.extend({}, this.env.address_sources), this.env.contactgroups);
278 if (this.gui_objects.contactslist) {
280 this.contact_list = new rcube_list_widget(this.gui_objects.contactslist,
281 {multiselect:true, draggable:this.gui_objects.folderlist?true:false, keyboard:true});
282 this.contact_list.row_init = function(row){ p.triggerEvent('insertrow', { cid:row.uid, row:row }); };
283 this.contact_list.addEventListener('keypress', function(o){ p.contactlist_keypress(o); });
284 this.contact_list.addEventListener('select', function(o){ p.contactlist_select(o); });
285 this.contact_list.addEventListener('dragstart', function(o){ p.drag_start(o); });
286 this.contact_list.addEventListener('dragmove', function(e){ p.drag_move(e); });
287 this.contact_list.addEventListener('dragend', function(e){ p.drag_end(e); });
288 this.contact_list.init();
291 this.contact_list.highlight_row(this.env.cid);
293 this.gui_objects.contactslist.parentNode.onmousedown = function(e){ return p.click_on_list(e); };
294 document.onmouseup = function(e){ return p.doc_mouse_up(e); };
295 if (this.gui_objects.qsearchbox) {
296 $(this.gui_objects.qsearchbox).focusin(function() { rcmail.contact_list.blur(); });
300 this.set_page_buttons();
302 if (this.env.address_sources && this.env.address_sources[this.env.source] && !this.env.address_sources[this.env.source].readonly) {
303 this.enable_command('add', 'import', true);
304 this.enable_command('group-create', this.env.address_sources[this.env.source].groups);
308 this.enable_command('show', 'edit', true);
309 // register handlers for group assignment via checkboxes
310 if (this.gui_objects.editform) {
311 $('input.groupmember').change(function(){
312 var cmd = this.checked ? 'group-addmembers' : 'group-delmembers';
313 ref.http_post(cmd, '_cid='+urlencode(ref.env.cid)
314 + '&_source='+urlencode(ref.env.source)
315 + '&_gid='+urlencode(this.value));
320 if ((this.env.action=='add' || this.env.action=='edit') && this.gui_objects.editform) {
321 this.enable_command('save', true);
322 $("input[type='text']").first().select();
324 else if (this.gui_objects.qsearchbox) {
325 this.enable_command('search', 'reset-search', 'moveto', true);
326 $(this.gui_objects.qsearchbox).select();
329 if (this.contact_list && this.contact_list.rowcount > 0)
330 this.enable_command('export', true);
332 this.enable_command('list', 'listgroup', true);
337 this.enable_command('preferences', 'identities', 'save', 'folders', true);
339 if (this.env.action=='identities') {
340 this.enable_command('add', this.env.identities_level < 2);
342 else if (this.env.action=='edit-identity' || this.env.action=='add-identity') {
343 this.enable_command('add', this.env.identities_level < 2);
344 this.enable_command('save', 'delete', 'edit', 'toggle-editor', true);
346 else if (this.env.action=='folders') {
347 this.enable_command('subscribe', 'unsubscribe', 'create-folder', 'rename-folder', true);
349 else if (this.env.action == 'edit-folder' && this.gui_objects.editform) {
350 this.enable_command('save', 'folder-size', true);
351 parent.rcmail.env.messagecount = this.env.messagecount;
352 parent.rcmail.enable_command('purge', this.env.messagecount);
353 $("input[type='text']").first().select();
356 if (this.gui_objects.identitieslist) {
357 this.identity_list = new rcube_list_widget(this.gui_objects.identitieslist, {multiselect:false, draggable:false, keyboard:false});
358 this.identity_list.addEventListener('select', function(o){ p.identity_select(o); });
359 this.identity_list.init();
360 this.identity_list.focus();
363 this.identity_list.highlight_row(this.env.iid);
365 else if (this.gui_objects.sectionslist) {
366 this.sections_list = new rcube_list_widget(this.gui_objects.sectionslist, {multiselect:false, draggable:false, keyboard:false});
367 this.sections_list.addEventListener('select', function(o){ p.section_select(o); });
368 this.sections_list.init();
369 this.sections_list.focus();
371 else if (this.gui_objects.subscriptionlist)
372 this.init_subscription_list();
377 var input_user = $('#rcmloginuser');
378 input_user.bind('keyup', function(e){ return rcmail.login_user_keyup(e); });
380 if (input_user.val() == '')
383 $('#rcmloginpwd').focus();
385 // detect client timezone
386 $('#rcmlogintz').val(new Date().getTimezoneOffset() / -60);
388 // display 'loading' message on form submit, lock submit button
389 $('form').submit(function () {
390 $('input[type=submit]', this).attr('disabled', true);
391 rcmail.display_message('', 'loading');
394 this.enable_command('login', true);
401 // flag object as complete
405 if (this.pending_message)
406 this.display_message(this.pending_message[0], this.pending_message[1]);
408 // map implicit containers
409 if (this.gui_objects.folderlist)
410 this.gui_containers.foldertray = $(this.gui_objects.folderlist);
412 // trigger init event hook
413 this.triggerEvent('init', { task:this.task, action:this.env.action });
415 // execute all foreign onload scripts
417 for (var i in this.onloads) {
418 if (typeof(this.onloads[i]) == 'string')
419 eval(this.onloads[i]);
420 else if (typeof(this.onloads[i]) == 'function')
424 // start keep-alive interval
425 this.start_keepalive();
429 /*********************************************************/
430 /********* client command interface *********/
431 /*********************************************************/
433 // execute a specific command on the web client
434 this.command = function(command, props, obj)
442 // command not supported or allowed
443 if (!this.commands[command]) {
444 // pass command to parent window
445 if (this.is_framed())
446 parent.rcmail.command(command, props);
451 // check input before leaving compose step
452 if (this.task=='mail' && this.env.action=='compose' && $.inArray(command, this.env.compose_commands)<0) {
453 if (this.cmp_hash != this.compose_field_hash() && !confirm(this.get_label('notsentwarning')))
457 // process external commands
458 if (typeof this.command_handlers[command] == 'function') {
459 var ret = this.command_handlers[command](props, obj);
460 return ret !== null ? ret : (obj ? false : true);
462 else if (typeof this.command_handlers[command] == 'string') {
463 var ret = window[this.command_handlers[command]](props, obj);
464 return ret !== null ? ret : (obj ? false : true);
467 // trigger plugin hooks
468 this.triggerEvent('actionbefore', {props:props, action:command});
469 var event_ret = this.triggerEvent('before'+command, props);
470 if (typeof event_ret != 'undefined') {
471 // abort if one the handlers returned false
472 if (event_ret === false)
478 // process internal command
482 if (this.gui_objects.loginform)
483 this.gui_objects.loginform.submit();
486 // commands to switch task
491 this.switch_task(command);
495 if (obj && obj.href && obj.target)
497 else if (this.env.permaurl)
498 parent.location.href = this.env.permaurl;
503 this.triggerEvent(command, {props:props});
508 if (uid = this.get_single_uid()) {
509 obj.href = '?_task='+this.env.task+'&_action=show&_mbox='+urlencode(this.env.mailbox)+'&_uid='+uid;
515 if (this.task=='mail') {
516 if (!this.env.search_request || (props && props != this.env.mailbox))
517 this.reset_qsearch();
519 this.list_mailbox(props);
521 if (this.env.trash_mailbox)
522 this.set_alttext('delete', this.env.mailbox != this.env.trash_mailbox ? 'movemessagetotrash' : 'deletemessage');
524 else if (this.task=='addressbook') {
525 if (!this.env.search_request || (props != this.env.source))
526 this.reset_qsearch();
528 this.list_contacts(props);
529 this.enable_command('add', 'import', (this.env.address_sources && !this.env.address_sources[this.env.source].readonly));
534 this.load_headers(obj);
538 var sort_order, sort_col = props;
540 if (this.env.sort_col==sort_col)
541 sort_order = this.env.sort_order=='ASC' ? 'DESC' : 'ASC';
545 // set table header and update env
546 this.set_list_sorting(sort_col, sort_order);
548 // reload message list
549 this.list_mailbox('', '', sort_col+'_'+sort_order);
553 this.list_page('next');
557 this.list_page('last');
561 this.list_page('prev');
565 this.list_page('first');
569 if (this.env.messagecount)
570 this.expunge_mailbox(this.env.mailbox);
574 case 'empty-mailbox':
575 if (this.env.messagecount)
576 this.purge_mailbox(this.env.mailbox);
579 // common commands used in multiple tasks
581 if (this.task=='mail') {
582 var uid = this.get_single_uid();
583 if (uid && (!this.env.uid || uid != this.env.uid)) {
584 if (this.env.mailbox == this.env.drafts_mailbox)
585 this.goto_url('compose', '_draft_uid='+uid+'&_mbox='+urlencode(this.env.mailbox), true);
587 this.show_message(uid);
590 else if (this.task=='addressbook') {
591 var cid = props ? props : this.get_single_cid();
592 if (cid && !(this.env.action=='show' && cid==this.env.cid))
593 this.load_contact(cid, 'show');
598 if (this.task=='addressbook')
599 this.load_contact(0, 'add');
600 else if (this.task=='settings') {
601 this.identity_list.clear_selection();
602 this.load_identity(0, 'add-identity');
608 if (this.task=='addressbook' && (cid = this.get_single_cid()))
609 this.load_contact(cid, 'edit');
610 else if (this.task=='settings' && props)
611 this.load_identity(props, 'edit-identity');
612 else if (this.task=='mail' && (cid = this.get_single_uid())) {
613 var url = (this.env.mailbox == this.env.drafts_mailbox) ? '_draft_uid=' : '_uid=';
614 this.goto_url('compose', url+cid+'&_mbox='+urlencode(this.env.mailbox), true);
619 if (this.gui_objects.editform) {
620 var input_pagesize = $("input[name='_pagesize']");
621 var input_name = $("input[name='_name']");
622 var input_email = $("input[name='_email']");
625 if (input_pagesize.length && isNaN(parseInt(input_pagesize.val()))) {
626 alert(this.get_label('nopagesizewarning'));
627 input_pagesize.focus();
630 // contacts/identities
632 if (input_name.length && input_name.val() == '') {
633 alert(this.get_label('nonamewarning'));
637 else if (input_email.length && !rcube_check_email(input_email.val())) {
638 alert(this.get_label('noemailwarning'));
644 this.gui_objects.editform.submit();
650 if (this.task == 'mail')
651 this.delete_messages();
653 else if (this.task == 'addressbook')
654 this.delete_contacts();
655 // user settings task
656 else if (this.task == 'settings')
657 this.delete_identity();
660 // mail task commands
663 if (this.task == 'mail')
664 this.move_messages(props);
665 else if (this.task == 'addressbook' && this.drag_active)
666 this.copy_contact(null, props);
670 if (this.task == 'mail')
671 this.copy_messages(props);
676 this.mark_message(props);
679 case 'toggle_status':
680 if (props && !props._row)
683 var uid, flag = 'read';
685 if (props._row.uid) {
686 uid = props._row.uid;
688 // toggle read/unread
689 if (this.message_list.rows[uid].deleted) {
692 else if (!this.message_list.rows[uid].unread)
696 this.mark_message(flag, uid);
700 if (props && !props._row)
703 var uid, flag = 'flagged';
705 if (props._row.uid) {
706 uid = props._row.uid;
707 // toggle flagged/unflagged
708 if (this.message_list.rows[uid].flagged)
711 this.mark_message(flag, uid);
715 if (this.env.uid && this.env.sender) {
716 this.add_contact(urlencode(this.env.sender));
717 window.setTimeout(function(){ ref.command('load-images'); }, 300);
723 this.show_message(this.env.uid, true, this.env.action=='preview');
726 case 'load-attachment':
727 var qstring = '_mbox='+urlencode(this.env.mailbox)+'&_uid='+this.env.uid+'&_part='+props.part;
729 // open attachment in frame if it's of a supported mimetype
730 if (this.env.uid && props.mimetype && $.inArray(props.mimetype, this.mimetypes)>=0) {
731 if (props.mimetype == 'text/html')
732 qstring += '&_safe=1';
733 this.attachment_win = window.open(this.env.comm_path+'&_action=get&'+qstring+'&_frame=1', 'rcubemailattachment');
734 if (this.attachment_win) {
735 window.setTimeout(function(){ ref.attachment_win.focus(); }, 10);
740 this.goto_url('get', qstring+'&_download=1', false);
744 this.select_all_mode = props ? false : true;
745 this.dummy_select = true; // prevent msg opening if there's only one msg on the list
746 if (props == 'invert')
747 this.message_list.invert_selection();
749 this.message_list.select_all(props == 'page' ? '' : props);
750 this.dummy_select = null;
754 this.select_all_mode = false;
755 this.message_list.clear_selection();
759 this.env.autoexpand_threads = 1;
760 this.message_list.expand_all();
763 case 'expand-unread':
764 this.env.autoexpand_threads = 2;
765 this.message_list.collapse_all();
766 this.expand_unread();
770 this.env.autoexpand_threads = 0;
771 this.message_list.collapse_all();
775 if (this.env.next_uid)
776 this.show_message(this.env.next_uid, false, this.env.action=='preview');
780 if (this.env.last_uid)
781 this.show_message(this.env.last_uid);
784 case 'previousmessage':
785 if (this.env.prev_uid)
786 this.show_message(this.env.prev_uid, false, this.env.action=='preview');
790 if (this.env.first_uid)
791 this.show_message(this.env.first_uid);
795 this.check_for_recent(true);
799 var url = this.env.comm_path+'&_action=compose';
801 if (this.task=='mail') {
802 url += '&_mbox='+urlencode(this.env.mailbox);
804 if (this.env.mailbox==this.env.drafts_mailbox) {
806 if (uid = this.get_single_uid())
807 url += '&_draft_uid='+uid;
810 url += '&_to='+urlencode(props);
812 // modify url if we're in addressbook
813 else if (this.task=='addressbook') {
814 // switch to mail compose step directly
815 if (props && props.indexOf('@') > 0) {
816 url = this.get_task_url('mail', url);
817 this.redirect(url + '&_to='+urlencode(props));
821 // use contact_id passed as command parameter
825 // get selected contacts
826 else if (this.contact_list) {
827 var selection = this.contact_list.get_selection();
828 for (var n=0; n<selection.length; n++)
829 a_cids.push(selection[n]);
833 this.http_request('mailto', '_cid='+urlencode(a_cids.join(','))+'&_source='+urlencode(this.env.source), true);
838 // don't know if this is necessary...
839 url = url.replace(/&_framed=1/, '');
845 if (window.tinyMCE && tinyMCE.get(this.env.composebody)) {
846 tinyMCE.execCommand('mceSpellCheck', true);
848 else if (this.env.spellcheck && this.env.spellcheck.spellCheck && this.spellcheck_ready) {
849 this.env.spellcheck.spellCheck();
850 this.set_spellcheck_state('checking');
855 // Reset the auto-save timer
856 self.clearTimeout(this.save_timer);
858 if (!this.gui_objects.messageform)
861 // if saving Drafts is disabled in main.inc.php
862 // or if compose form did not change
863 if (!this.env.drafts_mailbox || this.cmp_hash == this.compose_field_hash())
866 var form = this.gui_objects.messageform,
867 msgid = this.set_busy(true, 'savingmessage');
869 form.target = "savetarget";
870 form._draft.value = '1';
871 form.action = this.add_url(form.action, '_unlock', msgid);
876 if (!this.gui_objects.messageform)
879 if (!this.check_compose_input())
882 // Reset the auto-save timer
883 self.clearTimeout(this.save_timer);
885 // all checks passed, send message
886 var form = this.gui_objects.messageform,
887 msgid = this.set_busy(true, 'sendingmessage');
889 form.target = 'savetarget';
890 form._draft.value = '';
891 form.action = this.add_url(form.action, '_unlock', msgid);
894 // clear timeout (sending could take longer)
895 clearTimeout(this.request_timer);
898 case 'send-attachment':
899 // Reset the auto-save timer
900 self.clearTimeout(this.save_timer);
902 this.upload_file(props)
906 this.change_identity($("[name='_from']")[0], true);
913 if (uid = this.get_single_uid()) {
914 var url = '_reply_uid='+uid+'&_mbox='+urlencode(this.env.mailbox);
915 if (command == 'reply-all')
916 // do reply-list, when list is detected and popup menu wasn't used
917 url += '&_all=' + (!props && this.commands['reply-list'] ? 'list' : 'all');
918 else if (command == 'reply-list')
921 this.goto_url('compose', url, true);
927 if (uid = this.get_single_uid())
928 this.goto_url('compose', '_forward_uid='+uid+'&_mbox='+urlencode(this.env.mailbox), true);
933 if (uid = this.get_single_uid()) {
934 ref.printwin = window.open(this.env.comm_path+'&_action=print&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)+(this.env.safemode ? '&_safe=1' : ''));
936 window.setTimeout(function(){ ref.printwin.focus(); }, 20);
937 if (this.env.action != 'show')
938 this.mark_message('read', uid);
945 if (uid = this.get_single_uid()) {
946 ref.sourcewin = window.open(this.env.comm_path+'&_action=viewsource&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox));
948 window.setTimeout(function(){ ref.sourcewin.focus(); }, 20);
954 if (uid = this.get_single_uid())
955 this.goto_url('viewsource', '&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)+'&_save=1');
960 if (!props && this.gui_objects.qsearchbox)
961 props = this.gui_objects.qsearchbox.value;
969 var s = this.env.search_request;
970 this.reset_qsearch();
972 if (s && this.env.mailbox)
973 this.list_mailbox(this.env.mailbox);
974 else if (s && this.task == 'addressbook')
975 this.list_contacts(this.env.source, this.env.group);
979 this.list_contacts(props.source, props.id);
983 if (this.env.action == 'import' && this.gui_objects.importform) {
984 var file = document.getElementById('rcmimportfile');
985 if (file && !file.value) {
986 alert(this.get_label('selectimportfile'));
989 this.gui_objects.importform.submit();
990 this.set_busy(true, 'importwait');
991 this.lock_form(this.gui_objects.importform, true);
994 this.goto_url('import', (this.env.source ? '_target='+urlencode(this.env.source)+'&' : ''));
998 if (this.contact_list.rowcount > 0) {
999 var add_url = (this.env.source ? '_source='+urlencode(this.env.source)+'&' : '');
1000 if (this.env.search_request)
1001 add_url += '_search='+this.env.search_request;
1003 this.goto_url('export', add_url);
1007 // user settings commands
1011 this.goto_url('settings/' + command);
1014 // unified command call (command name == function name)
1016 var func = command.replace(/-/g, '_');
1017 if (this[func] && typeof this[func] == 'function')
1022 this.triggerEvent('after'+command, props);
1023 this.triggerEvent('actionafter', {props:props, action:command});
1025 return obj ? false : true;
1028 // set command(s) enabled or disabled
1029 this.enable_command = function()
1031 var args = Array.prototype.slice.call(arguments),
1032 enable = args.pop(), cmd;
1034 for (var n=0; n<args.length; n++) {
1036 // argument of type array
1037 if (typeof cmd === 'string') {
1038 this.commands[cmd] = enable;
1039 this.set_button(cmd, (enable ? 'act' : 'pas'));
1041 // push array elements into commands array
1049 // lock/unlock interface
1050 this.set_busy = function(a, message, id)
1053 var msg = this.get_label(message);
1057 id = this.display_message(msg, 'loading');
1059 else if (!a && id) {
1060 this.hide_message(id);
1064 //document.body.style.cursor = a ? 'wait' : 'default';
1066 if (this.gui_objects.editform)
1067 this.lock_form(this.gui_objects.editform, a);
1069 // clear pending timer
1070 if (this.request_timer)
1071 clearTimeout(this.request_timer);
1073 // set timer for requests
1074 if (a && this.env.request_timeout)
1075 this.request_timer = window.setTimeout(function(){ ref.request_timed_out(); }, this.env.request_timeout * 1000);
1080 // return a localized string
1081 this.get_label = function(name, domain)
1083 if (domain && this.labels[domain+'.'+name])
1084 return this.labels[domain+'.'+name];
1085 else if (this.labels[name])
1086 return this.labels[name];
1091 // alias for convenience reasons
1092 this.gettext = this.get_label;
1094 // switch to another application task
1095 this.switch_task = function(task)
1097 if (this.task===task && task!='mail')
1100 var url = this.get_task_url(task);
1102 url += '&_mbox=INBOX';
1107 this.get_task_url = function(task, url)
1110 url = this.env.comm_path;
1112 return url.replace(/_task=[a-z]+/, '_task='+task);
1115 // called when a request timed out
1116 this.request_timed_out = function()
1118 this.set_busy(false);
1119 this.display_message('Request timed out!', 'error');
1122 this.reload = function(delay)
1124 if (this.is_framed())
1125 parent.rcmail.reload(delay);
1127 window.setTimeout(function(){ rcmail.reload(); }, delay);
1128 else if (window.location)
1129 location.href = this.env.comm_path + (this.env.action ? '&_action='+this.env.action : '');
1132 // Add variable to GET string, replace old value if exists
1133 this.add_url = function(url, name, value)
1135 value = urlencode(value);
1137 if (/(\?.*)$/.test(url)) {
1138 var urldata = RegExp.$1,
1139 datax = RegExp('((\\?|&)'+RegExp.escape(name)+'=[^&]*)');
1141 if (datax.test(urldata)) {
1142 urldata = urldata.replace(datax, RegExp.$2 + name + '=' + value);
1145 urldata += '&' + name + '=' + value
1147 return url.replace(/(\?.*)$/, urldata);
1150 return url + '?' + name + '=' + value;
1153 this.is_framed = function()
1155 return (this.env.framed && parent.rcmail);
1159 /*********************************************************/
1160 /********* event handling methods *********/
1161 /*********************************************************/
1163 this.drag_menu = function(e, target)
1165 var modkey = rcube_event.get_modifier(e),
1166 menu = $('#'+this.gui_objects.message_dragmenu);
1168 if (menu && modkey == SHIFT_KEY && this.commands['copy']) {
1169 var pos = rcube_event.get_mouse_pos(e);
1170 this.env.drag_target = target;
1171 menu.css({top: (pos.y-10)+'px', left: (pos.x-10)+'px'}).show();
1178 this.drag_menu_action = function(action)
1180 var menu = $('#'+this.gui_objects.message_dragmenu);
1184 this.command(action, this.env.drag_target);
1185 this.env.drag_target = null;
1188 this.drag_start = function(list)
1190 var model = this.task == 'mail' ? this.env.mailboxes : this.env.contactfolders;
1192 this.drag_active = true;
1194 if (this.preview_timer)
1195 clearTimeout(this.preview_timer);
1196 if (this.preview_read_timer)
1197 clearTimeout(this.preview_read_timer);
1199 // save folderlist and folders location/sizes for droptarget calculation in drag_move()
1200 if (this.gui_objects.folderlist && model) {
1201 this.initialBodyScrollTop = bw.ie ? 0 : window.pageYOffset;
1202 this.initialListScrollTop = this.gui_objects.folderlist.parentNode.scrollTop;
1204 var li, pos, list, height;
1205 list = $(this.gui_objects.folderlist);
1206 pos = list.offset();
1207 this.env.folderlist_coords = { x1:pos.left, y1:pos.top, x2:pos.left + list.width(), y2:pos.top + list.height() };
1209 this.env.folder_coords = [];
1210 for (var k in model) {
1211 if (li = this.get_folder_li(k)) {
1212 // only visible folders
1213 if (height = li.firstChild.offsetHeight) {
1214 pos = $(li.firstChild).offset();
1215 this.env.folder_coords[k] = { x1:pos.left, y1:pos.top,
1216 x2:pos.left + li.firstChild.offsetWidth, y2:pos.top + height, on:0 };
1223 this.drag_end = function(e)
1225 this.drag_active = false;
1226 this.env.last_folder_target = null;
1228 if (this.folder_auto_timer) {
1229 window.clearTimeout(this.folder_auto_timer);
1230 this.folder_auto_timer = null;
1231 this.folder_auto_expand = null;
1235 if (this.gui_objects.folderlist && this.env.folder_coords) {
1236 for (var k in this.env.folder_coords) {
1237 if (this.env.folder_coords[k].on)
1238 $(this.get_folder_li(k)).removeClass('droptarget');
1243 this.drag_move = function(e)
1245 if (this.gui_objects.folderlist && this.env.folder_coords) {
1246 // offsets to compensate for scrolling while dragging a message
1247 var boffset = bw.ie ? -document.documentElement.scrollTop : this.initialBodyScrollTop;
1248 var moffset = this.initialListScrollTop-this.gui_objects.folderlist.parentNode.scrollTop;
1249 var toffset = -moffset-boffset;
1250 var li, div, pos, mouse, check, oldclass,
1251 layerclass = 'draglayernormal';
1253 if (this.contact_list && this.contact_list.draglayer)
1254 oldclass = this.contact_list.draglayer.attr('class');
1256 mouse = rcube_event.get_mouse_pos(e);
1257 pos = this.env.folderlist_coords;
1260 // if mouse pointer is outside of folderlist
1261 if (mouse.x < pos.x1 || mouse.x >= pos.x2 || mouse.y < pos.y1 || mouse.y >= pos.y2) {
1262 if (this.env.last_folder_target) {
1263 $(this.get_folder_li(this.env.last_folder_target)).removeClass('droptarget');
1264 this.env.folder_coords[this.env.last_folder_target].on = 0;
1265 this.env.last_folder_target = null;
1267 if (layerclass != oldclass && this.contact_list && this.contact_list.draglayer)
1268 this.contact_list.draglayer.attr('class', layerclass);
1273 for (var k in this.env.folder_coords) {
1274 pos = this.env.folder_coords[k];
1275 if (mouse.x >= pos.x1 && mouse.x < pos.x2 && mouse.y >= pos.y1 && mouse.y < pos.y2){
1276 if ((check = this.check_droptarget(k))) {
1277 li = this.get_folder_li(k);
1278 div = $(li.getElementsByTagName('div')[0]);
1280 // if the folder is collapsed, expand it after 1sec and restart the drag & drop process.
1281 if (div.hasClass('collapsed')) {
1282 if (this.folder_auto_timer)
1283 window.clearTimeout(this.folder_auto_timer);
1285 this.folder_auto_expand = k;
1286 this.folder_auto_timer = window.setTimeout(function() {
1287 rcmail.command('collapse-folder', rcmail.folder_auto_expand);
1288 rcmail.drag_start(null);
1290 } else if (this.folder_auto_timer) {
1291 window.clearTimeout(this.folder_auto_timer);
1292 this.folder_auto_timer = null;
1293 this.folder_auto_expand = null;
1296 $(li).addClass('droptarget');
1297 this.env.folder_coords[k].on = 1;
1298 this.env.last_folder_target = k;
1299 layerclass = 'draglayer' + (check > 1 ? 'copy' : 'normal');
1300 } else { // Clear target, otherwise drag end will trigger move into last valid droptarget
1301 this.env.last_folder_target = null;
1305 $(this.get_folder_li(k)).removeClass('droptarget');
1306 this.env.folder_coords[k].on = 0;
1310 if (layerclass != oldclass && this.contact_list && this.contact_list.draglayer)
1311 this.contact_list.draglayer.attr('class', layerclass);
1315 this.collapse_folder = function(id)
1317 var li = this.get_folder_li(id),
1318 div = $(li.getElementsByTagName('div')[0]);
1320 if (!div || (!div.hasClass('collapsed') && !div.hasClass('expanded')))
1323 var ul = $(li.getElementsByTagName('ul')[0]);
1325 if (div.hasClass('collapsed')) {
1327 div.removeClass('collapsed').addClass('expanded');
1328 var reg = new RegExp('&'+urlencode(id)+'&');
1329 this.set_env('collapsed_folders', this.env.collapsed_folders.replace(reg, ''));
1333 div.removeClass('expanded').addClass('collapsed');
1334 this.set_env('collapsed_folders', this.env.collapsed_folders+'&'+urlencode(id)+'&');
1336 // select parent folder if one of its childs is currently selected
1337 if (this.env.mailbox.indexOf(id + this.env.delimiter) == 0)
1338 this.command('list', id);
1341 // Work around a bug in IE6 and IE7, see #1485309
1342 if (bw.ie6 || bw.ie7) {
1343 var siblings = li.nextSibling ? li.nextSibling.getElementsByTagName('ul') : null;
1344 if (siblings && siblings.length && (li = siblings[0]) && li.style && li.style.display != 'none') {
1345 li.style.display = 'none';
1346 li.style.display = '';
1350 this.http_post('save-pref', '_name=collapsed_folders&_value='+urlencode(this.env.collapsed_folders));
1351 this.set_unread_count_display(id, false);
1354 this.doc_mouse_up = function(e)
1356 var model, list, li, id;
1358 if (list = this.message_list) {
1359 if (!rcube_mouse_is_over(e, list.list.parentNode))
1363 model = this.env.mailboxes;
1365 else if (list = this.contact_list) {
1366 if (!rcube_mouse_is_over(e, list.list.parentNode))
1370 model = this.env.contactfolders;
1372 else if (this.ksearch_value) {
1373 this.ksearch_blur();
1376 // handle mouse release when dragging
1377 if (this.drag_active && model && this.env.last_folder_target) {
1378 var target = model[this.env.last_folder_target];
1380 $(this.get_folder_li(this.env.last_folder_target)).removeClass('droptarget');
1381 this.env.last_folder_target = null;
1382 list.draglayer.hide();
1384 if (!this.drag_menu(e, target))
1385 this.command('moveto', target);
1388 // reset 'pressed' buttons
1389 if (this.buttons_sel) {
1390 for (id in this.buttons_sel)
1391 if (typeof id != 'function')
1392 this.button_out(this.buttons_sel[id], id);
1393 this.buttons_sel = {};
1397 this.click_on_list = function(e)
1399 if (this.gui_objects.qsearchbox)
1400 this.gui_objects.qsearchbox.blur();
1402 if (this.message_list)
1403 this.message_list.focus();
1404 else if (this.contact_list)
1405 this.contact_list.focus();
1410 this.msglist_select = function(list)
1412 if (this.preview_timer)
1413 clearTimeout(this.preview_timer);
1414 if (this.preview_read_timer)
1415 clearTimeout(this.preview_read_timer);
1417 var selected = list.get_single_selection() != null;
1419 this.enable_command(this.env.message_commands, selected);
1421 // Hide certain command buttons when Drafts folder is selected
1422 if (this.env.mailbox == this.env.drafts_mailbox)
1423 this.enable_command('reply', 'reply-all', 'reply-list', 'forward', false);
1424 // Disable reply-list when List-Post header is not set
1426 var msg = this.env.messages[list.get_single_selection()];
1428 this.enable_command('reply-list', false);
1431 // Multi-message commands
1432 this.enable_command('delete', 'moveto', 'copy', 'mark', (list.selection.length > 0 ? true : false));
1434 // reset all-pages-selection
1435 if (selected || (list.selection.length && list.selection.length != list.rowcount))
1436 this.select_all_mode = false;
1438 // start timer for message preview (wait for double click)
1439 if (selected && this.env.contentframe && !list.multi_selecting && !this.dummy_select)
1440 this.preview_timer = window.setTimeout(function(){ ref.msglist_get_preview(); }, 200);
1441 else if (this.env.contentframe)
1442 this.show_contentframe(false);
1445 // This allow as to re-select selected message and display it in preview frame
1446 this.msglist_click = function(list)
1448 if (list.multi_selecting || !this.env.contentframe)
1451 if (list.get_single_selection() && window.frames && window.frames[this.env.contentframe]) {
1452 if (window.frames[this.env.contentframe].location.href.indexOf(this.env.blankpage)>=0) {
1453 if (this.preview_timer)
1454 clearTimeout(this.preview_timer);
1455 if (this.preview_read_timer)
1456 clearTimeout(this.preview_read_timer);
1457 this.preview_timer = window.setTimeout(function(){ ref.msglist_get_preview(); }, 200);
1462 this.msglist_dbl_click = function(list)
1464 if (this.preview_timer)
1465 clearTimeout(this.preview_timer);
1467 if (this.preview_read_timer)
1468 clearTimeout(this.preview_read_timer);
1470 var uid = list.get_single_selection();
1471 if (uid && this.env.mailbox == this.env.drafts_mailbox)
1472 this.goto_url('compose', '_draft_uid='+uid+'&_mbox='+urlencode(this.env.mailbox), true);
1474 this.show_message(uid, false, false);
1477 this.msglist_keypress = function(list)
1479 if (list.key_pressed == list.ENTER_KEY)
1480 this.command('show');
1481 else if (list.key_pressed == list.DELETE_KEY)
1482 this.command('delete');
1483 else if (list.key_pressed == list.BACKSPACE_KEY)
1484 this.command('delete');
1485 else if (list.key_pressed == 33)
1486 this.command('previouspage');
1487 else if (list.key_pressed == 34)
1488 this.command('nextpage');
1491 this.msglist_get_preview = function()
1493 var uid = this.get_single_uid();
1494 if (uid && this.env.contentframe && !this.drag_active)
1495 this.show_message(uid, false, true);
1496 else if (this.env.contentframe)
1497 this.show_contentframe(false);
1500 this.msglist_expand = function(row)
1502 if (this.env.messages[row.uid])
1503 this.env.messages[row.uid].expanded = row.expanded;
1506 this.msglist_set_coltypes = function(list)
1508 var i, found, name, cols = list.list.tHead.rows[0].cells;
1510 this.env.coltypes = [];
1512 for (i=0; i<cols.length; i++)
1513 if (cols[i].id && cols[i].id.match(/^rcm/)) {
1514 name = cols[i].id.replace(/^rcm/, '');
1515 this.env.coltypes.push(name == 'to' ? 'from' : name);
1518 if ((found = $.inArray('flag', this.env.coltypes)) >= 0)
1519 this.set_env('flagged_col', found);
1521 if ((found = $.inArray('subject', this.env.coltypes)) >= 0)
1522 this.set_env('subject_col', found);
1524 this.http_post('save-pref', { '_name':'list_cols', '_value':this.env.coltypes, '_session':'list_attrib/columns' });
1527 this.check_droptarget = function(id)
1529 var allow = false, copy = false;
1531 if (this.task == 'mail')
1532 allow = (this.env.mailboxes[id] && this.env.mailboxes[id].id != this.env.mailbox && !this.env.mailboxes[id].virtual);
1533 else if (this.task == 'settings')
1534 allow = (id != this.env.mailbox);
1535 else if (this.task == 'addressbook') {
1536 if (id != this.env.source && this.env.contactfolders[id]) {
1537 if (this.env.contactfolders[id].type == 'group') {
1538 var target_abook = this.env.contactfolders[id].source;
1539 allow = this.env.contactfolders[id].id != this.env.group && !this.env.contactfolders[target_abook].readonly;
1540 copy = target_abook != this.env.source;
1543 allow = !this.env.contactfolders[id].readonly;
1549 return allow ? (copy ? 2 : 1) : 0;
1553 /*********************************************************/
1554 /********* (message) list functionality *********/
1555 /*********************************************************/
1557 this.init_message_row = function(row)
1559 var expando, self = this, uid = row.uid,
1560 status_icon = (this.env.status_col != null ? 'status' : 'msg') + 'icn' + row.uid;
1562 if (uid && this.env.messages[uid])
1563 $.extend(row, this.env.messages[uid]);
1565 // set eventhandler to status icon
1566 if (row.icon = document.getElementById(status_icon)) {
1567 row.icon._row = row.obj;
1568 row.icon.onmousedown = function(e) { self.command('toggle_status', this); rcube_event.cancel(e); };
1571 // save message icon position too
1572 if (this.env.status_col != null)
1573 row.msgicon = document.getElementById('msgicn'+row.uid);
1575 row.msgicon = row.icon;
1577 // set eventhandler to flag icon, if icon found
1578 if (this.env.flagged_col != null && (row.flagicon = document.getElementById('flagicn'+row.uid))) {
1579 row.flagicon._row = row.obj;
1580 row.flagicon.onmousedown = function(e) { self.command('toggle_flag', this); rcube_event.cancel(e); };
1583 if (!row.depth && row.has_children && (expando = document.getElementById('rcmexpando'+row.uid))) {
1584 row.expando = expando;
1585 expando.onmousedown = function(e) { return self.expand_message_row(e, uid); };
1588 this.triggerEvent('insertrow', { uid:uid, row:row });
1591 // create a table row in the message list
1592 this.add_message_row = function(uid, cols, flags, attop)
1594 if (!this.gui_objects.messagelist || !this.message_list)
1597 if (!this.env.messages[uid])
1598 this.env.messages[uid] = {};
1600 // merge flags over local message object
1601 $.extend(this.env.messages[uid], {
1602 deleted: flags.deleted?1:0,
1603 replied: flags.replied?1:0,
1604 unread: flags.unread?1:0,
1605 forwarded: flags.forwarded?1:0,
1606 flagged: flags.flagged?1:0,
1607 has_children: flags.has_children?1:0,
1608 depth: flags.depth?flags.depth:0,
1609 unread_children: flags.unread_children?flags.unread_children:0,
1610 parent_uid: flags.parent_uid?flags.parent_uid:0,
1611 selected: this.select_all_mode || this.message_list.in_selection(uid),
1614 // flags from plugins
1615 flags: flags.extra_flags
1618 var c, html, tree = expando = '',
1619 list = this.message_list,
1621 tbody = this.gui_objects.messagelist.tBodies[0],
1622 rowcount = tbody.rows.length,
1624 message = this.env.messages[uid],
1625 css_class = 'message'
1626 + (even ? ' even' : ' odd')
1627 + (flags.unread ? ' unread' : '')
1628 + (flags.deleted ? ' deleted' : '')
1629 + (flags.flagged ? ' flagged' : '')
1630 + (flags.unread_children && !flags.unread && !this.env.autoexpand_threads ? ' unroot' : '')
1631 + (message.selected ? ' selected' : ''),
1632 // for performance use DOM instead of jQuery here
1633 row = document.createElement('tr'),
1634 col = document.createElement('td');
1636 row.id = 'rcmrow'+uid;
1637 row.className = css_class;
1639 // message status icons
1640 css_class = 'msgicon';
1641 if (this.env.status_col === null) {
1642 css_class += ' status';
1644 css_class += ' deleted';
1645 else if (flags.unread)
1646 css_class += ' unread';
1647 else if (flags.unread_children > 0)
1648 css_class += ' unreadchildren';
1651 css_class += ' replied';
1652 if (flags.forwarded)
1653 css_class += ' forwarded';
1656 if (message.selected && !list.in_selection(uid))
1657 list.selection.push(uid);
1660 if (this.env.threading) {
1661 // This assumes that div width is hardcoded to 15px,
1662 var width = message.depth * 15;
1663 if (message.depth) {
1664 if ((rows[message.parent_uid] && rows[message.parent_uid].expanded === false)
1665 || ((this.env.autoexpand_threads == 0 || this.env.autoexpand_threads == 2) &&
1666 (!rows[message.parent_uid] || !rows[message.parent_uid].expanded))
1668 row.style.display = 'none';
1669 message.expanded = false;
1672 message.expanded = true;
1674 else if (message.has_children) {
1675 if (typeof(message.expanded) == 'undefined' && (this.env.autoexpand_threads == 1 || (this.env.autoexpand_threads == 2 && message.unread_children))) {
1676 message.expanded = true;
1681 tree += '<span id="rcmtab' + uid + '" class="branch" style="width:' + width + 'px;"> </span>';
1683 if (message.has_children && !message.depth)
1684 expando = '<div id="rcmexpando' + uid + '" class="' + (message.expanded ? 'expanded' : 'collapsed') + '"> </div>';
1687 tree += '<span id="msgicn'+uid+'" class="'+css_class+'"> </span>';
1689 // build subject link
1690 if (!bw.ie && cols.subject) {
1691 var action = flags.mbox == this.env.drafts_mailbox ? 'compose' : 'show';
1692 var uid_param = flags.mbox == this.env.drafts_mailbox ? '_draft_uid' : '_uid';
1693 cols.subject = '<a href="./?_task=mail&_action='+action+'&_mbox='+urlencode(flags.mbox)+'&'+uid_param+'='+uid+'"'+
1694 ' onclick="return rcube_event.cancel(event)" onmouseover="rcube_webmail.long_subject_title(this,'+(message.depth+1)+')">'+cols.subject+'</a>';
1697 // add each submitted col
1698 for (var n in this.env.coltypes) {
1699 c = this.env.coltypes[n];
1700 col = document.createElement('td');
1701 col.className = String(c).toLowerCase();
1704 css_class = (flags.flagged ? 'flagged' : 'unflagged');
1705 html = '<span id="flagicn'+uid+'" class="'+css_class+'"> </span>';
1707 else if (c == 'attachment') {
1708 if (/application\/|multipart\/m/.test(flags.ctype))
1709 html = '<span class="attachment"> </span>';
1710 else if (/multipart\/report/.test(flags.ctype))
1711 html = '<span class="report"> </span>';
1715 else if (c == 'status') {
1717 css_class = 'deleted';
1718 else if (flags.unread)
1719 css_class = 'unread';
1720 else if (flags.unread_children > 0)
1721 css_class = 'unreadchildren';
1723 css_class = 'msgicon';
1724 html = '<span id="statusicn'+uid+'" class="'+css_class+'"> </span>';
1726 else if (c == 'threads')
1728 else if (c == 'subject')
1729 html = tree + cols[c];
1733 col.innerHTML = html;
1735 row.appendChild(col);
1738 list.insert_row(row, attop);
1741 if (attop && this.env.pagesize && list.rowcount > this.env.pagesize) {
1742 var uid = list.get_last_row();
1743 list.remove_row(uid);
1744 list.clear_selection(uid);
1748 this.set_list_sorting = function(sort_col, sort_order)
1750 // set table header class
1751 $('#rcm'+this.env.sort_col).removeClass('sorted'+(this.env.sort_order.toUpperCase()));
1753 $('#rcm'+sort_col).addClass('sorted'+sort_order);
1755 this.env.sort_col = sort_col;
1756 this.env.sort_order = sort_order;
1759 this.set_list_options = function(cols, sort_col, sort_order, threads)
1761 var update, add_url = '';
1763 if (typeof sort_col == 'undefined')
1764 sort_col = this.env.sort_col;
1766 sort_order = this.env.sort_order;
1768 if (this.env.sort_col != sort_col || this.env.sort_order != sort_order) {
1770 this.set_list_sorting(sort_col, sort_order);
1773 if (this.env.threading != threads) {
1775 add_url += '&_threads=' + threads;
1778 if (cols && cols.length) {
1779 // make sure new columns are added at the end of the list
1780 var i, idx, name, newcols = [], oldcols = this.env.coltypes;
1781 for (i=0; i<oldcols.length; i++) {
1782 name = oldcols[i] == 'to' ? 'from' : oldcols[i];
1783 idx = $.inArray(name, cols);
1789 for (i=0; i<cols.length; i++)
1791 newcols.push(cols[i]);
1793 if (newcols.join() != oldcols.join()) {
1795 add_url += '&_cols=' + newcols.join(',');
1800 this.list_mailbox('', '', sort_col+'_'+sort_order, add_url);
1803 // when user doble-clicks on a row
1804 this.show_message = function(id, safe, preview)
1809 var target = window,
1810 action = preview ? 'preview': 'show',
1811 url = '&_action='+action+'&_uid='+id+'&_mbox='+urlencode(this.env.mailbox);
1813 if (preview && this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
1814 target = window.frames[this.env.contentframe];
1815 url += '&_framed=1';
1821 // also send search request to get the right messages
1822 if (this.env.search_request)
1823 url += '&_search='+this.env.search_request;
1825 if (action == 'preview' && String(target.location.href).indexOf(url) >= 0)
1826 this.show_contentframe(true);
1828 if (!this.env.frame_lock) {
1829 (this.is_framed() ? parent.rcmail : this).env.frame_lock = this.set_busy(true, 'loading');
1831 target.location.href = this.env.comm_path+url;
1833 // mark as read and change mbox unread counter
1834 if (action == 'preview' && this.message_list && this.message_list.rows[id] && this.message_list.rows[id].unread && this.env.preview_pane_mark_read >= 0) {
1835 this.preview_read_timer = window.setTimeout(function() {
1836 ref.set_message(id, 'unread', false);
1837 ref.update_thread_root(id, 'read');
1838 if (ref.env.unread_counts[ref.env.mailbox]) {
1839 ref.env.unread_counts[ref.env.mailbox] -= 1;
1840 ref.set_unread_count(ref.env.mailbox, ref.env.unread_counts[ref.env.mailbox], ref.env.mailbox == 'INBOX');
1842 if (ref.env.preview_pane_mark_read > 0)
1843 ref.http_post('mark', '_uid='+id+'&_flag=read&_quiet=1');
1844 }, this.env.preview_pane_mark_read * 1000);
1849 this.show_contentframe = function(show)
1852 if (this.env.contentframe && (frm = $('#'+this.env.contentframe)) && frm.length) {
1853 if (!show && (win = window.frames[this.env.contentframe])) {
1854 if (win.location && win.location.href.indexOf(this.env.blankpage)<0)
1855 win.location.href = this.env.blankpage;
1857 else if (!bw.safari && !bw.konq)
1858 frm[show ? 'show' : 'hide']();
1861 if (!show && this.busy)
1862 this.set_busy(false, null, this.env.frame_lock);
1865 // list a specific page
1866 this.list_page = function(page)
1869 page = this.env.current_page+1;
1870 else if (page == 'last')
1871 page = this.env.pagecount;
1872 else if (page == 'prev' && this.env.current_page > 1)
1873 page = this.env.current_page-1;
1874 else if (page == 'first' && this.env.current_page > 1)
1877 if (page > 0 && page <= this.env.pagecount) {
1878 this.env.current_page = page;
1880 if (this.task == 'mail')
1881 this.list_mailbox(this.env.mailbox, page);
1882 else if (this.task == 'addressbook')
1883 this.list_contacts(this.env.source, this.env.group, page);
1887 // list messages of a specific mailbox using filter
1888 this.filter_mailbox = function(filter)
1890 var search, lock = this.set_busy(true, 'searching');
1892 if (this.gui_objects.qsearchbox)
1893 search = this.gui_objects.qsearchbox.value;
1895 this.clear_message_list();
1898 this.env.current_page = 1;
1899 this.http_request('search', '_filter='+filter
1900 + (search ? '&_q='+urlencode(search) : '')
1901 + (this.env.mailbox ? '&_mbox='+urlencode(this.env.mailbox) : ''), lock);
1904 // list messages of a specific mailbox
1905 this.list_mailbox = function(mbox, page, sort, add_url)
1907 var url = '', target = window;
1910 mbox = this.env.mailbox ? this.env.mailbox : 'INBOX';
1915 // add sort to url if set
1917 url += '&_sort=' + sort;
1919 // also send search request to get the right messages
1920 if (this.env.search_request)
1921 url += '&_search='+this.env.search_request;
1923 // set page=1 if changeing to another mailbox
1924 if (this.env.mailbox != mbox) {
1926 this.env.current_page = page;
1927 this.select_all_mode = false;
1930 // unselect selected messages and clear the list and message data
1931 this.clear_message_list();
1933 if (mbox != this.env.mailbox || (mbox == this.env.mailbox && !page && !sort))
1934 url += '&_refresh=1';
1936 this.select_folder(mbox, this.env.mailbox);
1937 this.env.mailbox = mbox;
1939 // load message list remotely
1940 if (this.gui_objects.messagelist) {
1941 this.list_mailbox_remote(mbox, page, url);
1945 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
1946 target = window.frames[this.env.contentframe];
1947 url += '&_framed=1';
1950 // load message list to target frame/window
1952 this.set_busy(true, 'loading');
1953 target.location.href = this.env.comm_path+'&_mbox='+urlencode(mbox)+(page ? '&_page='+page : '')+url;
1957 this.clear_message_list = function()
1959 this.env.messages = {};
1960 this.last_selected = 0;
1962 this.show_contentframe(false);
1963 if (this.message_list)
1964 this.message_list.clear(true);
1967 // send remote request to load message list
1968 this.list_mailbox_remote = function(mbox, page, add_url)
1970 // clear message list first
1971 this.message_list.clear();
1973 // send request to server
1974 var url = '_mbox='+urlencode(mbox)+(page ? '&_page='+page : ''),
1975 lock = this.set_busy(true, 'loading');
1976 this.http_request('list', url+add_url, lock);
1979 // removes messages that doesn't exists from list selection array
1980 this.update_selection = function()
1982 var selected = this.message_list.selection,
1983 rows = this.message_list.rows,
1987 if (rows[selected[i]])
1988 selection.push(selected[i]);
1990 this.message_list.selection = selection;
1993 // expand all threads with unread children
1994 this.expand_unread = function()
1996 var r, tbody = this.gui_objects.messagelist.tBodies[0],
1997 new_row = tbody.firstChild;
2000 if (new_row.nodeType == 1 && (r = this.message_list.rows[new_row.uid])
2001 && r.unread_children) {
2002 this.message_list.expand_all(r);
2003 this.set_unread_children(r.uid);
2005 new_row = new_row.nextSibling;
2010 // thread expanding/collapsing handler
2011 this.expand_message_row = function(e, uid)
2013 var row = this.message_list.rows[uid];
2015 // handle unread_children mark
2016 row.expanded = !row.expanded;
2017 this.set_unread_children(uid);
2018 row.expanded = !row.expanded;
2020 this.message_list.expand_row(e, uid);
2023 // message list expanding
2024 this.expand_threads = function()
2026 if (!this.env.threading || !this.env.autoexpand_threads || !this.message_list)
2029 switch (this.env.autoexpand_threads) {
2030 case 2: this.expand_unread(); break;
2031 case 1: this.message_list.expand_all(); break;
2035 // Initializes threads indicators/expanders after list update
2036 this.init_threads = function(roots)
2038 for (var n=0, len=roots.length; n<len; n++)
2039 this.add_tree_icons(roots[n]);
2040 this.expand_threads();
2043 // adds threads tree icons to the list (or specified thread)
2044 this.add_tree_icons = function(root)
2046 var i, l, r, n, len, pos, tmp = [], uid = [],
2047 row, rows = this.message_list.rows;
2050 row = rows[root] ? rows[root].obj : null;
2052 row = this.message_list.list.tBodies[0].firstChild;
2055 if (row.nodeType == 1 && (r = rows[row.uid])) {
2057 for (i=tmp.length-1; i>=0; i--) {
2058 len = tmp[i].length;
2059 if (len > r.depth) {
2060 pos = len - r.depth;
2061 if (!(tmp[i][pos] & 2))
2062 tmp[i][pos] = tmp[i][pos] ? tmp[i][pos]+2 : 2;
2064 else if (len == r.depth) {
2065 if (!(tmp[i][0] & 2))
2072 tmp.push(new Array(r.depth));
2073 tmp[tmp.length-1][0] = 1;
2079 this.set_tree_icons(uid[i], tmp[i]);
2084 if (root && row != rows[root].obj)
2088 row = row.nextSibling;
2093 this.set_tree_icons(uid[i], tmp[i]);
2098 // adds tree icons to specified message row
2099 this.set_tree_icons = function(uid, tree)
2101 var i, divs = [], html = '', len = tree.length;
2103 for (i=0; i<len; i++) {
2105 divs.push({'class': 'l3', width: 15});
2106 else if (tree[i] > 1)
2107 divs.push({'class': 'l2', width: 15});
2108 else if (tree[i] > 0)
2109 divs.push({'class': 'l1', width: 15});
2111 else if (divs.length && !divs[divs.length-1]['class'])
2112 divs[divs.length-1].width += 15;
2114 divs.push({'class': null, width: 15});
2117 for (i=divs.length-1; i>=0; i--) {
2118 if (divs[i]['class'])
2119 html += '<div class="tree '+divs[i]['class']+'" />';
2121 html += '<div style="width:'+divs[i].width+'px" />';
2125 $('#rcmtab'+uid).html(html);
2128 // update parent in a thread
2129 this.update_thread_root = function(uid, flag)
2131 if (!this.env.threading)
2134 var root = this.message_list.find_root(uid);
2139 var p = this.message_list.rows[root];
2141 if (flag == 'read' && p.unread_children) {
2142 p.unread_children--;
2144 else if (flag == 'unread' && p.has_children) {
2145 // unread_children may be undefined
2146 p.unread_children = p.unread_children ? p.unread_children + 1 : 1;
2152 this.set_message_icon(root);
2153 this.set_unread_children(root);
2156 // update thread indicators for all messages in a thread below the specified message
2157 // return number of removed/added root level messages
2158 this.update_thread = function (uid)
2160 if (!this.env.threading)
2163 var r, parent, count = 0,
2164 rows = this.message_list.rows,
2166 depth = rows[uid].depth,
2169 if (!row.depth) // root message: decrease roots count
2171 else if (row.unread) {
2172 // update unread_children for thread root
2173 parent = this.message_list.find_root(uid);
2174 rows[parent].unread_children--;
2175 this.set_unread_children(parent);
2178 parent = row.parent_uid;
2181 row = row.obj.nextSibling;
2183 if (row.nodeType == 1 && (r = rows[row.uid])) {
2184 if (!r.depth || r.depth <= depth)
2187 r.depth--; // move left
2188 // reset width and clear the content of a tab, icons will be added later
2189 $('#rcmtab'+r.uid).width(r.depth * 15).html('');
2190 if (!r.depth) { // a new root
2191 count++; // increase roots count
2193 if (r.has_children) {
2194 // replace 'leaf' with 'collapsed'
2195 $('#rcmrow'+r.uid+' '+'.leaf:first')
2196 .attr('id', 'rcmexpando' + r.uid)
2197 .attr('class', (r.obj.style.display != 'none' ? 'expanded' : 'collapsed'))
2198 .bind('mousedown', {uid:r.uid, p:this},
2199 function(e) { return e.data.p.expand_message_row(e, e.data.uid); });
2201 r.unread_children = 0;
2204 // show if it was hidden
2205 if (r.obj.style.display == 'none')
2209 if (r.depth == depth)
2210 r.parent_uid = parent;
2211 if (r.unread && roots.length)
2212 roots[roots.length-1].unread_children++;
2215 row = row.nextSibling;
2218 // update unread_children for roots
2219 for (var i=0; i<roots.length; i++)
2220 this.set_unread_children(roots[i].uid);
2225 this.delete_excessive_thread_rows = function()
2227 var rows = this.message_list.rows,
2228 tbody = this.message_list.list.tBodies[0],
2229 row = tbody.firstChild,
2230 cnt = this.env.pagesize + 1;
2233 if (row.nodeType == 1 && (r = rows[row.uid])) {
2234 if (!r.depth && cnt)
2238 this.message_list.remove_row(row.uid);
2240 row = row.nextSibling;
2245 this.set_message_icon = function(uid)
2248 row = this.message_list.rows[uid];
2254 css_class = 'msgicon';
2256 css_class += ' deleted';
2257 else if (row.unread)
2258 css_class += ' unread';
2259 else if (row.unread_children)
2260 css_class += ' unreadchildren';
2261 if (row.msgicon == row.icon) {
2263 css_class += ' replied';
2265 css_class += ' forwarded';
2266 css_class += ' status';
2269 row.icon.className = css_class;
2272 if (row.msgicon && row.msgicon != row.icon) {
2273 css_class = 'msgicon';
2274 if (!row.unread && row.unread_children)
2275 css_class += ' unreadchildren';
2277 css_class += ' replied';
2279 css_class += ' forwarded';
2281 row.msgicon.className = css_class;
2285 css_class = (row.flagged ? 'flagged' : 'unflagged');
2286 row.flagicon.className = css_class;
2290 // set message status
2291 this.set_message_status = function(uid, flag, status)
2293 var row = this.message_list.rows[uid];
2298 if (flag == 'unread')
2299 row.unread = status;
2300 else if(flag == 'deleted')
2301 row.deleted = status;
2302 else if (flag == 'replied')
2303 row.replied = status;
2304 else if (flag == 'forwarded')
2305 row.forwarded = status;
2306 else if (flag == 'flagged')
2307 row.flagged = status;
2310 // set message row status, class and icon
2311 this.set_message = function(uid, flag, status)
2313 var row = this.message_list.rows[uid];
2319 this.set_message_status(uid, flag, status);
2321 var rowobj = $(row.obj);
2323 if (row.unread && !rowobj.hasClass('unread'))
2324 rowobj.addClass('unread');
2325 else if (!row.unread && rowobj.hasClass('unread'))
2326 rowobj.removeClass('unread');
2328 if (row.deleted && !rowobj.hasClass('deleted'))
2329 rowobj.addClass('deleted');
2330 else if (!row.deleted && rowobj.hasClass('deleted'))
2331 rowobj.removeClass('deleted');
2333 if (row.flagged && !rowobj.hasClass('flagged'))
2334 rowobj.addClass('flagged');
2335 else if (!row.flagged && rowobj.hasClass('flagged'))
2336 rowobj.removeClass('flagged');
2338 this.set_unread_children(uid);
2339 this.set_message_icon(uid);
2342 // sets unroot (unread_children) class of parent row
2343 this.set_unread_children = function(uid)
2345 var row = this.message_list.rows[uid];
2350 if (!row.unread && row.unread_children && !row.expanded)
2351 $(row.obj).addClass('unroot');
2353 $(row.obj).removeClass('unroot');
2356 // copy selected messages to the specified mailbox
2357 this.copy_messages = function(mbox)
2359 if (mbox && typeof mbox == 'object')
2362 // exit if current or no mailbox specified or if selection is empty
2363 if (!mbox || mbox == this.env.mailbox || (!this.env.uid && (!this.message_list || !this.message_list.get_selection().length)))
2367 lock = this.display_message(this.get_label('copyingmessage'), 'loading'),
2368 add_url = '&_target_mbox='+urlencode(mbox)+'&_from='+(this.env.action ? this.env.action : '');
2371 a_uids[0] = this.env.uid;
2373 var selection = this.message_list.get_selection();
2374 for (var n in selection) {
2375 a_uids.push(selection[n]);
2379 add_url += '&_uid='+this.uids_to_list(a_uids);
2381 // send request to server
2382 this.http_post('copy', '_mbox='+urlencode(this.env.mailbox)+add_url, lock);
2385 // move selected messages to the specified mailbox
2386 this.move_messages = function(mbox)
2388 if (mbox && typeof mbox == 'object')
2391 // exit if current or no mailbox specified or if selection is empty
2392 if (!mbox || mbox == this.env.mailbox || (!this.env.uid && (!this.message_list || !this.message_list.get_selection().length)))
2396 add_url = '&_target_mbox='+urlencode(mbox)+'&_from='+(this.env.action ? this.env.action : '');
2398 // show wait message
2399 if (this.env.action == 'show') {
2400 lock = this.set_busy(true, 'movingmessage');
2403 this.show_contentframe(false);
2405 // Hide message command buttons until a message is selected
2406 this.enable_command(this.env.message_commands, false);
2408 this._with_selected_messages('moveto', lock, add_url);
2411 // delete selected messages from the current mailbox
2412 this.delete_messages = function()
2414 var uid, i, len, trash = this.env.trash_mailbox,
2415 list = this.message_list,
2416 selection = list ? $.merge([], list.get_selection()) : [];
2418 // exit if no mailbox specified or if selection is empty
2419 if (!this.env.uid && !selection.length)
2422 // also select childs of collapsed rows
2423 for (i=0, len=selection.length; i<len; i++) {
2425 if (list.rows[uid].has_children && !list.rows[uid].expanded)
2426 list.select_childs(uid);
2429 // if config is set to flag for deletion
2430 if (this.env.flag_for_deletion) {
2431 this.mark_message('delete');
2434 // if there isn't a defined trash mailbox or we are in it
2435 // @TODO: we should check if defined trash mailbox exists
2436 else if (!trash || this.env.mailbox == trash)
2437 this.permanently_remove_messages();
2438 // if there is a trash mailbox defined and we're not currently in it
2440 // if shift was pressed delete it immediately
2441 if (list && list.shiftkey) {
2442 if (confirm(this.get_label('deletemessagesconfirm')))
2443 this.permanently_remove_messages();
2446 this.move_messages(trash);
2452 // delete the selected messages permanently
2453 this.permanently_remove_messages = function()
2455 // exit if no mailbox specified or if selection is empty
2456 if (!this.env.uid && (!this.message_list || !this.message_list.get_selection().length))
2459 this.show_contentframe(false);
2460 this._with_selected_messages('delete', false, '&_from='+(this.env.action ? this.env.action : ''));
2463 // Send a specifc moveto/delete request with UIDs of all selected messages
2465 this._with_selected_messages = function(action, lock, add_url)
2467 var a_uids = [], count = 0, msg;
2470 a_uids[0] = this.env.uid;
2472 var n, id, root, roots = [],
2473 selection = this.message_list.get_selection();
2475 for (n=0, len=selection.length; n<len; n++) {
2479 if (this.env.threading) {
2480 count += this.update_thread(id);
2481 root = this.message_list.find_root(id);
2482 if (root != id && $.inArray(root, roots) < 0) {
2486 this.message_list.remove_row(id, (this.env.display_next && n == selection.length-1));
2488 // make sure there are no selected rows
2489 if (!this.env.display_next)
2490 this.message_list.clear_selection();
2491 // update thread tree icons
2492 for (n=0, len=roots.length; n<len; n++) {
2493 this.add_tree_icons(roots[n]);
2497 // also send search request to get the right messages
2498 if (this.env.search_request)
2499 add_url += '&_search='+this.env.search_request;
2501 if (this.env.display_next && this.env.next_uid)
2502 add_url += '&_next_uid='+this.env.next_uid;
2505 add_url += '&_count='+(count*-1);
2507 // remove threads from the end of the list
2508 this.delete_excessive_thread_rows();
2510 add_url += '&_uid='+this.uids_to_list(a_uids);
2513 msg = action == 'moveto' ? 'movingmessage' : 'deletingmessage';
2514 lock = this.display_message(this.get_label(msg), 'loading');
2517 // send request to server
2518 this.http_post(action, '_mbox='+urlencode(this.env.mailbox)+add_url, lock);
2521 // set a specific flag to one or more messages
2522 this.mark_message = function(flag, uid)
2524 var a_uids = [], r_uids = [], len, n, id,
2525 selection = this.message_list ? this.message_list.get_selection() : [];
2529 else if (this.env.uid)
2530 a_uids[0] = this.env.uid;
2531 else if (this.message_list) {
2532 for (n=0, len=selection.length; n<len; n++) {
2533 a_uids.push(selection[n]);
2537 if (!this.message_list)
2540 for (n=0, len=a_uids.length; n<len; n++) {
2542 if ((flag=='read' && this.message_list.rows[id].unread)
2543 || (flag=='unread' && !this.message_list.rows[id].unread)
2544 || (flag=='delete' && !this.message_list.rows[id].deleted)
2545 || (flag=='undelete' && this.message_list.rows[id].deleted)
2546 || (flag=='flagged' && !this.message_list.rows[id].flagged)
2547 || (flag=='unflagged' && this.message_list.rows[id].flagged))
2554 if (!r_uids.length && !this.select_all_mode)
2560 this.toggle_read_status(flag, r_uids);
2564 this.toggle_delete_status(r_uids);
2568 this.toggle_flagged_status(flag, a_uids);
2573 // set class to read/unread
2574 this.toggle_read_status = function(flag, a_uids)
2576 // mark all message rows as read/unread
2577 for (var i=0; i<a_uids.length; i++)
2578 this.set_message(a_uids[i], 'unread', (flag=='unread' ? true : false));
2580 var url = '_uid='+this.uids_to_list(a_uids)+'&_flag='+flag,
2581 lock = this.display_message(this.get_label('markingmessage'), 'loading');
2583 // also send search request to get the right messages
2584 if (this.env.search_request)
2585 url += '&_search='+this.env.search_request;
2587 this.http_post('mark', url, lock);
2589 for (var i=0; i<a_uids.length; i++)
2590 this.update_thread_root(a_uids[i], flag);
2593 // set image to flagged or unflagged
2594 this.toggle_flagged_status = function(flag, a_uids)
2596 // mark all message rows as flagged/unflagged
2597 for (var i=0; i<a_uids.length; i++)
2598 this.set_message(a_uids[i], 'flagged', (flag=='flagged' ? true : false));
2600 var url = '_uid='+this.uids_to_list(a_uids)+'&_flag='+flag,
2601 lock = this.display_message(this.get_label('markingmessage'), 'loading');
2603 // also send search request to get the right messages
2604 if (this.env.search_request)
2605 url += '&_search='+this.env.search_request;
2607 this.http_post('mark', url, lock);
2610 // mark all message rows as deleted/undeleted
2611 this.toggle_delete_status = function(a_uids)
2613 var rows = this.message_list ? this.message_list.rows : [];
2615 if (a_uids.length==1) {
2616 if (!rows.length || (rows[a_uids[0]] && !rows[a_uids[0]].deleted))
2617 this.flag_as_deleted(a_uids);
2619 this.flag_as_undeleted(a_uids);
2624 var uid, all_deleted = true;
2625 for (var i=0, len=a_uids.length; i<len; i++) {
2627 if (rows[uid] && !rows[uid].deleted) {
2628 all_deleted = false;
2634 this.flag_as_undeleted(a_uids);
2636 this.flag_as_deleted(a_uids);
2641 this.flag_as_undeleted = function(a_uids)
2643 for (var i=0, len=a_uids.length; i<len; i++)
2644 this.set_message(a_uids[i], 'deleted', false);
2646 var url = '_uid='+this.uids_to_list(a_uids)+'&_flag=undelete',
2647 lock = this.display_message(this.get_label('markingmessage'), 'loading');
2649 // also send search request to get the right messages
2650 if (this.env.search_request)
2651 url += '&_search='+this.env.search_request;
2653 this.http_post('mark', url, lock);
2657 this.flag_as_deleted = function(a_uids)
2661 rows = this.message_list ? this.message_list.rows : [],
2664 for (var i=0, len=a_uids.length; i<len; i++) {
2667 if (rows[uid].unread)
2668 r_uids[r_uids.length] = uid;
2670 if (this.env.skip_deleted) {
2671 count += this.update_thread(uid);
2672 this.message_list.remove_row(uid, (this.env.display_next && i == this.message_list.selection.length-1));
2675 this.set_message(uid, 'deleted', true);
2679 // make sure there are no selected rows
2680 if (this.env.skip_deleted && this.message_list) {
2681 if(!this.env.display_next)
2682 this.message_list.clear_selection();
2684 add_url += '&_count='+(count*-1);
2686 // remove threads from the end of the list
2687 this.delete_excessive_thread_rows();
2690 add_url = '&_from='+(this.env.action ? this.env.action : ''),
2691 lock = this.display_message(this.get_label('markingmessage'), 'loading');
2695 add_url += '&_ruid='+this.uids_to_list(r_uids);
2697 if (this.env.skip_deleted) {
2698 if (this.env.display_next && this.env.next_uid)
2699 add_url += '&_next_uid='+this.env.next_uid;
2702 // also send search request to get the right messages
2703 if (this.env.search_request)
2704 add_url += '&_search='+this.env.search_request;
2706 this.http_post('mark', '_uid='+this.uids_to_list(a_uids)+'&_flag=delete'+add_url, lock);
2710 // flag as read without mark request (called from backend)
2711 // argument should be a coma-separated list of uids
2712 this.flag_deleted_as_read = function(uids)
2715 rows = this.message_list ? this.message_list.rows : [],
2717 a_uids = str.split(',');
2719 for (var i=0; i<a_uids.length; i++) {
2722 this.set_message(uid, 'unread', false);
2726 // Converts array of message UIDs to comma-separated list for use in URL
2727 // with select_all mode checking
2728 this.uids_to_list = function(uids)
2730 return this.select_all_mode ? '*' : uids.join(',');
2734 /*********************************************************/
2735 /********* mailbox folders methods *********/
2736 /*********************************************************/
2738 this.expunge_mailbox = function(mbox)
2741 url = '_mbox='+urlencode(mbox);
2743 // lock interface if it's the active mailbox
2744 if (mbox == this.env.mailbox) {
2745 lock = this.set_busy(true, 'loading');
2746 url += '&_reload=1';
2749 // send request to server
2750 this.http_post('expunge', url, lock);
2753 this.purge_mailbox = function(mbox)
2756 url = '_mbox='+urlencode(mbox);
2758 if (!confirm(this.get_label('purgefolderconfirm')))
2761 // lock interface if it's the active mailbox
2762 if (mbox == this.env.mailbox) {
2763 lock = this.set_busy(true, 'loading');
2764 url += '&_reload=1';
2767 // send request to server
2768 this.http_post('purge', url, lock);
2771 // test if purge command is allowed
2772 this.purge_mailbox_test = function()
2774 return (this.env.messagecount && (this.env.mailbox == this.env.trash_mailbox || this.env.mailbox == this.env.junk_mailbox
2775 || this.env.mailbox.match('^' + RegExp.escape(this.env.trash_mailbox) + RegExp.escape(this.env.delimiter))
2776 || this.env.mailbox.match('^' + RegExp.escape(this.env.junk_mailbox) + RegExp.escape(this.env.delimiter))));
2780 /*********************************************************/
2781 /********* login form methods *********/
2782 /*********************************************************/
2784 // handler for keyboard events on the _user field
2785 this.login_user_keyup = function(e)
2787 var key = rcube_event.get_keycode(e);
2788 var passwd = $('#rcmloginpwd');
2791 if (key == 13 && passwd.length && !passwd.val()) {
2793 return rcube_event.cancel(e);
2800 /*********************************************************/
2801 /********* message compose methods *********/
2802 /*********************************************************/
2804 // init message compose form: set focus and eventhandlers
2805 this.init_messageform = function()
2807 if (!this.gui_objects.messageform)
2810 var input_from = $("[name='_from']"),
2811 input_to = $("[name='_to']"),
2812 input_subject = $("input[name='_subject']"),
2813 input_message = $("[name='_message']").get(0),
2814 html_mode = $("input[name='_is_html']").val() == '1',
2815 ac_fields = ['cc', 'bcc', 'replyto', 'followupto'];
2817 // init live search events
2818 this.init_address_input_events(input_to);
2819 for (var i in ac_fields) {
2820 this.init_address_input_events($("[name='_"+ac_fields[i]+"']"));
2824 this.set_caret_pos(input_message, this.env.top_posting ? 0 : $(input_message).val().length);
2825 // add signature according to selected identity
2826 // if we have HTML editor, signature is added in callback
2827 if (input_from.attr('type') == 'select-one' && $("input[name='_draft_saveid']").val() == '') {
2828 this.change_identity(input_from[0]);
2832 if (input_to.val() == '')
2834 else if (input_subject.val() == '')
2835 input_subject.focus();
2836 else if (input_message)
2837 input_message.focus();
2839 this.env.compose_focus_elem = document.activeElement;
2841 // get summary of all field values
2842 this.compose_field_hash(true);
2844 // start the auto-save timer
2845 this.auto_save_start();
2848 this.init_address_input_events = function(obj)
2850 obj[bw.ie || bw.safari || bw.chrome ? 'keydown' : 'keypress'](function(e){ return ref.ksearch_keydown(e, this); })
2851 .attr('autocomplete', 'off');
2854 // checks the input fields before sending a message
2855 this.check_compose_input = function()
2857 // check input fields
2858 var ed, input_to = $("[name='_to']"),
2859 input_cc = $("[name='_cc']"),
2860 input_bcc = $("[name='_bcc']"),
2861 input_from = $("[name='_from']"),
2862 input_subject = $("[name='_subject']"),
2863 input_message = $("[name='_message']");
2865 // check sender (if have no identities)
2866 if (input_from.attr('type') == 'text' && !rcube_check_email(input_from.val(), true)) {
2867 alert(this.get_label('nosenderwarning'));
2872 // check for empty recipient
2873 var recipients = input_to.val() ? input_to.val() : (input_cc.val() ? input_cc.val() : input_bcc.val());
2874 if (!rcube_check_email(recipients.replace(/^\s+/, '').replace(/[\s,;]+$/, ''), true)) {
2875 alert(this.get_label('norecipientwarning'));
2880 // check if all files has been uploaded
2881 for (var key in this.env.attachments) {
2882 if (typeof this.env.attachments[key] == 'object' && !this.env.attachments[key].complete) {
2883 alert(this.get_label('notuploadedwarning'));
2888 // display localized warning for missing subject
2889 if (input_subject.val() == '') {
2890 var subject = prompt(this.get_label('nosubjectwarning'), this.get_label('nosubject'));
2892 // user hit cancel, so don't send
2893 if (!subject && subject !== '') {
2894 input_subject.focus();
2898 input_subject.val((subject ? subject : this.get_label('nosubject')));
2901 // Apply spellcheck changes if spell checker is active
2902 this.stop_spellchecking();
2905 ed = tinyMCE.get(this.env.composebody);
2907 // check for empty body
2908 if (!ed && input_message.val() == '' && !confirm(this.get_label('nobodywarning'))) {
2909 input_message.focus();
2913 if (!ed.getContent() && !confirm(this.get_label('nobodywarning'))) {
2917 // move body from html editor to textarea (just to be sure, #1485860)
2918 tinyMCE.triggerSave();
2924 this.toggle_editor = function(props)
2926 if (props.mode == 'html') {
2927 this.display_spellcheck_controls(false);
2928 this.plain2html($('#'+props.id).val(), props.id);
2929 tinyMCE.execCommand('mceAddControl', false, props.id);
2932 var thisMCE = tinyMCE.get(props.id), existingHtml;
2933 if (thisMCE.plugins.spellchecker && thisMCE.plugins.spellchecker.active)
2934 thisMCE.execCommand('mceSpellCheck', false);
2936 if (existingHtml = thisMCE.getContent()) {
2937 if (!confirm(this.get_label('editorwarning'))) {
2940 this.html2plain(existingHtml, props.id);
2942 tinyMCE.execCommand('mceRemoveControl', false, props.id);
2943 this.display_spellcheck_controls(true);
2949 this.stop_spellchecking = function()
2952 if (window.tinyMCE && (ed = tinyMCE.get(this.env.composebody))) {
2953 if (ed.plugins.spellchecker && ed.plugins.spellchecker.active)
2954 ed.execCommand('mceSpellCheck');
2956 else if ((ed = this.env.spellcheck) && !this.spellcheck_ready) {
2957 $(ed.spell_span).trigger('click');
2958 this.set_spellcheck_state('ready');
2962 this.display_spellcheck_controls = function(vis)
2964 if (this.env.spellcheck) {
2965 // stop spellchecking process
2967 this.stop_spellchecking();
2969 $(this.env.spellcheck.spell_container).css('visibility', vis ? 'visible' : 'hidden');
2973 this.set_spellcheck_state = function(s)
2975 this.spellcheck_ready = (s == 'ready' || s == 'no_error_found');
2976 this.enable_command('spellcheck', this.spellcheck_ready);
2979 this.set_draft_id = function(id)
2981 $("input[name='_draft_saveid']").val(id);
2984 this.auto_save_start = function()
2986 if (this.env.draft_autosave)
2987 this.save_timer = self.setTimeout(function(){ ref.command("savedraft"); }, this.env.draft_autosave * 1000);
2989 // Unlock interface now that saving is complete
2993 this.compose_field_hash = function(save)
2995 // check input fields
2997 value_to = $("[name='_to']").val(),
2998 value_cc = $("[name='_cc']").val(),
2999 value_bcc = $("[name='_bcc']").val(),
3000 value_subject = $("[name='_subject']").val();
3003 str += value_to+':';
3005 str += value_cc+':';
3007 str += value_bcc+':';
3009 str += value_subject+':';
3011 if (window.tinyMCE && (ed = tinyMCE.get(this.env.composebody)))
3012 str += ed.getContent();
3014 str += $("[name='_message']").val();
3016 if (this.env.attachments)
3017 for (var upload_id in this.env.attachments)
3021 this.cmp_hash = str;
3026 this.change_identity = function(obj, show_sig)
3028 if (!obj || !obj.options)
3032 show_sig = this.env.show_sig;
3034 var cursor_pos, p = -1,
3035 id = obj.options[obj.selectedIndex].value,
3036 input_message = $("[name='_message']"),
3037 message = input_message.val(),
3038 is_html = ($("input[name='_is_html']").val() == '1'),
3039 sig = this.env.identity,
3040 sig_separator = this.env.sig_above && (this.env.compose_mode == 'reply' || this.env.compose_mode == 'forward') ? '---' : '-- ';
3042 // enable manual signature insert
3043 if (this.env.signatures && this.env.signatures[id]) {
3044 this.enable_command('insert-sig', true);
3045 this.env.compose_commands.push('insert-sig');
3048 this.enable_command('insert-sig', false);
3051 // remove the 'old' signature
3052 if (show_sig && sig && this.env.signatures && this.env.signatures[sig]) {
3054 sig = this.env.signatures[sig].is_html ? this.env.signatures[sig].plain_text : this.env.signatures[sig].text;
3055 sig = sig.replace(/\r\n/g, '\n');
3057 if (!sig.match(/^--[ -]\n/))
3058 sig = sig_separator + '\n' + sig;
3060 p = this.env.sig_above ? message.indexOf(sig) : message.lastIndexOf(sig);
3062 message = message.substring(0, p) + message.substring(p+sig.length, message.length);
3064 // add the new signature string
3065 if (show_sig && this.env.signatures && this.env.signatures[id]) {
3066 sig = this.env.signatures[id]['is_html'] ? this.env.signatures[id]['plain_text'] : this.env.signatures[id]['text'];
3067 sig = sig.replace(/\r\n/g, '\n');
3069 if (!sig.match(/^--[ -]\n/))
3070 sig = sig_separator + '\n' + sig;
3072 if (this.env.sig_above) {
3073 if (p >= 0) { // in place of removed signature
3074 message = message.substring(0, p) + sig + message.substring(p, message.length);
3077 else if (pos = this.get_caret_pos(input_message.get(0))) { // at cursor position
3078 message = message.substring(0, pos) + '\n' + sig + '\n\n' + message.substring(pos, message.length);
3083 message = '\n\n' + sig + '\n\n' + message.replace(/^[\r\n]+/, '');
3087 message = message.replace(/[\r\n]+$/, '');
3088 cursor_pos = !this.env.top_posting && message.length ? message.length+1 : 0;
3089 message += '\n\n' + sig;
3093 cursor_pos = this.env.top_posting ? 0 : message.length;
3095 input_message.val(message);
3097 // move cursor before the signature
3098 this.set_caret_pos(input_message.get(0), cursor_pos);
3100 else if (show_sig && this.env.signatures) { // html
3101 var editor = tinyMCE.get(this.env.composebody),
3102 sigElem = editor.dom.get('_rc_sig');
3104 // Append the signature as a div within the body
3106 var body = editor.getBody(),
3107 doc = editor.getDoc();
3109 sigElem = doc.createElement('div');
3110 sigElem.setAttribute('id', '_rc_sig');
3112 if (this.env.sig_above) {
3113 // if no existing sig and top posting then insert at caret pos
3114 editor.getWin().focus(); // correct focus in IE & Chrome
3116 var node = editor.selection.getNode();
3117 if (node.nodeName == 'BODY') {
3118 // no real focus, insert at start
3119 body.insertBefore(sigElem, body.firstChild);
3120 body.insertBefore(doc.createElement('br'), body.firstChild);
3123 body.insertBefore(sigElem, node.nextSibling);
3124 body.insertBefore(doc.createElement('br'), node.nextSibling);
3128 if (bw.ie) // add empty line before signature on IE
3129 body.appendChild(doc.createElement('br'));
3131 body.appendChild(sigElem);
3135 if (this.env.signatures[id]) {
3136 if (this.env.signatures[id].is_html) {
3137 sig = this.env.signatures[id].text;
3138 if (!this.env.signatures[id].plain_text.match(/^--[ -]\r?\n/))
3139 sig = sig_separator + '<br />' + sig;
3142 sig = this.env.signatures[id].text;
3143 if (!sig.match(/^--[ -]\r?\n/))
3144 sig = sig_separator + '\n' + sig;
3145 sig = '<pre>' + sig + '</pre>';
3148 sigElem.innerHTML = sig;
3152 this.env.identity = id;
3156 // upload attachment file
3157 this.upload_file = function(form)
3162 // get file input fields
3164 for (var n=0; n<form.elements.length; n++)
3165 if (form.elements[n].type=='file' && form.elements[n].value) {
3170 // create hidden iframe and post upload form
3172 var ts = new Date().getTime();
3173 var frame_name = 'rcmupload'+ts;
3175 // have to do it this way for IE
3176 // otherwise the form will be posted to a new window
3178 var html = '<iframe name="'+frame_name+'" src="program/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>';
3179 document.body.insertAdjacentHTML('BeforeEnd',html);
3181 else { // for standards-compilant browsers
3182 var frame = document.createElement('iframe');
3183 frame.name = frame_name;
3184 frame.style.border = 'none';
3185 frame.style.width = 0;
3186 frame.style.height = 0;
3187 frame.style.visibility = 'hidden';
3188 document.body.appendChild(frame);
3191 // handle upload errors, parsing iframe content in onload
3192 $(frame_name).bind('load', {ts:ts}, function(e) {
3193 var d, content = '';
3195 if (this.contentDocument) {
3196 d = this.contentDocument;
3197 } else if (this.contentWindow) {
3198 d = this.contentWindow.document;
3200 content = d.childNodes[0].innerHTML;
3203 if (!content.match(/add2attachment/) && (!bw.opera || (rcmail.env.uploadframe && rcmail.env.uploadframe == e.data.ts))) {
3204 if (!content.match(/display_message/))
3205 rcmail.display_message(rcmail.get_label('fileuploaderror'), 'error');
3206 rcmail.remove_from_attachment_list(e.data.ts);
3208 // Opera hack: handle double onload
3210 rcmail.env.uploadframe = e.data.ts;
3213 form.target = frame_name;
3214 form.action = this.env.comm_path+'&_action=upload&_uploadid='+ts;
3215 form.setAttribute('enctype', 'multipart/form-data');
3218 // display upload indicator and cancel button
3219 var content = this.get_label('uploading');
3220 if (this.env.loadingicon)
3221 content = '<img src="'+this.env.loadingicon+'" alt="" />'+content;
3222 if (this.env.cancelicon)
3223 content = '<a title="'+this.get_label('cancel')+'" onclick="return rcmail.cancel_attachment_upload(\''+ts+'\', \''+frame_name+'\');" href="#cancelupload"><img src="'+this.env.cancelicon+'" alt="" /></a>'+content;
3224 this.add2attachment_list(ts, { name:'', html:content, complete:false });
3227 // set reference to the form object
3228 this.gui_objects.attachmentform = form;
3232 // add file name to attachment list
3233 // called from upload page
3234 this.add2attachment_list = function(name, att, upload_id)
3236 if (!this.gui_objects.attachmentlist)
3239 var li = $('<li>').attr('id', name).html(att.html);
3242 // replace indicator's li
3243 if (upload_id && (indicator = document.getElementById(upload_id))) {
3244 li.replaceAll(indicator);
3246 else { // add new li
3247 li.appendTo(this.gui_objects.attachmentlist);
3250 if (upload_id && this.env.attachments[upload_id])
3251 delete this.env.attachments[upload_id];
3253 this.env.attachments[name] = att;
3258 this.remove_from_attachment_list = function(name)
3260 if (this.env.attachments[name])
3261 delete this.env.attachments[name];
3263 if (!this.gui_objects.attachmentlist)
3266 var list = this.gui_objects.attachmentlist.getElementsByTagName("li");
3267 for (i=0;i<list.length;i++)
3268 if (list[i].id == name)
3269 this.gui_objects.attachmentlist.removeChild(list[i]);
3272 this.remove_attachment = function(name)
3274 if (name && this.env.attachments[name])
3275 this.http_post('remove-attachment', '_file='+urlencode(name));
3280 this.cancel_attachment_upload = function(name, frame_name)
3282 if (!name || !frame_name)
3285 this.remove_from_attachment_list(name);
3286 $("iframe[name='"+frame_name+"']").remove();
3290 // send remote request to add a new contact
3291 this.add_contact = function(value)
3294 this.http_post('addcontact', '_address='+value);
3299 // send remote request to search mail or contacts
3300 this.qsearch = function(value)
3304 if (this.message_list) {
3305 this.clear_message_list();
3306 if (this.env.search_mods) {
3307 var mods = this.env.search_mods[this.env.mailbox] ? this.env.search_mods[this.env.mailbox] : this.env.search_mods['*'];
3312 addurl += '&_headers='+head_arr.join(',');
3315 } else if (this.contact_list) {
3316 this.contact_list.clear(true);
3317 this.show_contentframe(false);
3320 if (this.gui_objects.search_filter)
3321 addurl += '&_filter=' + this.gui_objects.search_filter.value;
3324 this.env.current_page = 1;
3325 var lock = this.set_busy(true, 'searching');
3326 this.http_request('search', '_q='+urlencode(value)
3327 + (this.env.mailbox ? '&_mbox='+urlencode(this.env.mailbox) : '')
3328 + (this.env.source ? '&_source='+urlencode(this.env.source) : '')
3329 + (this.env.group ? '&_gid='+urlencode(this.env.group) : '')
3330 + (addurl ? addurl : ''), lock);
3335 // reset quick-search form
3336 this.reset_qsearch = function()
3338 if (this.gui_objects.qsearchbox)
3339 this.gui_objects.qsearchbox.value = '';
3341 this.env.search_request = null;
3345 this.sent_successfully = function(type, msg)
3347 this.display_message(msg, type);
3348 // before redirect we need to wait some time for Chrome (#1486177)
3349 window.setTimeout(function(){ ref.list_mailbox(); }, 500);
3353 /*********************************************************/
3354 /********* keyboard live-search methods *********/
3355 /*********************************************************/
3357 // handler for keyboard events on address-fields
3358 this.ksearch_keydown = function(e, obj)
3360 if (this.ksearch_timer)
3361 clearTimeout(this.ksearch_timer);
3364 var key = rcube_event.get_keycode(e);
3365 var mod = rcube_event.get_modifier(e);
3369 case 40: // key down
3370 if (!this.ksearch_pane)
3373 var dir = key==38 ? 1 : 0;
3375 highlight = document.getElementById('rcmksearchSelected');
3377 highlight = this.ksearch_pane.__ul.firstChild;
3380 this.ksearch_select(dir ? highlight.previousSibling : highlight.nextSibling);
3382 return rcube_event.cancel(e);
3385 if (mod == SHIFT_KEY)
3389 if (this.ksearch_selected===null || !this.ksearch_input || !this.ksearch_value)
3392 // insert selected address and hide ksearch pane
3393 this.insert_recipient(this.ksearch_selected);
3394 this.ksearch_hide();
3396 return rcube_event.cancel(e);
3399 this.ksearch_hide();
3404 if (mod != SHIFT_KEY)
3409 this.ksearch_timer = window.setTimeout(function(){ ref.ksearch_get_results(); }, 200);
3410 this.ksearch_input = obj;
3415 this.ksearch_select = function(node)
3417 var current = $('#rcmksearchSelected');
3418 if (current[0] && node) {
3419 current.removeAttr('id').removeClass('selected');
3423 $(node).attr('id', 'rcmksearchSelected').addClass('selected');
3424 this.ksearch_selected = node._rcm_id;
3428 this.insert_recipient = function(id)
3430 if (!this.env.contacts[id] || !this.ksearch_input)
3434 var inp_value = this.ksearch_input.value,
3435 cpos = this.get_caret_pos(this.ksearch_input),
3436 p = inp_value.lastIndexOf(this.ksearch_value, cpos),
3439 // replace search string with full address
3440 pre = inp_value.substring(0, p),
3441 end = inp_value.substring(p+this.ksearch_value.length, inp_value.length);
3443 // insert all members of a group
3444 if (typeof this.env.contacts[id] == 'object' && this.env.contacts[id].id) {
3445 insert += this.env.contacts[id].name + ', ';
3446 this.group2expand = $.extend({}, this.env.contacts[id]);
3447 this.group2expand.input = this.ksearch_input;
3448 this.http_request('group-expand', '_source='+urlencode(this.env.contacts[id].source)+'&_gid='+urlencode(this.env.contacts[id].id), false);
3450 else if (typeof this.env.contacts[id] == 'string')
3451 insert = this.env.contacts[id] + ', ';
3453 this.ksearch_input.value = pre + insert + end;
3455 // set caret to insert pos
3456 cpos = p+insert.length;
3457 if (this.ksearch_input.setSelectionRange)
3458 this.ksearch_input.setSelectionRange(cpos, cpos);
3461 this.replace_group_recipients = function(id, recipients)
3463 if (this.group2expand && this.group2expand.id == id) {
3464 this.group2expand.input.value = this.group2expand.input.value.replace(this.group2expand.name, recipients);
3465 this.group2expand = null;
3469 // address search processor
3470 this.ksearch_get_results = function()
3472 var inp_value = this.ksearch_input ? this.ksearch_input.value : null;
3474 if (inp_value === null)
3477 if (this.ksearch_pane && this.ksearch_pane.is(":visible"))
3478 this.ksearch_pane.hide();
3480 // get string from current cursor pos to last comma
3481 var cpos = this.get_caret_pos(this.ksearch_input),
3482 p = inp_value.lastIndexOf(',', cpos-1),
3483 q = inp_value.substring(p+1, cpos),
3484 min = this.env.autocomplete_min_length;
3486 // trim query string
3489 // Don't (re-)search if the last results are still active
3490 if (q == this.ksearch_value)
3493 if (q.length < min) {
3494 if (!this.env.acinfo) {
3495 var label = this.get_label('autocompletechars');
3496 label = label.replace('$min', min);
3497 this.env.acinfo = this.display_message(label);
3501 else if (this.env.acinfo && q.length == min) {
3502 this.hide_message(this.env.acinfo);
3505 var old_value = this.ksearch_value;
3506 this.ksearch_value = q;
3508 // ...string is empty
3512 // ...new search value contains old one and previous search result was empty
3513 if (old_value && old_value.length && this.env.contacts && !this.env.contacts.length && q.indexOf(old_value) == 0)
3516 var lock = this.display_message(this.get_label('searching'), 'loading');
3517 this.http_post('autocomplete', '_search='+urlencode(q), lock);
3520 this.ksearch_query_results = function(results, search)
3522 // ignore this outdated search response
3523 if (this.ksearch_value && search != this.ksearch_value)
3526 this.env.contacts = results ? results : [];
3527 this.ksearch_display_results(this.env.contacts);
3530 this.ksearch_display_results = function (a_results)
3532 // display search results
3533 if (a_results.length && this.ksearch_input && this.ksearch_value) {
3534 var p, ul, li, text, s_val = this.ksearch_value;
3536 // create results pane if not present
3537 if (!this.ksearch_pane) {
3539 this.ksearch_pane = $('<div>').attr('id', 'rcmKSearchpane').css({ position:'absolute', 'z-index':30000 }).append(ul).appendTo(document.body);
3540 this.ksearch_pane.__ul = ul[0];
3543 // remove all search results
3544 ul = this.ksearch_pane.__ul;
3547 // add each result line to list
3548 for (i=0; i < a_results.length; i++) {
3549 text = typeof a_results[i] == 'object' ? a_results[i].name : a_results[i];
3550 li = document.createElement('LI');
3551 li.innerHTML = text.replace(new RegExp('('+RegExp.escape(s_val)+')', 'ig'), '##$1%%').replace(/</g, '<').replace(/>/g, '>').replace(/##([^%]+)%%/g, '<b>$1</b>');
3552 li.onmouseover = function(){ ref.ksearch_select(this); };
3553 li.onmouseup = function(){ ref.ksearch_click(this) };
3559 $(ul.firstChild).attr('id', 'rcmksearchSelected').addClass('selected');
3560 this.ksearch_selected = 0;
3562 // move the results pane right under the input box and make it visible
3563 var pos = $(this.ksearch_input).offset();
3564 this.ksearch_pane.css({ left:pos.left+'px', top:(pos.top + this.ksearch_input.offsetHeight)+'px' }).show();
3566 // hide results pane
3568 this.ksearch_hide();
3571 this.ksearch_click = function(node)
3573 if (this.ksearch_input)
3574 this.ksearch_input.focus();
3576 this.insert_recipient(node._rcm_id);
3577 this.ksearch_hide();
3580 this.ksearch_blur = function()
3582 if (this.ksearch_timer)
3583 clearTimeout(this.ksearch_timer);
3585 this.ksearch_value = '';
3586 this.ksearch_input = null;
3587 this.ksearch_hide();
3591 this.ksearch_hide = function()
3593 this.ksearch_selected = null;
3595 if (this.ksearch_pane)
3596 this.ksearch_pane.hide();
3600 /*********************************************************/
3601 /********* address book methods *********/
3602 /*********************************************************/
3604 this.contactlist_keypress = function(list)
3606 if (list.key_pressed == list.DELETE_KEY)
3607 this.command('delete');
3610 this.contactlist_select = function(list)
3612 if (this.preview_timer)
3613 clearTimeout(this.preview_timer);
3615 var id, frame, ref = this;
3616 if (id = list.get_single_selection())
3617 this.preview_timer = window.setTimeout(function(){ ref.load_contact(id, 'show'); }, 200);
3618 else if (this.env.contentframe)
3619 this.show_contentframe(false);
3621 this.enable_command('compose', list.selection.length > 0);
3622 this.enable_command('edit', (id && this.env.address_sources && !this.env.address_sources[this.env.source].readonly) ? true : false);
3623 this.enable_command('delete', list.selection.length && this.env.address_sources && !this.env.address_sources[this.env.source].readonly);
3628 this.list_contacts = function(src, group, page)
3634 src = this.env.source;
3636 if (page && this.current_page == page && src == this.env.source && group == this.env.group)
3639 if (src != this.env.source) {
3640 page = this.env.current_page = 1;
3641 this.reset_qsearch();
3643 else if (group != this.env.group)
3644 page = this.env.current_page = 1;
3646 this.select_folder((group ? 'G'+src+group : src), (this.env.group ? 'G'+this.env.source+this.env.group : this.env.source));
3648 this.env.source = src;
3649 this.env.group = group;
3651 // load contacts remotely
3652 if (this.gui_objects.contactslist) {
3653 this.list_contacts_remote(src, group, page);
3657 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
3658 target = window.frames[this.env.contentframe];
3659 add_url = '&_framed=1';
3663 add_url += '&_gid='+group;
3665 add_url += '&_page='+page;
3667 // also send search request to get the correct listing
3668 if (this.env.search_request)
3669 add_url += '&_search='+this.env.search_request;
3671 this.set_busy(true, 'loading');
3672 target.location.href = this.env.comm_path + (src ? '&_source='+urlencode(src) : '') + add_url;
3675 // send remote request to load contacts list
3676 this.list_contacts_remote = function(src, group, page)
3678 // clear message list first
3679 this.contact_list.clear(true);
3680 this.show_contentframe(false);
3681 this.enable_command('delete', 'compose', false);
3683 // send request to server
3684 var url = (src ? '_source='+urlencode(src) : '') + (page ? (src?'&':'') + '_page='+page : ''),
3685 lock = this.set_busy(true, 'loading');
3687 this.env.source = src;
3688 this.env.group = group;
3691 url += '&_gid='+group;
3693 // also send search request to get the right messages
3694 if (this.env.search_request)
3695 url += '&_search='+this.env.search_request;
3697 this.http_request('list', url, lock);
3700 // load contact record
3701 this.load_contact = function(cid, action, framed)
3703 var add_url = '', target = window;
3705 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
3706 add_url = '&_framed=1';
3707 target = window.frames[this.env.contentframe];
3708 this.show_contentframe(true);
3713 if (action && (cid || action=='add') && !this.drag_active) {
3715 add_url += '&_gid='+urlencode(this.env.group);
3717 this.set_busy(true);
3718 target.location.href = this.env.comm_path+'&_action='+action+'&_source='+urlencode(this.env.source)+'&_cid='+urlencode(cid) + add_url;
3723 // copy a contact to the specified target (group or directory)
3724 this.copy_contact = function(cid, to)
3727 cid = this.contact_list.get_selection().join(',');
3729 if (to.type == 'group' && to.source == this.env.source) {
3730 this.http_post('group-addmembers', '_cid='+urlencode(cid)
3731 + '&_source='+urlencode(this.env.source)
3732 + '&_gid='+urlencode(to.id));
3734 else if (to.type == 'group' && !this.env.address_sources[to.source].readonly) {
3735 this.http_post('copy', '_cid='+urlencode(cid)
3736 + '&_source='+urlencode(this.env.source)
3737 + '&_to='+urlencode(to.source)
3738 + '&_togid='+urlencode(to.id)
3739 + (this.env.group ? '&_gid='+urlencode(this.env.group) : ''));
3741 else if (to.id != this.env.source && cid && this.env.address_sources[to.id] && !this.env.address_sources[to.id].readonly) {
3742 this.http_post('copy', '_cid='+urlencode(cid)
3743 + '&_source='+urlencode(this.env.source)
3744 + '&_to='+urlencode(to.id)
3745 + (this.env.group ? '&_gid='+urlencode(this.env.group) : ''));
3749 this.delete_contacts = function()
3751 // exit if no mailbox specified or if selection is empty
3752 var selection = this.contact_list.get_selection();
3753 if (!(selection.length || this.env.cid) || !confirm(this.get_label('deletecontactconfirm')))
3756 var id, a_cids = [], qs = '';
3759 a_cids.push(this.env.cid);
3761 for (var n=0; n<selection.length; n++) {
3764 this.contact_list.remove_row(id, (n == selection.length-1));
3767 // hide content frame if we delete the currently displayed contact
3768 if (selection.length == 1)
3769 this.show_contentframe(false);
3773 qs += '&_gid='+urlencode(this.env.group);
3775 // also send search request to get the right records from the next page
3776 if (this.env.search_request)
3777 qs += '&_search='+this.env.search_request;
3779 // send request to server
3780 this.http_post('delete', '_cid='+urlencode(a_cids.join(','))+'&_source='+urlencode(this.env.source)+'&_from='+(this.env.action ? this.env.action : '')+qs);
3785 // update a contact record in the list
3786 this.update_contact_row = function(cid, cols_arr, newcid)
3789 if (this.contact_list.rows[cid] && (row = this.contact_list.rows[cid].obj)) {
3790 for (var c=0; c<cols_arr.length; c++)
3792 $(row.cells[c]).html(cols_arr[c]);
3796 row.id = 'rcmrow' + newcid;
3797 this.contact_list.remove_row(cid);
3798 this.contact_list.init_row(row);
3799 this.contact_list.selection[0] = newcid;
3800 row.style.display = '';
3809 // add row to contacts list
3810 this.add_contact_row = function(cid, cols, select)
3812 if (!this.gui_objects.contactslist || !this.gui_objects.contactslist.tBodies[0])
3815 var tbody = this.gui_objects.contactslist.tBodies[0],
3816 rowcount = tbody.rows.length,
3818 row = document.createElement('tr');
3820 row.id = 'rcmrow'+cid;
3821 row.className = 'contact '+(even ? 'even' : 'odd');
3823 if (this.contact_list.in_selection(cid))
3824 row.className += ' selected';
3826 // add each submitted col
3827 for (var c in cols) {
3828 col = document.createElement('td');
3829 col.className = String(c).toLowerCase();
3830 col.innerHTML = cols[c];
3831 row.appendChild(col);
3834 this.contact_list.insert_row(row);
3836 this.enable_command('export', (this.contact_list.rowcount > 0));
3839 this.group_create = function()
3841 if (!this.gui_objects.folderlist || !this.env.address_sources[this.env.source].groups)
3844 if (!this.name_input) {
3845 this.name_input = $('<input>').attr('type', 'text');
3846 this.name_input.bind('keydown', function(e){ return rcmail.add_input_keydown(e); });
3847 this.name_input_li = $('<li>').addClass('contactgroup').append(this.name_input);
3849 var li = this.get_folder_li(this.env.source)
3850 this.name_input_li.insertAfter(li);
3853 this.name_input.select().focus();
3856 this.group_rename = function()
3858 if (!this.env.group || !this.gui_objects.folderlist)
3861 if (!this.name_input) {
3862 this.enable_command('list', 'listgroup', false);
3863 this.name_input = $('<input>').attr('type', 'text').val(this.env.contactgroups['G'+this.env.source+this.env.group].name);
3864 this.name_input.bind('keydown', function(e){ return rcmail.add_input_keydown(e); });
3865 this.env.group_renaming = true;
3867 var link, li = this.get_folder_li(this.env.source+this.env.group, 'rcmliG');
3868 if (li && (link = li.firstChild)) {
3869 $(link).hide().before(this.name_input);
3873 this.name_input.select().focus();
3876 this.group_delete = function()
3879 this.http_post('group-delete', '_source='+urlencode(this.env.source)+'&_gid='+urlencode(this.env.group), true);
3882 // callback from server upon group-delete command
3883 this.remove_group_item = function(prop)
3885 var li, key = 'G'+prop.source+prop.id;
3886 if ((li = this.get_folder_li(key))) {
3887 this.triggerEvent('group_delete', { source:prop.source, id:prop.id, li:li });
3889 li.parentNode.removeChild(li);
3890 delete this.env.contactfolders[key];
3891 delete this.env.contactgroups[key];
3894 this.list_contacts(prop.source, 0);
3897 // handler for keyboard events on the input field
3898 this.add_input_keydown = function(e)
3900 var key = rcube_event.get_keycode(e);
3904 var newname = this.name_input.val();
3907 var lock = this.set_busy(true, 'loading');
3908 if (this.env.group_renaming)
3909 this.http_post('group-rename', '_source='+urlencode(this.env.source)+'&_gid='+urlencode(this.env.group)+'&_name='+urlencode(newname), lock);
3911 this.http_post('group-create', '_source='+urlencode(this.env.source)+'&_name='+urlencode(newname), lock);
3917 this.reset_add_input();
3922 this.reset_add_input = function()
3924 if (this.name_input) {
3925 if (this.env.group_renaming) {
3926 var li = this.name_input.parent();
3927 li.children().last().show();
3928 this.env.group_renaming = false;
3931 this.name_input.remove();
3933 if (this.name_input_li)
3934 this.name_input_li.remove();
3936 this.name_input = this.name_input_li = null;
3939 this.enable_command('list', 'listgroup', true);
3942 // callback for creating a new contact group
3943 this.insert_contact_group = function(prop)
3945 this.reset_add_input();
3947 prop.type = 'group';
3948 var key = 'G'+prop.source+prop.id;
3949 this.env.contactfolders[key] = this.env.contactgroups[key] = prop;
3951 var link = $('<a>').attr('href', '#')
3952 .bind('click', function() { return rcmail.command('listgroup', prop, this);})
3954 var li = $('<li>').attr('id', 'rcmli'+key)
3955 .addClass('contactgroup')
3957 .insertAfter(this.get_folder_li(prop.source));
3959 this.triggerEvent('group_insert', { id:prop.id, source:prop.source, name:prop.name, li:li[0] });
3962 // callback for renaming a contact group
3963 this.update_contact_group = function(prop)
3965 this.reset_add_input();
3967 var key = 'G'+prop.source+prop.id, link, li = this.get_folder_li(key);
3969 if (li && (link = li.firstChild) && link.tagName.toLowerCase() == 'a')
3970 link.innerHTML = prop.name;
3972 this.env.contactfolders[key].name = this.env.contactgroups[key].name = prop.name;
3973 this.triggerEvent('group_update', { id:prop.id, source:prop.source, name:prop.name, li:li[0] });
3977 /*********************************************************/
3978 /********* user settings methods *********/
3979 /*********************************************************/
3981 this.init_subscription_list = function()
3984 this.subscription_list = new rcube_list_widget(this.gui_objects.subscriptionlist,
3985 {multiselect:false, draggable:true, keyboard:false, toggleselect:true});
3986 this.subscription_list.addEventListener('select', function(o){ p.subscription_select(o); });
3987 this.subscription_list.addEventListener('dragstart', function(o){ p.drag_active = true; });
3988 this.subscription_list.addEventListener('dragend', function(o){ p.subscription_move_folder(o); });
3989 this.subscription_list.row_init = function (row) {
3990 row.obj.onmouseover = function() { p.focus_subscription(row.id); };
3991 row.obj.onmouseout = function() { p.unfocus_subscription(row.id); };
3993 this.subscription_list.init();
3996 // preferences section select and load options frame
3997 this.section_select = function(list)
3999 var id = list.get_single_selection();
4002 var add_url = '', target = window;
4003 this.set_busy(true);
4005 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
4006 add_url = '&_framed=1';
4007 target = window.frames[this.env.contentframe];
4009 target.location.href = this.env.comm_path+'&_action=edit-prefs&_section='+id+add_url;
4015 this.identity_select = function(list)
4018 if (id = list.get_single_selection())
4019 this.load_identity(id, 'edit-identity');
4022 // load identity record
4023 this.load_identity = function(id, action)
4025 if (action=='edit-identity' && (!id || id==this.env.iid))
4028 var add_url = '', target = window;
4030 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
4031 add_url = '&_framed=1';
4032 target = window.frames[this.env.contentframe];
4033 document.getElementById(this.env.contentframe).style.visibility = 'inherit';
4036 if (action && (id || action=='add-identity')) {
4037 this.set_busy(true);
4038 target.location.href = this.env.comm_path+'&_action='+action+'&_iid='+id+add_url;
4044 this.delete_identity = function(id)
4046 // exit if no mailbox specified or if selection is empty
4047 var selection = this.identity_list.get_selection();
4048 if (!(selection.length || this.env.iid))
4052 id = this.env.iid ? this.env.iid : selection[0];
4054 // append token to request
4055 this.goto_url('delete-identity', '_iid='+id+'&_token='+this.env.request_token, true);
4060 this.focus_subscription = function(id)
4063 delim = RegExp.escape(this.env.delimiter),
4064 reg = RegExp('['+delim+']?[^'+delim+']+$');
4066 if (this.drag_active && this.env.mailbox && (row = document.getElementById(id)))
4067 if (this.env.subscriptionrows[id] &&
4068 (folder = this.env.subscriptionrows[id][0])) {
4069 if (this.check_droptarget(folder) &&
4070 !this.env.subscriptionrows[this.get_folder_row_id(this.env.mailbox)][2] &&
4071 (folder != this.env.mailbox.replace(reg, '')) &&
4072 (!folder.match(new RegExp('^'+RegExp.escape(this.env.mailbox+this.env.delimiter))))) {
4073 this.set_env('dstfolder', folder);
4074 $(row).addClass('droptarget');
4077 else if (this.env.mailbox.match(new RegExp(delim))) {
4078 this.set_env('dstfolder', this.env.delimiter);
4079 $(this.subscription_list.frame).addClass('droptarget');
4083 this.unfocus_subscription = function(id)
4085 var row = $('#'+id);
4087 this.set_env('dstfolder', null);
4088 if (this.env.subscriptionrows[id] && row[0])
4089 row.removeClass('droptarget');
4091 $(this.subscription_list.frame).removeClass('droptarget');
4094 this.subscription_select = function(list)
4098 if (list && (id = list.get_single_selection()) &&
4099 (folder = this.env.subscriptionrows['rcmrow'+id])
4101 this.set_env('mailbox', folder[0]);
4102 this.show_folder(folder[0]);
4103 this.enable_command('delete-folder', !folder[2]);
4106 this.env.mailbox = null;
4107 this.show_contentframe(false);
4108 this.enable_command('delete-folder', 'purge', false);
4112 this.subscription_move_folder = function(list)
4114 var delim = RegExp.escape(this.env.delimiter),
4115 reg = RegExp('['+delim+']?[^'+delim+']+$');
4117 if (this.env.mailbox && this.env.dstfolder && (this.env.dstfolder != this.env.mailbox) &&
4118 (this.env.dstfolder != this.env.mailbox.replace(reg, ''))
4120 reg = new RegExp('[^'+delim+']*['+delim+']', 'g');
4121 var lock = this.set_busy(true, 'foldermoving'),
4122 basename = this.env.mailbox.replace(reg, ''),
4123 newname = this.env.dstfolder==this.env.delimiter ? basename : this.env.dstfolder+this.env.delimiter+basename;
4125 this.http_post('rename-folder', '_folder_oldname='+urlencode(this.env.mailbox)+'&_folder_newname='+urlencode(newname), lock);
4127 this.drag_active = false;
4128 this.unfocus_subscription(this.get_folder_row_id(this.env.dstfolder));
4131 // tell server to create and subscribe a new mailbox
4132 this.create_folder = function()
4134 this.show_folder('', this.env.mailbox);
4137 // delete a specific mailbox with all its messages
4138 this.delete_folder = function(name)
4140 var id = this.get_folder_row_id(name ? name : this.env.mailbox),
4141 folder = this.env.subscriptionrows[id][0];
4143 if (folder && confirm(this.get_label('deletefolderconfirm'))) {
4144 var lock = this.set_busy(true, 'folderdeleting');
4145 this.http_post('delete-folder', '_mbox='+urlencode(folder), lock);
4149 // add a new folder to the subscription list by cloning a folder row
4150 this.add_folder_row = function(name, display_name, replace, before)
4152 if (!this.gui_objects.subscriptionlist)
4155 // find not protected folder
4157 for (var rid in this.env.subscriptionrows) {
4158 if (this.env.subscriptionrows[rid]!=null && !this.env.subscriptionrows[rid][2]) {
4165 tbody = this.gui_objects.subscriptionlist.tBodies[0],
4166 id = 'rcmrow'+(tbody.childNodes.length+1),
4167 selection = this.subscription_list.get_single_selection();
4169 if (replace && replace.id) {
4174 if (!id || !refid || !(refrow = document.getElementById(refid))) {
4175 // Refresh page if we don't have a table row to clone
4176 this.goto_url('folders');
4180 // clone a table row if there are existing rows
4181 var row = this.clone_table_row(refrow);
4184 if (before && (before = this.get_folder_row_id(before)))
4185 tbody.insertBefore(row, document.getElementById(before));
4187 tbody.appendChild(row);
4190 tbody.removeChild(replace);
4192 // add to folder/row-ID map
4193 this.env.subscriptionrows[row.id] = [name, display_name, 0];
4196 row.cells[0].innerHTML = display_name;
4199 // set messages count to zero
4200 row.cells[1].innerHTML = '*';
4202 // update subscription checkbox
4203 $('input[name="_subscribed[]"]', row).val(name).attr('checked', true);
4206 this.init_subscription_list();
4207 if (selection && document.getElementById('rcmrow'+selection))
4208 this.subscription_list.select_row(selection);
4210 if (document.getElementById(id).scrollIntoView)
4211 document.getElementById(id).scrollIntoView();
4214 // replace an existing table row with a new folder line
4215 this.replace_folder_row = function(oldfolder, newfolder, display_name, before)
4217 var id = this.get_folder_row_id(oldfolder),
4218 row = document.getElementById(id);
4220 // replace an existing table row (if found)
4221 this.add_folder_row(newfolder, display_name, row, before);
4224 // remove the table row of a specific mailbox from the table
4225 // (the row will not be removed, just hidden)
4226 this.remove_folder_row = function(folder)
4228 var row, id = this.get_folder_row_id(folder);
4230 if (id && (row = document.getElementById(id)))
4231 row.style.display = 'none';
4234 this.subscribe = function(folder)
4237 var lock = this.display_message(this.get_label('foldersubscribing'), 'loading');
4238 this.http_post('subscribe', '_mbox='+urlencode(folder), lock);
4242 this.unsubscribe = function(folder)
4245 var lock = this.display_message(this.get_label('folderunsubscribing'), 'loading');
4246 this.http_post('unsubscribe', '_mbox='+urlencode(folder), lock);
4250 // helper method to find a specific mailbox row ID
4251 this.get_folder_row_id = function(folder)
4253 for (var id in this.env.subscriptionrows)
4254 if (this.env.subscriptionrows[id] && this.env.subscriptionrows[id][0] == folder)
4260 // duplicate a specific table row
4261 this.clone_table_row = function(row)
4264 new_row = document.createElement('tr');
4266 for (var n=0; n<row.cells.length; n++) {
4267 cell = row.cells[n];
4268 td = document.createElement('td');
4271 td.className = cell.className;
4273 td.setAttribute('align', cell.align);
4275 td.innerHTML = cell.innerHTML;
4276 new_row.appendChild(td);
4282 // when user select a folder in manager
4283 this.show_folder = function(folder, path, force)
4285 var target = window,
4286 url = '&_action=edit-folder&_mbox='+urlencode(folder);
4289 url += '&_path='+urlencode(path);
4291 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
4292 target = window.frames[this.env.contentframe];
4293 url += '&_framed=1';
4296 if (String(target.location.href).indexOf(url) >= 0 && !force) {
4297 this.show_contentframe(true);
4300 if (!this.env.frame_lock) {
4301 (parent.rcmail ? parent.rcmail : this).env.frame_lock = this.set_busy(true, 'loading');
4303 target.location.href = this.env.comm_path+url;
4307 // disables subscription checkbox (for protected folder)
4308 this.disable_subscription = function(folder)
4310 var id = this.get_folder_row_id(folder);
4312 $('input[name="_subscribed[]"]', $('#'+id)).attr('disabled', true);
4315 this.folder_size = function(folder)
4317 var lock = this.set_busy(true, 'loading');
4318 this.http_post('folder-size', '_mbox='+urlencode(folder), lock);
4321 this.folder_size_update = function(size)
4323 $('#folder-size').replaceWith(size);
4327 /*********************************************************/
4328 /********* GUI functionality *********/
4329 /*********************************************************/
4331 // enable/disable buttons for page shifting
4332 this.set_page_buttons = function()
4334 this.enable_command('nextpage', 'lastpage', (this.env.pagecount > this.env.current_page));
4335 this.enable_command('previouspage', 'firstpage', (this.env.current_page > 1));
4338 // set event handlers on registered buttons
4339 this.init_buttons = function()
4341 for (var cmd in this.buttons) {
4342 if (typeof cmd != 'string')
4345 for (var i=0; i< this.buttons[cmd].length; i++) {
4346 var prop = this.buttons[cmd][i];
4347 var elm = document.getElementById(prop.id);
4351 var preload = false;
4352 if (prop.type == 'image') {
4353 elm = elm.parentNode;
4360 elm.onmousedown = function(e){ return rcmail.button_sel(this._command, this._id); };
4361 elm.onmouseup = function(e){ return rcmail.button_out(this._command, this._id); };
4363 new Image().src = prop.sel;
4366 elm.onmouseover = function(e){ return rcmail.button_over(this._command, this._id); };
4367 elm.onmouseout = function(e){ return rcmail.button_out(this._command, this._id); };
4369 new Image().src = prop.over;
4375 // set button to a specific state
4376 this.set_button = function(command, state)
4378 var button, obj, a_buttons = this.buttons[command];
4380 if (!a_buttons || !a_buttons.length)
4383 for (var n=0; n<a_buttons.length; n++) {
4384 button = a_buttons[n];
4385 obj = document.getElementById(button.id);
4387 // get default/passive setting of the button
4388 if (obj && button.type=='image' && !button.status) {
4389 button.pas = obj._original_src ? obj._original_src : obj.src;
4390 // respect PNG fix on IE browsers
4391 if (obj.runtimeStyle && obj.runtimeStyle.filter && obj.runtimeStyle.filter.match(/src=['"]([^'"]+)['"]/))
4392 button.pas = RegExp.$1;
4394 else if (obj && !button.status)
4395 button.pas = String(obj.className);
4397 // set image according to button state
4398 if (obj && button.type=='image' && button[state]) {
4399 button.status = state;
4400 obj.src = button[state];
4402 // set class name according to button state
4403 else if (obj && typeof(button[state])!='undefined') {
4404 button.status = state;
4405 obj.className = button[state];
4407 // disable/enable input buttons
4408 if (obj && button.type=='input') {
4409 button.status = state;
4410 obj.disabled = !state;
4415 // display a specific alttext
4416 this.set_alttext = function(command, label)
4418 if (!this.buttons[command] || !this.buttons[command].length)
4421 var button, obj, link;
4422 for (var n=0; n<this.buttons[command].length; n++) {
4423 button = this.buttons[command][n];
4424 obj = document.getElementById(button.id);
4426 if (button.type=='image' && obj) {
4427 obj.setAttribute('alt', this.get_label(label));
4428 if ((link = obj.parentNode) && link.tagName.toLowerCase() == 'a')
4429 link.setAttribute('title', this.get_label(label));
4432 obj.setAttribute('title', this.get_label(label));
4436 // mouse over button
4437 this.button_over = function(command, id)
4439 var button, elm, a_buttons = this.buttons[command];
4441 if (!a_buttons || !a_buttons.length)
4444 for (var n=0; n<a_buttons.length; n++) {
4445 button = a_buttons[n];
4446 if (button.id == id && button.status == 'act') {
4447 elm = document.getElementById(button.id);
4448 if (elm && button.over) {
4449 if (button.type == 'image')
4450 elm.src = button.over;
4452 elm.className = button.over;
4458 // mouse down on button
4459 this.button_sel = function(command, id)
4461 var button, elm, a_buttons = this.buttons[command];
4463 if (!a_buttons || !a_buttons.length)
4466 for (var n=0; n<a_buttons.length; n++) {
4467 button = a_buttons[n];
4468 if (button.id == id && button.status == 'act') {
4469 elm = document.getElementById(button.id);
4470 if (elm && button.sel) {
4471 if (button.type == 'image')
4472 elm.src = button.sel;
4474 elm.className = button.sel;
4476 this.buttons_sel[id] = command;
4481 // mouse out of button
4482 this.button_out = function(command, id)
4484 var button, elm, a_buttons = this.buttons[command];
4486 if (!a_buttons || !a_buttons.length)
4489 for (var n=0; n<a_buttons.length; n++) {
4490 button = a_buttons[n];
4491 if (button.id == id && button.status == 'act') {
4492 elm = document.getElementById(button.id);
4493 if (elm && button.act) {
4494 if (button.type == 'image')
4495 elm.src = button.act;
4497 elm.className = button.act;
4503 // write to the document/window title
4504 this.set_pagetitle = function(title)
4506 if (title && document.title)
4507 document.title = title;
4510 // display a system message, list of types in common.css (below #message definition)
4511 this.display_message = function(msg, type)
4513 // pass command to parent window
4514 if (this.is_framed())
4515 return parent.rcmail.display_message(msg, type);
4517 if (!this.gui_objects.message) {
4518 // save message in order to display after page loaded
4519 if (type != 'loading')
4520 this.pending_message = new Array(msg, type);
4524 type = type ? type : 'notice';
4529 id = type + date.getTime(),
4530 timeout = this.message_time * (type == 'error' || type == 'warning' ? 2 : 1);
4532 if (type == 'loading') {
4534 timeout = this.env.request_timeout * 1000;
4536 msg = this.get_label('loading');
4539 // The same message is already displayed
4540 if (this.messages[key]) {
4542 if (this.messages[key].obj)
4543 this.messages[key].obj.html(msg);
4544 // store label in stack
4545 if (type == 'loading') {
4546 this.messages[key].labels.push({'id': id, 'msg': msg});
4548 // add element and set timeout
4549 this.messages[key].elements.push(id);
4550 window.setTimeout(function() { ref.hide_message(id, type == 'loading'); }, timeout);
4554 // create DOM object and display it
4555 var obj = $('<div>').addClass(type).html(msg).data('key', key),
4556 cont = $(this.gui_objects.message).append(obj).show();
4558 this.messages[key] = {'obj': obj, 'elements': [id]};
4560 if (type == 'loading') {
4561 this.messages[key].labels = [{'id': id, 'msg': msg}];
4564 obj.click(function() { return ref.hide_message(obj); });
4567 window.setTimeout(function() { ref.hide_message(id, type == 'loading'); }, timeout);
4571 // make a message to disapear
4572 this.hide_message = function(obj, fade)
4574 // pass command to parent window
4575 if (this.is_framed())
4576 return parent.rcmail.hide_message(obj, fade);
4578 var k, n, i, msg, m = this.messages;
4580 // Hide message by object, don't use for 'loading'!
4581 if (typeof(obj) == 'object') {
4582 $(obj)[fade?'fadeOut':'hide']();
4583 msg = $(obj).data('key');
4584 if (this.messages[msg])
4585 delete this.messages[msg];
4587 // Hide message by id
4590 for (n in m[k].elements) {
4591 if (m[k] && m[k].elements[n] == obj) {
4592 m[k].elements.splice(n, 1);
4593 // hide DOM element if last instance is removed
4594 if (!m[k].elements.length) {
4595 m[k].obj[fade?'fadeOut':'hide']();
4598 // set pending action label for 'loading' message
4599 else if (k == 'loading') {
4600 for (i in m[k].labels) {
4601 if (m[k].labels[i].id == obj) {
4602 delete m[k].labels[i];
4605 msg = m[k].labels[i].msg;
4616 // mark a mailbox as selected and set environment variable
4617 this.select_folder = function(name, old, prefix)
4619 if (this.gui_objects.folderlist) {
4620 var current_li, target_li;
4622 if ((current_li = this.get_folder_li(old, prefix))) {
4623 $(current_li).removeClass('selected').addClass('unfocused');
4625 if ((target_li = this.get_folder_li(name, prefix))) {
4626 $(target_li).removeClass('unfocused').addClass('selected');
4629 // trigger event hook
4630 this.triggerEvent('selectfolder', { folder:name, old:old, prefix:prefix });
4634 // helper method to find a folder list item
4635 this.get_folder_li = function(name, prefix)
4640 if (this.gui_objects.folderlist) {
4641 name = String(name).replace(this.identifier_expr, '_');
4642 return document.getElementById(prefix+name);
4648 // for reordering column array (Konqueror workaround)
4649 // and for setting some message list global variables
4650 this.set_message_coltypes = function(coltypes, repl)
4652 var list = this.message_list,
4653 thead = list ? list.list.tHead : null,
4654 cell, col, n, len, th, tr;
4656 this.env.coltypes = coltypes;
4658 // replace old column headers
4661 th = document.createElement('thead');
4662 tr = document.createElement('tr');
4664 for (c=0, len=repl.length; c < len; c++) {
4665 cell = document.createElement('td');
4666 cell.innerHTML = repl[c].html;
4667 if (repl[c].id) cell.id = repl[c].id;
4668 if (repl[c].className) cell.className = repl[c].className;
4669 tr.appendChild(cell);
4672 thead.parentNode.replaceChild(th, thead);
4676 for (n=0, len=this.env.coltypes.length; n<len; n++) {
4677 col = this.env.coltypes[n];
4678 if ((cell = thead.rows[0].cells[n]) && (col=='from' || col=='to')) {
4679 cell.id = 'rcm'+col;
4680 // if we have links for sorting, it's a bit more complicated...
4681 if (cell.firstChild && cell.firstChild.tagName.toLowerCase()=='a') {
4682 cell = cell.firstChild;
4683 cell.onclick = function(){ return rcmail.command('sort', this.__col, this); };
4686 cell.innerHTML = this.get_label(col);
4691 this.env.subject_col = null;
4692 this.env.flagged_col = null;
4693 this.env.status_col = null;
4695 if ((n = $.inArray('subject', this.env.coltypes)) >= 0) {
4696 this.set_env('subject_col', n);
4698 list.subject_col = n;
4700 if ((n = $.inArray('flag', this.env.coltypes)) >= 0)
4701 this.set_env('flagged_col', n);
4702 if ((n = $.inArray('status', this.env.coltypes)) >= 0)
4703 this.set_env('status_col', n);
4709 // replace content of row count display
4710 this.set_rowcount = function(text)
4712 $(this.gui_objects.countdisplay).html(text);
4714 // update page navigation buttons
4715 this.set_page_buttons();
4718 // replace content of mailboxname display
4719 this.set_mailboxname = function(content)
4721 if (this.gui_objects.mailboxname && content)
4722 this.gui_objects.mailboxname.innerHTML = content;
4725 // replace content of quota display
4726 this.set_quota = function(content)
4728 if (content && this.gui_objects.quotadisplay) {
4729 if (typeof(content) == 'object' && content.type == 'image')
4730 this.percent_indicator(this.gui_objects.quotadisplay, content);
4732 $(this.gui_objects.quotadisplay).html(content);
4736 // update the mailboxlist
4737 this.set_unread_count = function(mbox, count, set_title)
4739 if (!this.gui_objects.mailboxlist)
4742 this.env.unread_counts[mbox] = count;
4743 this.set_unread_count_display(mbox, set_title);
4746 // update the mailbox count display
4747 this.set_unread_count_display = function(mbox, set_title)
4749 var reg, text_obj, item, mycount, childcount, div;
4751 if (item = this.get_folder_li(mbox)) {
4752 mycount = this.env.unread_counts[mbox] ? this.env.unread_counts[mbox] : 0;
4753 text_obj = item.getElementsByTagName('a')[0];
4754 reg = /\s+\([0-9]+\)$/i;
4757 if ((div = item.getElementsByTagName('div')[0]) &&
4758 div.className.match(/collapsed/)) {
4759 // add children's counters
4760 for (var k in this.env.unread_counts)
4761 if (k.indexOf(mbox + this.env.delimiter) == 0)
4762 childcount += this.env.unread_counts[k];
4765 if (mycount && text_obj.innerHTML.match(reg))
4766 text_obj.innerHTML = text_obj.innerHTML.replace(reg, ' ('+mycount+')');
4768 text_obj.innerHTML += ' ('+mycount+')';
4770 text_obj.innerHTML = text_obj.innerHTML.replace(reg, '');
4772 // set parent's display
4773 reg = new RegExp(RegExp.escape(this.env.delimiter) + '[^' + RegExp.escape(this.env.delimiter) + ']+$');
4774 if (mbox.match(reg))
4775 this.set_unread_count_display(mbox.replace(reg, ''), false);
4777 // set the right classes
4778 if ((mycount+childcount)>0)
4779 $(item).addClass('unread');
4781 $(item).removeClass('unread');
4784 // set unread count to window title
4785 reg = /^\([0-9]+\)\s+/i;
4786 if (set_title && document.title) {
4788 doc_title = String(document.title);
4790 if (mycount && doc_title.match(reg))
4791 new_title = doc_title.replace(reg, '('+mycount+') ');
4793 new_title = '('+mycount+') '+doc_title;
4795 new_title = doc_title.replace(reg, '');
4797 this.set_pagetitle(new_title);
4801 // notifies that a new message(s) has hit the mailbox
4802 this.new_message_focus = function()
4804 // focus main window
4805 if (this.env.framed && window.parent)
4806 window.parent.focus();
4811 this.toggle_prefer_html = function(checkbox)
4814 if (elem = document.getElementById('rcmfd_addrbook_show_images'))
4815 elem.disabled = !checkbox.checked;
4818 this.toggle_preview_pane = function(checkbox)
4821 if (elem = document.getElementById('rcmfd_preview_pane_mark_read'))
4822 elem.disabled = !checkbox.checked;
4825 // display fetched raw headers
4826 this.set_headers = function(content)
4828 if (this.gui_objects.all_headers_row && this.gui_objects.all_headers_box && content)
4829 $(this.gui_objects.all_headers_box).html(content).show();
4832 // display all-headers row and fetch raw message headers
4833 this.load_headers = function(elem)
4835 if (!this.gui_objects.all_headers_row || !this.gui_objects.all_headers_box || !this.env.uid)
4838 $(elem).removeClass('show-headers').addClass('hide-headers');
4839 $(this.gui_objects.all_headers_row).show();
4840 elem.onclick = function() { rcmail.hide_headers(elem); };
4842 // fetch headers only once
4843 if (!this.gui_objects.all_headers_box.innerHTML) {
4844 var lock = this.display_message(this.get_label('loading'), 'loading');
4845 this.http_post('headers', '_uid='+this.env.uid, lock);
4849 // hide all-headers row
4850 this.hide_headers = function(elem)
4852 if (!this.gui_objects.all_headers_row || !this.gui_objects.all_headers_box)
4855 $(elem).removeClass('hide-headers').addClass('show-headers');
4856 $(this.gui_objects.all_headers_row).hide();
4857 elem.onclick = function() { rcmail.load_headers(elem); };
4860 // percent (quota) indicator
4861 this.percent_indicator = function(obj, data)
4866 var limit_high = 80,
4868 width = data.width ? data.width : this.env.indicator_width ? this.env.indicator_width : 100,
4869 height = data.height ? data.height : this.env.indicator_height ? this.env.indicator_height : 14,
4870 quota = data.percent ? Math.abs(parseInt(data.percent)) : 0,
4871 quota_width = parseInt(quota / 100 * width),
4872 pos = $(obj).position();
4874 // workarounds for Opera and Webkit bugs
4875 pos.top = Math.max(0, pos.top);
4876 pos.left = Math.max(0, pos.left);
4878 this.env.indicator_width = width;
4879 this.env.indicator_height = height;
4882 if (quota_width > width) {
4883 quota_width = width;
4888 data.title = this.get_label('quota') + ': ' + data.title;
4891 var main = $('<div>');
4892 main.css({position: 'absolute', top: pos.top, left: pos.left,
4893 width: width + 'px', height: height + 'px', zIndex: 100, lineHeight: height + 'px'})
4894 .attr('title', data.title).addClass('quota_text').html(quota + '%');
4896 var bar1 = $('<div>');
4897 bar1.css({position: 'absolute', top: pos.top + 1, left: pos.left + 1,
4898 width: quota_width + 'px', height: height + 'px', zIndex: 99});
4900 var bar2 = $('<div>');
4901 bar2.css({position: 'absolute', top: pos.top + 1, left: pos.left + 1,
4902 width: width + 'px', height: height + 'px', zIndex: 98})
4903 .addClass('quota_bg');
4905 if (quota >= limit_high) {
4906 main.addClass(' quota_text_high');
4907 bar1.addClass('quota_high');
4909 else if(quota >= limit_mid) {
4910 main.addClass(' quota_text_mid');
4911 bar1.addClass('quota_mid');
4914 main.addClass(' quota_text_normal');
4915 bar1.addClass('quota_low');
4918 // replace quota image
4919 $(obj).html('').append(bar1).append(bar2).append(main);
4920 // update #quotaimg title
4921 $('#quotaimg').attr('title', data.title);
4924 /********************************************************/
4925 /********* html to text conversion functions *********/
4926 /********************************************************/
4928 this.html2plain = function(htmlText, id)
4931 url = '?_task=utils&_action=html2text',
4932 lock = this.set_busy(true, 'converting');
4934 console.log('HTTP POST: ' + url);
4936 $.ajax({ type: 'POST', url: url, data: htmlText, contentType: 'application/octet-stream',
4937 error: function(o, status, err) { rcmail.http_error(o, status, err, lock); },
4938 success: function(data) { rcmail.set_busy(false, null, lock); $(document.getElementById(id)).val(data); console.log(data); }
4942 this.plain2html = function(plainText, id)
4944 var lock = this.set_busy(true, 'converting');
4945 $(document.getElementById(id)).val('<pre>'+plainText+'</pre>');
4946 this.set_busy(false, null, lock);
4950 /********************************************************/
4951 /********* remote request methods *********/
4952 /********************************************************/
4954 this.redirect = function(url, lock)
4956 if (lock || lock === null)
4957 this.set_busy(true);
4959 if (this.env.framed && window.parent)
4960 parent.location.href = url;
4962 location.href = url;
4965 this.goto_url = function(action, query, lock)
4967 var url = this.env.comm_path,
4968 querystring = query ? '&'+query : '';
4970 // overwrite task name
4971 if (action.match(/([a-z]+)\/([a-z-_]+)/)) {
4973 url = url.replace(/\_task=[a-z]+/, '_task='+RegExp.$1);
4976 this.redirect(url+'&_action='+action+querystring, lock);
4979 // send a http request to the server
4980 this.http_request = function(action, query, lock)
4982 var url = this.env.comm_path;
4984 // overwrite task name
4985 if (action.match(/([a-z]+)\/([a-z-_]+)/)) {
4987 url = url.replace(/\_task=[a-z]+/, '_task='+RegExp.$1);
4990 // trigger plugin hook
4991 var result = this.triggerEvent('request'+action, query);
4993 if (typeof result != 'undefined') {
4994 // abort if one the handlers returned false
4995 if (result === false)
5001 url += '&_remote=1&_action=' + action + (query ? '&' : '') + query;
5004 console.log('HTTP GET: ' + url);
5006 type: 'GET', url: url, data: { _unlock:(lock?lock:0) }, dataType: 'json',
5007 success: function(data){ ref.http_response(data); },
5008 error: function(o, status, err) { rcmail.http_error(o, status, err, lock); }
5012 // send a http POST request to the server
5013 this.http_post = function(action, postdata, lock)
5015 var url = this.env.comm_path;
5017 // overwrite task name
5018 if (action.match(/([a-z]+)\/([a-z-_]+)/)) {
5020 url = url.replace(/\_task=[a-z]+/, '_task='+RegExp.$1);
5023 url += '&_action=' + action;
5025 if (postdata && typeof(postdata) == 'object') {
5026 postdata._remote = 1;
5027 postdata._unlock = (lock ? lock : 0);
5030 postdata += (postdata ? '&' : '') + '_remote=1' + (lock ? '&_unlock='+lock : '');
5032 // trigger plugin hook
5033 var result = this.triggerEvent('request'+action, postdata);
5034 if (typeof result != 'undefined') {
5035 // abort if one the handlers returned false
5036 if (result === false)
5043 console.log('HTTP POST: ' + url);
5045 type: 'POST', url: url, data: postdata, dataType: 'json',
5046 success: function(data){ ref.http_response(data); },
5047 error: function(o, status, err) { rcmail.http_error(o, status, err, lock); }
5051 // handle HTTP response
5052 this.http_response = function(response)
5057 if (response.unlock)
5058 this.set_busy(false);
5060 this.triggerEvent('responsebefore', {response: response});
5061 this.triggerEvent('responsebefore'+response.action, {response: response});
5065 this.set_env(response.env);
5067 // we have labels to add
5068 if (typeof response.texts == 'object') {
5069 for (var name in response.texts)
5070 if (typeof response.texts[name] == 'string')
5071 this.add_label(name, response.texts[name]);
5074 // if we get javascript code from server -> execute it
5075 if (response.exec) {
5076 console.log(response.exec);
5077 eval(response.exec);
5080 // execute callback functions of plugins
5081 if (response.callbacks && response.callbacks.length) {
5082 for (var i=0; i < response.callbacks.length; i++)
5083 this.triggerEvent(response.callbacks[i][0], response.callbacks[i][1]);
5086 // process the response data according to the sent action
5087 switch (response.action) {
5089 if (this.task == 'addressbook') {
5090 var uid = this.contact_list.get_selection();
5091 this.enable_command('compose', (uid && this.contact_list.rows[uid]));
5092 this.enable_command('delete', 'edit', (uid && this.contact_list.rows[uid] && this.env.address_sources && !this.env.address_sources[this.env.source].readonly));
5093 this.enable_command('export', (this.contact_list && this.contact_list.rowcount > 0));
5097 if (this.env.action == 'show') {
5098 // re-enable commands on move/delete error
5099 this.enable_command(this.env.message_commands, true);
5100 if (!this.env.list_post)
5101 this.enable_command('reply-list', false);
5103 else if (this.task == 'addressbook') {
5104 this.triggerEvent('listupdate', { folder:this.env.source, rowcount:this.contact_list.rowcount });
5109 if (this.task == 'mail') {
5110 if (!this.env.messagecount) {
5111 // clear preview pane content
5112 if (this.env.contentframe)
5113 this.show_contentframe(false);
5114 // disable commands useless when mailbox is empty
5115 this.enable_command(this.env.message_commands, 'purge', 'expunge',
5116 'select-all', 'select-none', 'sort', 'expand-all', 'expand-unread', 'collapse-all', false);
5118 if (this.message_list)
5119 this.triggerEvent('listupdate', { folder:this.env.mailbox, rowcount:this.message_list.rowcount });
5123 case 'check-recent':
5127 if (this.task == 'mail') {
5128 this.enable_command('show', 'expunge', 'select-all', 'select-none', 'sort', (this.env.messagecount > 0));
5129 this.enable_command('purge', this.purge_mailbox_test());
5130 this.enable_command('expand-all', 'expand-unread', 'collapse-all', this.env.threading && this.env.messagecount);
5132 if (response.action == 'list' || response.action == 'search') {
5133 this.msglist_select(this.message_list);
5134 this.triggerEvent('listupdate', { folder:this.env.mailbox, rowcount:this.message_list.rowcount });
5137 else if (this.task == 'addressbook') {
5138 this.enable_command('export', (this.contact_list && this.contact_list.rowcount > 0));
5140 if (response.action == 'list' || response.action == 'search') {
5141 this.enable_command('group-create',
5142 (this.env.address_sources[this.env.source].groups && !this.env.address_sources[this.env.source].readonly));
5143 this.enable_command('group-rename', 'group-delete',
5144 (this.env.address_sources[this.env.source].groups && this.env.group && !this.env.address_sources[this.env.source].readonly));
5145 this.triggerEvent('listupdate', { folder:this.env.source, rowcount:this.contact_list.rowcount });
5151 if (response.unlock)
5152 this.hide_message(response.unlock);
5154 this.triggerEvent('responseafter', {response: response});
5155 this.triggerEvent('responseafter'+response.action, {response: response});
5158 // handle HTTP request errors
5159 this.http_error = function(request, status, err, lock)
5161 var errmsg = request.statusText;
5163 this.set_busy(false, null, lock);
5166 if (request.status && errmsg)
5167 this.display_message(this.get_label('servererror') + ' (' + errmsg + ')', 'error');
5170 // starts interval for keep-alive/check-recent signal
5171 this.start_keepalive = function()
5174 clearInterval(this._int);
5176 if (this.env.keep_alive && !this.env.framed && this.task == 'mail' && this.gui_objects.mailboxlist)
5177 this._int = setInterval(function(){ ref.check_for_recent(false); }, this.env.keep_alive * 1000);
5178 else if (this.env.keep_alive && !this.env.framed && this.task != 'login' && this.env.action != 'print')
5179 this._int = setInterval(function(){ ref.send_keep_alive(); }, this.env.keep_alive * 1000);
5182 // sends keep-alive signal to the server
5183 this.send_keep_alive = function()
5186 this.http_request('keep-alive', '_t='+d.getTime());
5189 // sends request to check for recent messages
5190 this.check_for_recent = function(refresh)
5195 var lock, addurl = '_t=' + (new Date().getTime()) + '&_mbox=' + urlencode(this.env.mailbox);
5198 lock = this.set_busy(true, 'checkingmail');
5199 addurl += '&_refresh=1';
5200 // reset check-recent interval
5201 this.start_keepalive();
5204 if (this.gui_objects.messagelist)
5205 addurl += '&_list=1';
5206 if (this.gui_objects.quotadisplay)
5207 addurl += '&_quota=1';
5208 if (this.env.search_request)
5209 addurl += '&_search=' + this.env.search_request;
5211 this.http_request('check-recent', addurl, lock);
5215 /********************************************************/
5216 /********* helper methods *********/
5217 /********************************************************/
5219 // check if we're in show mode or if we have a unique selection
5220 // and return the message uid
5221 this.get_single_uid = function()
5223 return this.env.uid ? this.env.uid : (this.message_list ? this.message_list.get_single_selection() : null);
5226 // same as above but for contacts
5227 this.get_single_cid = function()
5229 return this.env.cid ? this.env.cid : (this.contact_list ? this.contact_list.get_single_selection() : null);
5232 // gets cursor position
5233 this.get_caret_pos = function(obj)
5235 if (typeof(obj.selectionEnd)!='undefined')
5236 return obj.selectionEnd;
5237 else if (document.selection && document.selection.createRange) {
5238 var range = document.selection.createRange();
5239 if (range.parentElement()!=obj)
5242 var gm = range.duplicate();
5243 if (obj.tagName == 'TEXTAREA')
5244 gm.moveToElementText(obj);
5246 gm.expand('textedit');
5248 gm.setEndPoint('EndToStart', range);
5249 var p = gm.text.length;
5251 return p<=obj.value.length ? p : -1;
5254 return obj.value.length;
5257 // moves cursor to specified position
5258 this.set_caret_pos = function(obj, pos)
5260 if (obj.setSelectionRange)
5261 obj.setSelectionRange(pos, pos);
5262 else if (obj.createTextRange) {
5263 var range = obj.createTextRange();
5264 range.collapse(true);
5265 range.moveEnd('character', pos);
5266 range.moveStart('character', pos);
5271 // disable/enable all fields of a form
5272 this.lock_form = function(form, lock)
5274 if (!form || !form.elements)
5280 this.disabled_form_elements = [];
5282 for (n=0, len=form.elements.length; n<len; n++) {
5283 elm = form.elements[n];
5285 if (elm.type == 'hidden')
5288 // remember which elem was disabled before lock
5289 if (lock && elm.disabled)
5290 this.disabled_form_elements.push(elm);
5291 else if (lock || $.inArray(elm, this.disabled_form_elements)<0)
5292 elm.disabled = lock;
5296 } // end object rcube_webmail
5299 // some static methods
5300 rcube_webmail.long_subject_title = function(elem, indent)
5303 var $elem = $(elem);
5304 if ($elem.width() + indent * 15 > $elem.parent().width())
5305 elem.title = $elem.html();
5309 // copy event engine prototype
5310 rcube_webmail.prototype.addEventListener = rcube_event_engine.prototype.addEventListener;
5311 rcube_webmail.prototype.removeEventListener = rcube_event_engine.prototype.removeEventListener;
5312 rcube_webmail.prototype.triggerEvent = rcube_event_engine.prototype.triggerEvent;