svncommit
2008-08-29 cca626ef7e4859ee84a02a2f09b3d4e8db9584c5
commit | author | age
e0ed97 1 /*
4e17e6 2  +-----------------------------------------------------------------------+
T 3  | RoundCube Webmail Client Script                                       |
4  |                                                                       |
5  | This file is part of the RoundCube Webmail client                     |
b85bf8 6  | Copyright (C) 2005-2008, RoundCube Dev, - Switzerland                 |
30233b 7  | Licensed under the GNU GPL                                            |
4e17e6 8  |                                                                       |
T 9  +-----------------------------------------------------------------------+
8c2e58 10  | Authors: Thomas Bruederli <roundcube@gmail.com>                       |
T 11  |          Charles McNulty <charles@charlesmcnulty.com>                 |
4e17e6 12  +-----------------------------------------------------------------------+
6b47de 13  | Requires: common.js, list.js                                          |
T 14  +-----------------------------------------------------------------------+
15
15a9d1 16   $Id$
4e17e6 17 */
24053e 18
4e17e6 19
T 20 var rcube_webmail_client;
21
22 function rcube_webmail()
23   {
24   this.env = new Object();
10a699 25   this.labels = new Object();
4e17e6 26   this.buttons = new Object();
T 27   this.gui_objects = new Object();
28   this.commands = new Object();
a7d5c6 29   this.onloads = new Array();
4e17e6 30
cfdf04 31   // create protected reference to myself
4e17e6 32   rcube_webmail_client = this;
T 33   this.ref = 'rcube_webmail_client';
cfdf04 34   var ref = this;
4e17e6 35  
T 36   // webmail client settings
b19097 37   this.dblclick_time = 500;
4b9efb 38   this.message_time = 3000;
9a5261 39   
f11541 40   this.identifier_expr = new RegExp('[^0-9a-z\-_]', 'gi');
4e17e6 41   
T 42   // mimetypes supported by the browser (default settings)
43   this.mimetypes = new Array('text/plain', 'text/html', 'text/xml',
44                              'image/jpeg', 'image/gif', 'image/png',
45                              'application/x-javascript', 'application/pdf',
46                              'application/x-shockwave-flash');
47
9a5261 48   // default environment vars
7139e3 49   this.env.keep_alive = 60;        // seconds
9a5261 50   this.env.request_timeout = 180;  // seconds
e170b4 51   this.env.draft_autosave = 0;     // seconds
f11541 52   this.env.comm_path = './';
T 53   this.env.bin_path = './bin/';
54   this.env.blankpage = 'program/blank.gif';
9a5261 55
4e17e6 56
f11541 57   // set environment variable(s)
T 58   this.set_env = function(p, value)
4e17e6 59     {
f11541 60     if (p != null && typeof(p) == 'object' && !value)
T 61       for (var n in p)
62         this.env[n] = p[n];
63     else
64       this.env[p] = value;
4e17e6 65     };
10a699 66
T 67
68   // add a localized label to the client environment
69   this.add_label = function(key, value)
70     {
71     this.labels[key] = value;
72     };
73
4e17e6 74
T 75   // add a button to the button list
76   this.register_button = function(command, id, type, act, sel, over)
77     {
78     if (!this.buttons[command])
79       this.buttons[command] = new Array();
80       
81     var button_prop = {id:id, type:type};
82     if (act) button_prop.act = act;
83     if (sel) button_prop.sel = sel;
84     if (over) button_prop.over = over;
85
86     this.buttons[command][this.buttons[command].length] = button_prop;    
87     };
88
89   // register a specific gui object
90   this.gui_object = function(name, id)
91     {
92     this.gui_objects[name] = id;
93     };
a7d5c6 94   
T 95   // execute the given script on load
96   this.add_onload = function(f)
97     {
98       this.onloads[this.onloads.length] = f;
99     };
4e17e6 100
T 101   // initialize webmail client
102   this.init = function()
103     {
6b47de 104     var p = this;
4e17e6 105     this.task = this.env.task;
T 106     
107     // check browser
a95e0e 108     if (!bw.dom || !bw.xmlhttp_test())
4e17e6 109       {
6b47de 110       this.goto_url('error', '_code=0x199');
4e17e6 111       return;
T 112       }
113     
114     // find all registered gui objects
115     for (var n in this.gui_objects)
116       this.gui_objects[n] = rcube_find_object(this.gui_objects[n]);
a7d5c6 117
4e17e6 118     // tell parent window that this frame is loaded
T 119     if (this.env.framed && parent.rcmail && parent.rcmail.set_busy)
120       parent.rcmail.set_busy(false);
121
122     // enable general commands
123     this.enable_command('logout', 'mail', 'addressbook', 'settings', true);
124     
125     switch (this.task)
126       {
127       case 'mail':
6b47de 128         if (this.gui_objects.messagelist)
4e17e6 129           {
6b47de 130           this.message_list = new rcube_list_widget(this.gui_objects.messagelist, {multiselect:true, draggable:true, keyboard:true, dblclick_time:this.dblclick_time});
T 131           this.message_list.row_init = function(o){ p.init_message_row(o); };
132           this.message_list.addEventListener('dblclick', function(o){ p.msglist_dbl_click(o); });
133           this.message_list.addEventListener('keypress', function(o){ p.msglist_keypress(o); });
134           this.message_list.addEventListener('select', function(o){ p.msglist_select(o); });
21168d 135           this.message_list.addEventListener('dragstart', function(o){ p.drag_active = true; if (p.preview_timer) clearTimeout(p.preview_timer); });
6b47de 136           this.message_list.addEventListener('dragend', function(o){ p.drag_active = false; });
T 137
138           this.message_list.init();
e189a6 139           this.enable_command('toggle_status', 'toggle_flag', true);
6b47de 140           
T 141           if (this.gui_objects.mailcontframe)
142             {
143             this.gui_objects.mailcontframe.onmousedown = function(e){ return p.click_on_list(e); };
144             document.onmouseup = function(e){ return p.doc_mouse_up(e); };
145             }
146           else
147             this.message_list.focus();
4e17e6 148           }
d24d20 149           
T 150         if (this.env.coltypes)
151           this.set_message_coltypes(this.env.coltypes);
4e17e6 152
T 153         // enable mail commands
f5aa16 154         this.enable_command('list', 'checkmail', 'compose', 'add-contact', 'search', 'reset-search', 'collapse-folder', true);
1f020b 155
S 156         if (this.env.search_text != null && document.getElementById('quicksearchbox') != null)
157           document.getElementById('quicksearchbox').value = this.env.search_text;
4e17e6 158         
b19097 159         if (this.env.action=='show' || this.env.action=='preview')
4e17e6 160           {
b85bf8 161           this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'delete', 'mark', 'viewsource', 'print', 'load-attachment', true);
4e17e6 162           if (this.env.next_uid)
d17008 163             {
4e17e6 164             this.enable_command('nextmessage', true);
d17008 165             this.enable_command('lastmessage', true);
S 166             }
4e17e6 167           if (this.env.prev_uid)
d17008 168             {
4e17e6 169             this.enable_command('previousmessage', true);
d17008 170             this.enable_command('firstmessage', true);
S 171             }
4e17e6 172           }
eb6842 173
T 174         if (this.env.trash_mailbox && this.env.mailbox != this.env.trash_mailbox)
175           this.set_alttext('delete', 'movemessagetotrash');
b19097 176         
T 177         // make preview/message frame visible
178         if (this.env.action == 'preview' && this.env.framed && parent.rcmail)
179           {
180           this.enable_command('compose', 'add-contact', false);
f11541 181           parent.rcmail.show_contentframe(true);
b19097 182           }
4e17e6 183
b19097 184         if ((this.env.action=='show' || this.env.action=='preview') && this.env.blockedobjects)
4e17e6 185           {
T 186           if (this.gui_objects.remoteobjectsmsg)
187             this.gui_objects.remoteobjectsmsg.style.display = 'block';
62e43d 188           this.enable_command('load-images', 'always-load', true);
a0109c 189           }
4e17e6 190
T 191         if (this.env.action=='compose')
ed5d29 192           {
a894ba 193           this.enable_command('add-attachment', 'send-attachment', 'remove-attachment', 'send', true);
ed5d29 194           if (this.env.spellcheck)
e170b4 195             {
86958f 196             this.env.spellcheck.spelling_state_observer = function(s){ ref.set_spellcheck_state(s); };
e170b4 197             this.set_spellcheck_state('ready');
4ca10b 198             if (rcube_find_object('_is_html').value == '1')
T 199               this.display_spellcheck_controls(false);
e170b4 200             }
41fa0b 201           if (this.env.drafts_mailbox)
T 202             this.enable_command('savedraft', true);
ed5d29 203           }
a0109c 204
4e17e6 205         if (this.env.messagecount)
164c7d 206           this.enable_command('select-all', 'select-none', 'expunge', true);
4e17e6 207
ddd776 208         if (this.env.messagecount 
4ca10b 209             && (this.env.mailbox == this.env.trash_mailbox || this.env.mailbox == this.env.junk_mailbox 
T 210               || this.env.mailbox.match('^' + RegExp.escape(this.env.trash_mailbox) + RegExp.escape(this.env.delimiter)) 
211               || this.env.mailbox.match('^' + RegExp.escape(this.env.junk_mailbox) + RegExp.escape(this.env.delimiter))))
5e3512 212           this.enable_command('purge', true);
T 213
4e17e6 214         this.set_page_buttons();
T 215
181970 216         // focus main window
S 217         if (this.env.framed && window.parent)
218           window.parent.focus();
219         else
220           window.focus();
4e17e6 221
T 222         // init message compose form
223         if (this.env.action=='compose')
224           this.init_messageform();
225
226         // show printing dialog
227         if (this.env.action=='print')
228           window.print();
a0109c 229
15a9d1 230         // get unread count for each mailbox
T 231         if (this.gui_objects.mailboxlist)
f11541 232         {
T 233           this.gui_objects.folderlist = this.gui_objects.mailboxlist;
15a9d1 234           this.http_request('getunread', '');
f11541 235         }
fba1f5 236         
T 237         // ask user to send MDN
238         if (this.env.mdn_request && this.env.uid)
239         {
240           var mdnurl = '_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox);
241           if (confirm(this.get_label('mdnrequest')))
242             this.http_post('sendmdn', mdnurl);
243           else
244             this.http_post('mark', mdnurl+'&_flag=mdnsent');
245         }
4e17e6 246
T 247         break;
248
249
250       case 'addressbook':
6b47de 251         if (this.gui_objects.contactslist)
T 252           {
f11541 253           this.contact_list = new rcube_list_widget(this.gui_objects.contactslist, {multiselect:true, draggable:true, keyboard:true});
6b47de 254           this.contact_list.addEventListener('keypress', function(o){ p.contactlist_keypress(o); });
T 255           this.contact_list.addEventListener('select', function(o){ p.contactlist_select(o); });
f11541 256           this.contact_list.addEventListener('dragstart', function(o){ p.drag_active = true; });
T 257           this.contact_list.addEventListener('dragend', function(o){ p.drag_active = false; });
6b47de 258           this.contact_list.init();
d1d2c4 259
6b47de 260           if (this.env.cid)
T 261             this.contact_list.highlight_row(this.env.cid);
262
263           if (this.gui_objects.contactslist.parentNode)
264             {
265             this.gui_objects.contactslist.parentNode.onmousedown = function(e){ return p.click_on_list(e); };
266             document.onmouseup = function(e){ return p.doc_mouse_up(e); };
267             }
268           else
269             this.contact_list.focus();
270           }
d1d2c4 271
4e17e6 272         this.set_page_buttons();
f11541 273         
56fab1 274         if (this.env.address_sources && !this.env.address_sources[this.env.source].readonly)
f11541 275           this.enable_command('add', true);
T 276         
4e17e6 277         if (this.env.cid)
T 278           this.enable_command('show', 'edit', true);
279
56fab1 280         if ((this.env.action=='add' || this.env.action=='edit') && this.gui_objects.editform)
4e17e6 281           this.enable_command('save', true);
f11541 282         else
T 283           this.enable_command('search', 'reset-search', 'moveto', true);
6b47de 284
f11541 285         this.enable_command('list', true);
4e17e6 286         break;
T 287
288
289       case 'settings':
290         this.enable_command('preferences', 'identities', 'save', 'folders', true);
291         
292         if (this.env.action=='identities' || this.env.action=='edit-identity' || this.env.action=='add-identity')
293           this.enable_command('edit', 'add', 'delete', true);
294
295         if (this.env.action=='edit-identity' || this.env.action=='add-identity')
296           this.enable_command('save', true);
297           
298         if (this.env.action=='folders')
c8c1e0 299           this.enable_command('subscribe', 'unsubscribe', 'create-folder', 'rename-folder', 'delete-folder', true);
6b47de 300
T 301         if (this.gui_objects.identitieslist)
302           {
303           this.identity_list = new rcube_list_widget(this.gui_objects.identitieslist, {multiselect:false, draggable:false, keyboard:false});
304           this.identity_list.addEventListener('select', function(o){ p.identity_select(o); });
305           this.identity_list.init();
306           this.identity_list.focus();
307
308           if (this.env.iid)
309             this.identity_list.highlight_row(this.env.iid);
310           }
4e17e6 311
b0dbf3 312         if (this.gui_objects.subscriptionlist)
S 313           this.init_subscription_list();
314
4e17e6 315         break;
T 316
317       case 'login':
0f675b 318         var input_user = rcube_find_object('rcmloginuser');
T 319         var input_pass = rcube_find_object('rcmloginpwd');
b566ff 320         if (input_user)
65444b 321           input_user.onkeyup = function(e){ return rcmail.login_user_keyup(e); };
4e17e6 322         if (input_user && input_user.value=='')
T 323           input_user.focus();
324         else if (input_pass)
325           input_pass.focus();
326           
327         this.enable_command('login', true);
328         break;
329       
330       default:
331         break;
332       }
333
334
335     // enable basic commands
336     this.enable_command('logout', true);
337
338     // flag object as complete
339     this.loaded = true;
9a5261 340
4e17e6 341     // show message
T 342     if (this.pending_message)
343       this.display_message(this.pending_message[0], this.pending_message[1]);
9a5261 344
T 345     // start keep-alive interval
346     this.start_keepalive();
a7d5c6 347     
T 348     
349     // execute all foreign onload scripts
350     for (var i=0; i<this.onloads.length; i++)
351       {
352       if (typeof(this.onloads[i]) == 'string')
353         eval(this.onloads[i]);
354       else if (typeof(this.onloads[i]) == 'function')
355         this.onloads[i]();
356       }
4e17e6 357     };
9a5261 358
T 359
360   // start interval for keep-alive/recent_check signal
361   this.start_keepalive = function()
362     {
3cd24d 363     if (this.env.keep_alive && !this.env.framed && this.task=='mail' && this.gui_objects.mailboxlist)
cfdf04 364       this._int = setInterval(function(){ ref.check_for_recent(); }, this.env.keep_alive * 1000);
1a98a6 365     else if (this.env.keep_alive && !this.env.framed && this.task!='login')
cfdf04 366       this._int = setInterval(function(){ ref.send_keep_alive(); }, this.env.keep_alive * 1000);    
9a5261 367     }
T 368
4e17e6 369
T 370   this.init_message_row = function(row)
6b47de 371   {
T 372     var uid = row.uid;
373     if (uid && this.env.messages[uid])
4e17e6 374       {
ae895a 375       row.deleted = this.env.messages[uid].deleted ? true : false;
T 376       row.unread = this.env.messages[uid].unread ? true : false;
377       row.replied = this.env.messages[uid].replied ? true : false;
e189a6 378       row.flagged = this.env.messages[uid].flagged ? true : false;
4e17e6 379       }
6b47de 380
T 381     // set eventhandler to message icon
382     if ((row.icon = row.obj.cells[0].childNodes[0]) && row.icon.nodeName=='IMG')
383       {
384       var p = this;
385       row.icon.id = 'msgicn_'+row.uid;
386       row.icon._row = row.obj;
387       row.icon.onmousedown = function(e) { p.command('toggle_status', this); };
e189a6 388       }
A 389
390     // global variable 'flagged_col' may be not defined yet
391     if (!this.env.flagged_col && this.env.coltypes)
392       {
393       var found;
394       if((found = find_in_array('flag', this.env.coltypes)) >= 0)
395           this.set_env('flagged_col', found+1);
396       }
397
398     // set eventhandler to flag icon, if icon found
399     if (this.env.flagged_col && (row.flagged_icon = row.obj.cells[this.env.flagged_col].childNodes[0]) 
400     && row.flagged_icon.nodeName=='IMG')
401       {
402       var p = this;
403       row.flagged_icon.id = 'flaggedicn_'+row.uid;
404       row.flagged_icon._row = row.obj;
405       row.flagged_icon.onmousedown = function(e) { p.command('toggle_flag', this); };
6b47de 406       }
T 407   };
4e17e6 408
T 409
410   // init message compose form: set focus and eventhandlers
411   this.init_messageform = function()
412     {
413     if (!this.gui_objects.messageform)
414       return false;
415     
416     //this.messageform = this.gui_objects.messageform;
1cded8 417     var input_from = rcube_find_object('_from');
4e17e6 418     var input_to = rcube_find_object('_to');
T 419     var input_cc = rcube_find_object('_cc');
420     var input_bcc = rcube_find_object('_bcc');
421     var input_replyto = rcube_find_object('_replyto');
422     var input_subject = rcube_find_object('_subject');
423     var input_message = rcube_find_object('_message');
a0109c 424
4e17e6 425     // init live search events
T 426     if (input_to)
427       this.init_address_input_events(input_to);
428     if (input_cc)
429       this.init_address_input_events(input_cc);
430     if (input_bcc)
431       this.init_address_input_events(input_bcc);
dbbd1f 432
1cded8 433     // add signature according to selected identity
T 434     if (input_from && input_from.type=='select-one')
435       this.change_identity(input_from);
4e17e6 436
T 437     if (input_to && input_to.value=='')
438       input_to.focus();
439     else if (input_subject && input_subject.value=='')
440       input_subject.focus();
441     else if (input_message)
6b47de 442       this.set_caret2start(input_message);
a0109c 443
977a29 444     // get summary of all field values
f11541 445     this.compose_field_hash(true);
f0f98f 446  
S 447     // start the auto-save timer
448     this.auto_save_start();
4e17e6 449     };
T 450
451   this.init_address_input_events = function(obj)
452     {
86958f 453     var handler = function(e){ return ref.ksearch_keypress(e,this); };
T 454     var handler2 = function(e){ return ref.ksearch_blur(e,this); };
455     
456     if (obj.addEventListener)
457     {
458       obj.addEventListener(bw.safari ? 'keydown' : 'keypress', handler, false);
4e17e6 459       obj.addEventListener('blur', handler2, false);
86958f 460     }
T 461     else
462     {
4e17e6 463       obj.onkeydown = handler;
86958f 464       obj.onblur = handler2;
T 465     }
6b47de 466
4e17e6 467     obj.setAttribute('autocomplete', 'off');       
T 468     };
469
470
471
472   /*********************************************************/
473   /*********       client command interface        *********/
474   /*********************************************************/
475
476
477   // execute a specific command on the web client
478   this.command = function(command, props, obj)
479     {
480     if (obj && obj.blur)
481       obj.blur();
482
483     if (this.busy)
484       return false;
485
486     // command not supported or allowed
487     if (!this.commands[command])
488       {
489       // pass command to parent window
490       if (this.env.framed && parent.rcmail && parent.rcmail.command)
491         parent.rcmail.command(command, props);
492
493       return false;
494       }
15a9d1 495       
T 496       
497    // check input before leaving compose step
498    if (this.task=='mail' && this.env.action=='compose' && (command=='list' || command=='mail' || command=='addressbook' || command=='settings'))
499      {
500      if (this.cmp_hash != this.compose_field_hash() && !confirm(this.get_label('notsentwarning')))
501         return false;
502      }
503
4e17e6 504
T 505     // process command
506     switch (command)
507       {
508       case 'login':
509         if (this.gui_objects.loginform)
510           this.gui_objects.loginform.submit();
511         break;
512
513       case 'logout':
756037 514         this.goto_url('logout', '', true);
4e17e6 515         break;      
T 516
517       // commands to switch task
518       case 'mail':
519       case 'addressbook':
520       case 'settings':
521         this.switch_task(command);
522         break;
523
524
525       // misc list commands
526       case 'list':
527         if (this.task=='mail')
4647e1 528           {
1f020b 529           if (this.env.search_request<0 || (props != '' && (this.env.search_request && props != this.env.mailbox)))
4647e1 530             this.reset_qsearch();
c8c1e0 531
4e17e6 532           this.list_mailbox(props);
eb6842 533
T 534           if (this.env.trash_mailbox)
535             this.set_alttext('delete', this.env.mailbox != this.env.trash_mailbox ? 'movemessagetotrash' : 'deletemessage');
4647e1 536           }
4e17e6 537         else if (this.task=='addressbook')
f11541 538           {
T 539           if (this.env.search_request<0 || (this.env.search_request && props != this.env.source))
540             this.reset_qsearch();
541
542           this.list_contacts(props);
543           this.enable_command('add', (this.env.address_sources && !this.env.address_sources[props].readonly));
544           }
f3b659 545         break;
c8c1e0 546
f3b659 547
T 548       case 'sort':
549         // get the type of sorting
b076a4 550         var a_sort = props.split('_');
T 551         var sort_col = a_sort[0];
1cded8 552         var sort_order = a_sort[1] ? a_sort[1].toUpperCase() : null;
b076a4 553         var header;
1cded8 554         
T 555         // no sort order specified: toggle
556         if (sort_order==null)
557           {
558           if (this.env.sort_col==sort_col)
559             sort_order = this.env.sort_order=='ASC' ? 'DESC' : 'ASC';
560           else
561             sort_order = this.env.sort_order;
562           }
24053e 563
b076a4 564         if (this.env.sort_col==sort_col && this.env.sort_order==sort_order)
T 565           break;
566
567         // set table header class
568         if (header = document.getElementById('rcmHead'+this.env.sort_col))
569           this.set_classname(header, 'sorted'+(this.env.sort_order.toUpperCase()), false);
570         if (header = document.getElementById('rcmHead'+sort_col))
571           this.set_classname(header, 'sorted'+sort_order, true);
572
573         // save new sort properties
574         this.env.sort_col = sort_col;
575         this.env.sort_order = sort_order;
576
577         // reload message list
1cded8 578         this.list_mailbox('', '', sort_col+'_'+sort_order);
4e17e6 579         break;
T 580
581       case 'nextpage':
582         this.list_page('next');
583         break;
584
d17008 585       case 'lastpage':
S 586         this.list_page('last');
587         break;
588
4e17e6 589       case 'previouspage':
T 590         this.list_page('prev');
d17008 591         break;
S 592
593       case 'firstpage':
594         this.list_page('first');
15a9d1 595         break;
T 596
597       case 'expunge':
598         if (this.env.messagecount)
599           this.expunge_mailbox(this.env.mailbox);
600         break;
601
5e3512 602       case 'purge':
T 603       case 'empty-mailbox':
604         if (this.env.messagecount)
605           this.purge_mailbox(this.env.mailbox);
4e17e6 606         break;
T 607
608
609       // common commands used in multiple tasks
610       case 'show':
611         if (this.task=='mail')
612           {
613           var uid = this.get_single_uid();
614           if (uid && (!this.env.uid || uid != this.env.uid))
41fa0b 615             {
6b47de 616             if (this.env.mailbox == this.env.drafts_mailbox)
T 617               this.goto_url('compose', '_draft_uid='+uid+'&_mbox='+urlencode(this.env.mailbox), true);
1966c5 618             else
S 619               this.show_message(uid);
41fa0b 620             }
4e17e6 621           }
T 622         else if (this.task=='addressbook')
623           {
624           var cid = props ? props : this.get_single_cid();
625           if (cid && !(this.env.action=='show' && cid==this.env.cid))
626             this.load_contact(cid, 'show');
627           }
628         break;
629
630       case 'add':
631         if (this.task=='addressbook')
6b47de 632           this.load_contact(0, 'add');
4e17e6 633         else if (this.task=='settings')
T 634           {
6b47de 635           this.identity_list.clear_selection();
4e17e6 636           this.load_identity(0, 'add-identity');
T 637           }
638         break;
639
640       case 'edit':
641         var cid;
642         if (this.task=='addressbook' && (cid = this.get_single_cid()))
643           this.load_contact(cid, 'edit');
644         else if (this.task=='settings' && props)
645           this.load_identity(props, 'edit-identity');
646         break;
647
648       case 'save-identity':
649       case 'save':
650         if (this.gui_objects.editform)
10a699 651           {
T 652           var input_pagesize = rcube_find_object('_pagesize');
653           var input_name  = rcube_find_object('_name');
654           var input_email = rcube_find_object('_email');
655
656           // user prefs
a03caa 657           if (input_pagesize && isNaN(parseInt(input_pagesize.value)))
10a699 658             {
T 659             alert(this.get_label('nopagesizewarning'));
660             input_pagesize.focus();
661             break;
662             }
663           // contacts/identities
664           else
665             {
666             if (input_name && input_name.value == '')
667               {
668               alert(this.get_label('nonamewarning'));
669               input_name.focus();
670               break;
671               }
672             else if (input_email && !rcube_check_email(input_email.value))
673               {
674               alert(this.get_label('noemailwarning'));
675               input_email.focus();
676               break;
677               }
678             }
679
4e17e6 680           this.gui_objects.editform.submit();
10a699 681           }
4e17e6 682         break;
T 683
684       case 'delete':
685         // mail task
857a38 686         if (this.task=='mail')
4e17e6 687           this.delete_messages();
T 688         // addressbook task
689         else if (this.task=='addressbook')
690           this.delete_contacts();
691         // user settings task
692         else if (this.task=='settings')
693           this.delete_identity();
694         break;
695
696
697       // mail task commands
698       case 'move':
699       case 'moveto':
f11541 700         if (this.task == 'mail')
T 701           this.move_messages(props);
702         else if (this.task == 'addressbook' && this.drag_active)
703           this.copy_contact(null, props);
4e17e6 704         break;
b85bf8 705
T 706       case 'mark':
707         if (props)
708           this.mark_message(props);
709         break;
710       
857a38 711       case 'toggle_status':
4e17e6 712         if (props && !props._row)
T 713           break;
714         
715         var uid;
716         var flag = 'read';
717         
718         if (props._row.uid)
719           {
720           uid = props._row.uid;
bf36a9 721           
4e17e6 722           // toggle read/unread
6b47de 723           if (this.message_list.rows[uid].deleted) {
T 724             flag = 'undelete';
725           } else if (!this.message_list.rows[uid].unread)
4e17e6 726             flag = 'unread';
T 727           }
728           
729         this.mark_message(flag, uid);
730         break;
731         
e189a6 732       case 'toggle_flag':
A 733         if (props && !props._row)
734           break;
735
736         var uid;
737         var flag = 'flagged';
738
739         if (props._row.uid)
740           {
741           uid = props._row.uid;
742           this.message_list.dont_select = true;
743           // toggle flagged/unflagged
744           if (this.message_list.rows[uid].flagged)
745             flag = 'unflagged';
746           }
747         this.mark_message(flag, uid);
748         break;
749
62e43d 750       case 'always-load':
T 751         if (this.env.uid && this.env.sender) {
752           this.add_contact(urlencode(this.env.sender));
753           window.setTimeout(function(){ ref.command('load-images'); }, 300);
754           break;
755         }
756         
4e17e6 757       case 'load-images':
T 758         if (this.env.uid)
b19097 759           this.show_message(this.env.uid, true, this.env.action=='preview');
4e17e6 760         break;
T 761
762       case 'load-attachment':
c5418b 763         var qstring = '_mbox='+urlencode(this.env.mailbox)+'&_uid='+this.env.uid+'&_part='+props.part;
4e17e6 764         
T 765         // open attachment in frame if it's of a supported mimetype
766         if (this.env.uid && props.mimetype && find_in_array(props.mimetype, this.mimetypes)>=0)
767           {
cfdf04 768           if (props.mimetype == 'text/html')
853b2e 769             qstring += '&_safe=1';
b19097 770           this.attachment_win = window.open(this.env.comm_path+'&_action=get&'+qstring+'&_frame=1', 'rcubemailattachment');
4e17e6 771           if (this.attachment_win)
T 772             {
dbbd1f 773             window.setTimeout(function(){ ref.attachment_win.focus(); }, 10);
4e17e6 774             break;
T 775             }
776           }
777
4b9efb 778         this.goto_url('get', qstring+'&_download=1', false);
4e17e6 779         break;
T 780         
781       case 'select-all':
6b47de 782         this.message_list.select_all(props);
4e17e6 783         break;
T 784
785       case 'select-none':
6b47de 786         this.message_list.clear_selection();
4e17e6 787         break;
T 788
789       case 'nextmessage':
790         if (this.env.next_uid)
b19097 791           this.show_message(this.env.next_uid, false, this.env.action=='preview');
4e17e6 792         break;
T 793
a7d5c6 794       case 'lastmessage':
d17008 795         if (this.env.last_uid)
S 796           this.show_message(this.env.last_uid);
797         break;
798
4e17e6 799       case 'previousmessage':
T 800         if (this.env.prev_uid)
b19097 801           this.show_message(this.env.prev_uid, false, this.env.action=='preview');
d17008 802         break;
S 803
804       case 'firstmessage':
805         if (this.env.first_uid)
806           this.show_message(this.env.first_uid);
4e17e6 807         break;
d1d2c4 808       
c8c1e0 809       case 'checkmail':
S 810         this.check_for_recent();
811         break;
d1d2c4 812       
4e17e6 813       case 'compose':
T 814         var url = this.env.comm_path+'&_action=compose';
1966c5 815        
S 816         if (this.task=='mail' && this.env.mailbox==this.env.drafts_mailbox)
817           {
aade7b 818           var uid;
T 819           if (uid = this.get_single_uid())
4d4264 820             url += '&_draft_uid='+uid+'&_mbox='+urlencode(this.env.mailbox);
f11541 821           }
4e17e6 822         // modify url if we're in addressbook
1966c5 823         else if (this.task=='addressbook')
4e17e6 824           {
f11541 825           // switch to mail compose step directly
T 826           if (props && props.indexOf('@') > 0)
827           {
828             url = this.get_task_url('mail', url);
829             this.redirect(url + '&_to='+urlencode(props));
830             break;
831           }
4e17e6 832           
T 833           // use contact_id passed as command parameter
f11541 834           var a_cids = new Array();
4e17e6 835           if (props)
T 836             a_cids[a_cids.length] = props;
837           // get selected contacts
f11541 838           else if (this.contact_list)
4e17e6 839             {
6b47de 840             var selection = this.contact_list.get_selection();
T 841             for (var n=0; n<selection.length; n++)
842               a_cids[a_cids.length] = selection[n];
4e17e6 843             }
f11541 844             
4e17e6 845           if (a_cids.length)
f11541 846             this.http_request('mailto', '_cid='+urlencode(a_cids.join(','))+'&_source='+urlencode(this.env.source), true);
T 847
848           break;
4e17e6 849           }
T 850         else if (props)
6b47de 851            url += '&_to='+urlencode(props);
bc8dc6 852
d1d2c4 853         // don't know if this is necessary...
S 854         url = url.replace(/&_framed=1/, "");
855
f11541 856         this.redirect(url);
ed5d29 857         break;
T 858         
859       case 'spellcheck':
4ca10b 860         if (window.tinyMCE && tinyMCE.get('compose-body')) {
T 861           tinyMCE.execCommand('mceSpellCheck', true);
862         }
863         else if (this.env.spellcheck && this.env.spellcheck.spellCheck && this.spellcheck_ready) {
ed5d29 864           this.env.spellcheck.spellCheck(this.env.spellcheck.check_link);
e170b4 865           this.set_spellcheck_state('checking');
4ca10b 866         }
ed5d29 867         break;
4e17e6 868
1966c5 869       case 'savedraft':
41fa0b 870         // Reset the auto-save timer
T 871         self.clearTimeout(this.save_timer);
f0f98f 872
1966c5 873         if (!this.gui_objects.messageform)
S 874           break;
f0f98f 875
41fa0b 876         // if saving Drafts is disabled in main.inc.php
e170b4 877         // or if compose form did not change
T 878         if (!this.env.drafts_mailbox || this.cmp_hash == this.compose_field_hash())
41fa0b 879           break;
f0f98f 880
1966c5 881         this.set_busy(true, 'savingmessage');
S 882         var form = this.gui_objects.messageform;
41fa0b 883         form.target = "savetarget";
4d0413 884         form._draft.value = '1';
1966c5 885         form.submit();
S 886         break;
887
4e17e6 888       case 'send':
T 889         if (!this.gui_objects.messageform)
890           break;
41fa0b 891
977a29 892         if (!this.check_compose_input())
10a699 893           break;
4315b0 894
9a5261 895         // Reset the auto-save timer
T 896         self.clearTimeout(this.save_timer);
10a699 897
T 898         // all checks passed, send message
899         this.set_busy(true, 'sendingmessage');
900         var form = this.gui_objects.messageform;
41fa0b 901         form.target = "savetarget";     
T 902         form._draft.value = '';
10a699 903         form.submit();
9a5261 904         
T 905         // clear timeout (sending could take longer)
906         clearTimeout(this.request_timer);
4e17e6 907         break;
T 908
909       case 'add-attachment':
910         this.show_attachment_form(true);
911         
912       case 'send-attachment':
f0f98f 913         // Reset the auto-save timer
41fa0b 914         self.clearTimeout(this.save_timer);
f0f98f 915
4e17e6 916         this.upload_file(props)      
T 917         break;
a894ba 918       
S 919       case 'remove-attachment':
920         this.remove_attachment(props);
921         break;
4e17e6 922
583f1c 923       case 'reply-all':
4e17e6 924       case 'reply':
T 925         var uid;
926         if (uid = this.get_single_uid())
6b47de 927           this.goto_url('compose', '_reply_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)+(command=='reply-all' ? '&_all=1' : ''), true);
4e17e6 928         break;      
T 929
930       case 'forward':
931         var uid;
932         if (uid = this.get_single_uid())
6b47de 933           this.goto_url('compose', '_forward_uid='+uid+'&_mbox='+urlencode(this.env.mailbox), true);
4e17e6 934         break;
T 935         
936       case 'print':
937         var uid;
938         if (uid = this.get_single_uid())
4d3f3b 939         {
cfdf04 940           ref.printwin = window.open(this.env.comm_path+'&_action=print&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)+(this.env.safemode ? '&_safe=1' : ''));
4e17e6 941           if (this.printwin)
4d3f3b 942           {
dbbd1f 943             window.setTimeout(function(){ ref.printwin.focus(); }, 20);
4d3f3b 944             if (this.env.action != 'show')
5d97ac 945               this.mark_message('read', uid);
4e17e6 946           }
4d3f3b 947         }
4e17e6 948         break;
T 949
950       case 'viewsource':
951         var uid;
952         if (uid = this.get_single_uid())
cfdf04 953           {
T 954           ref.sourcewin = window.open(this.env.comm_path+'&_action=viewsource&_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox));
4e17e6 955           if (this.sourcewin)
dbbd1f 956             window.setTimeout(function(){ ref.sourcewin.focus(); }, 20);
4e17e6 957           }
T 958         break;
959
960       case 'add-contact':
961         this.add_contact(props);
962         break;
d1d2c4 963       
f11541 964       // quicksearch
4647e1 965       case 'search':
T 966         if (!props && this.gui_objects.qsearchbox)
967           props = this.gui_objects.qsearchbox.value;
968         if (props)
f11541 969         {
T 970           this.qsearch(props);
971           break;
972         }
4647e1 973
T 974       // reset quicksearch        
975       case 'reset-search':
976         var s = this.env.search_request;
977         this.reset_qsearch();
978         
f11541 979         if (s && this.env.mailbox)
4647e1 980           this.list_mailbox(this.env.mailbox);
f11541 981         else if (s && this.task == 'addressbook')
T 982           this.list_contacts(this.env.source);
4647e1 983         break;
4e17e6 984
f5aa16 985       // collapse/expand folder
S 986       case 'collapse-folder':
987         if (props)
988           this.collapse_folder(props);
989         break;
4e17e6 990
T 991       // user settings commands
992       case 'preferences':
6b47de 993         this.goto_url('');
4e17e6 994         break;
T 995
996       case 'identities':
6b47de 997         this.goto_url('identities');
4e17e6 998         break;
T 999           
1000       case 'delete-identity':
1001         this.delete_identity();
1002         
1003       case 'folders':
6b47de 1004         this.goto_url('folders');
4e17e6 1005         break;
T 1006
1007       case 'subscribe':
1008         this.subscribe_folder(props);
1009         break;
1010
1011       case 'unsubscribe':
1012         this.unsubscribe_folder(props);
1013         break;
1014         
1015       case 'create-folder':
1016         this.create_folder(props);
c8c1e0 1017         break;
S 1018
1019       case 'rename-folder':
1020         this.rename_folder(props);
4e17e6 1021         break;
T 1022
1023       case 'delete-folder':
68b6a9 1024         this.delete_folder(props);
4e17e6 1025         break;
T 1026
1027       }
1028
1029     return obj ? false : true;
1030     };
1031
1032
1033   // set command enabled or disabled
1034   this.enable_command = function()
1035     {
1c5853 1036     var args = arguments;
4e17e6 1037     if(!args.length) return -1;
T 1038
1039     var command;
1040     var enable = args[args.length-1];
1041     
1042     for(var n=0; n<args.length-1; n++)
1043       {
1044       command = args[n];
1045       this.commands[command] = enable;
1046       this.set_button(command, (enable ? 'act' : 'pas'));
1047       }
1c5853 1048       return true;
4e17e6 1049     };
T 1050
1051
a95e0e 1052   // lock/unlock interface
4e17e6 1053   this.set_busy = function(a, message)
T 1054     {
1055     if (a && message)
10a699 1056       {
T 1057       var msg = this.get_label(message);
1058       if (msg==message)        
1059         msg = 'Loading...';
1060
1061       this.display_message(msg, 'loading', true);
1062       }
258f1e 1063     else if (!a)
4e17e6 1064       this.hide_message();
T 1065
1066     this.busy = a;
1067     //document.body.style.cursor = a ? 'wait' : 'default';
1068     
1069     if (this.gui_objects.editform)
1070       this.lock_form(this.gui_objects.editform, a);
a95e0e 1071       
T 1072     // clear pending timer
1073     if (this.request_timer)
1074       clearTimeout(this.request_timer);
1075
1076     // set timer for requests
9a5261 1077     if (a && this.env.request_timeout)
dbbd1f 1078       this.request_timer = window.setTimeout(function(){ ref.request_timed_out(); }, this.env.request_timeout * 1000);
4e17e6 1079     };
T 1080
1081
10a699 1082   // return a localized string
T 1083   this.get_label = function(name)
1084     {
1085     if (this.labels[name])
1086       return this.labels[name];
1087     else
1088       return name;
1089     };
1090
1091
1092   // switch to another application task
4e17e6 1093   this.switch_task = function(task)
T 1094     {
01bb03 1095     if (this.task===task && task!='mail')
4e17e6 1096       return;
T 1097
01bb03 1098     var url = this.get_task_url(task);
T 1099     if (task=='mail')
1100       url += '&_mbox=INBOX';
1101
f11541 1102     this.redirect(url);
4e17e6 1103     };
T 1104
1105
1106   this.get_task_url = function(task, url)
1107     {
1108     if (!url)
1109       url = this.env.comm_path;
1110
1111     return url.replace(/_task=[a-z]+/, '_task='+task);
a95e0e 1112     };
T 1113     
1114   
1115   // called when a request timed out
1116   this.request_timed_out = function()
1117     {
1118     this.set_busy(false);
1119     this.display_message('Request timed out!', 'error');
4e17e6 1120     };
T 1121
1122
1123   /*********************************************************/
1124   /*********        event handling methods         *********/
1125   /*********************************************************/
1126
1127
6b47de 1128   this.doc_mouse_up = function(e)
T 1129     {
1130     if (this.message_list)
1131       this.message_list.blur();
1132     else if (this.contact_list)
1133       this.contact_list.blur();
1134     };
1135
f11541 1136   this.focus_folder = function(id)
T 1137     {
1138     var li;
1139     if (this.drag_active && this.check_droptarget(id) && (li = this.get_folder_li(id)))
1140       this.set_classname(li, 'droptarget', true);
1141     }
6b47de 1142
f11541 1143   this.unfocus_folder = function(id)
T 1144     {
1145     var li;
1146     if (this.drag_active && (li = this.get_folder_li(id)))
1147       this.set_classname(li, 'droptarget', false);
f5aa16 1148     }
S 1149
1150   this.collapse_folder = function(id)
1151     {
1152     var div;
1153     if ((li = this.get_folder_li(id)) &&
1154         (div = li.getElementsByTagName("div")[0]) &&
1155         (div.className.match(/collapsed/) || div.className.match(/expanded/)))
1156       {
1157       var ul = li.getElementsByTagName("ul")[0];
1158       if (div.className.match(/collapsed/))
1159         {
1160         ul.style.display = '';
1161         this.set_classname(div, 'collapsed', false);
1162         this.set_classname(div, 'expanded', true);
1163         var reg = new RegExp('&'+escape(id)+'&');
1164         this.set_env('collapsed_folders', this.env.collapsed_folders.replace(reg, ''));
1165         }
1166       else
1167         {
1168         ul.style.display = 'none';
1169         this.set_classname(div, 'expanded', false);
1170         this.set_classname(div, 'collapsed', true);
1171         this.set_env('collapsed_folders', this.env.collapsed_folders+'&'+escape(id)+'&');
1172         }
1173       this.http_post('save-pref', '_name=collapsed_folders&_value='+escape(this.env.collapsed_folders));
7f9d71 1174       this.set_unread_count_display(id, false);
f5aa16 1175       }
f11541 1176     }
T 1177
1178   // onmouseup handler for folder list item
1179   this.folder_mouse_up = function(id)
4e17e6 1180     {
T 1181     if (this.drag_active)
fe79b1 1182       {
f11541 1183       this.unfocus_folder(id);
T 1184       this.command('moveto', id);
fe79b1 1185       }
4e17e6 1186     };
T 1187
6b47de 1188   this.click_on_list = function(e)
4e17e6 1189     {
6b47de 1190     if (this.message_list)
T 1191       this.message_list.focus();
1192     else if (this.contact_list)
1193         this.contact_list.focus();
4e17e6 1194
6b47de 1195     var mbox_li;
f11541 1196     if (mbox_li = this.get_folder_li())
6b47de 1197       this.set_classname(mbox_li, 'unfocused', true);
4e17e6 1198
6b47de 1199     rcube_event.cancel(e);
4e17e6 1200     };
T 1201
1202
6b47de 1203   this.msglist_select = function(list)
4e17e6 1204     {
b19097 1205     if (this.preview_timer)
T 1206       clearTimeout(this.preview_timer);
1207
6b47de 1208     var selected = list.selection.length==1;
4b9efb 1209
S 1210     // Hide certain command buttons when Drafts folder is selected
6b47de 1211     if (this.env.mailbox == this.env.drafts_mailbox)
4e17e6 1212       {
4b9efb 1213       this.enable_command('reply', 'reply-all', 'forward', false);
301454 1214       this.enable_command('show', selected);
b85bf8 1215       this.enable_command('delete', 'moveto', 'mark', (list.selection.length > 0 ? true : false));
4e17e6 1216       }
6b47de 1217     else
4e17e6 1218       {
301454 1219       this.enable_command('show', 'reply', 'reply-all', 'forward', 'print', selected);
b85bf8 1220       this.enable_command('delete', 'moveto', 'mark', (list.selection.length > 0 ? true : false));
4e17e6 1221       }
068f6a 1222
S 1223     // start timer for message preview (wait for double click)
21168d 1224     if (selected && this.env.contentframe && !list.multi_selecting)
26f5b0 1225       this.preview_timer = window.setTimeout(function(){ ref.msglist_get_preview(); }, 200);
068f6a 1226     else if (this.env.contentframe)
f11541 1227       this.show_contentframe(false);
b19097 1228     };
d1d2c4 1229
S 1230
6b47de 1231   this.msglist_dbl_click = function(list)
T 1232     {
b19097 1233       if (this.preview_timer)
T 1234         clearTimeout(this.preview_timer);
1235
6b47de 1236     var uid = list.get_single_selection();
T 1237     if (uid && this.env.mailbox == this.env.drafts_mailbox)
1238       this.goto_url('compose', '_draft_uid='+uid+'&_mbox='+urlencode(this.env.mailbox), true);
1239     else if (uid)
b19097 1240       this.show_message(uid, false, false);
6b47de 1241     };
4e17e6 1242
6b47de 1243
T 1244   this.msglist_keypress = function(list)
1245     {
1246     if (list.key_pressed == list.ENTER_KEY)
1247       this.command('show');
1248     else if (list.key_pressed == list.DELETE_KEY)
1249       this.command('delete');
110748 1250     else
T 1251       list.shiftkey = false;
4e17e6 1252     };
T 1253
1254
b19097 1255   this.msglist_get_preview = function()
T 1256   {
1257     var uid = this.get_single_uid();
f11541 1258     if (uid && this.env.contentframe && !this.drag_active)
b19097 1259       this.show_message(uid, false, true);
T 1260     else if (this.env.contentframe)
f11541 1261       this.show_contentframe(false);
T 1262   };
1263   
1264   
1265   this.check_droptarget = function(id)
1266   {
1267     if (this.task == 'mail')
1268       return (id != this.env.mailbox);
1269     else if (this.task == 'addressbook')
1270       return (id != this.env.source && this.env.address_sources[id] && !this.env.address_sources[id].readonly);
b0dbf3 1271     else if (this.task == 'settings')
S 1272       return (id != this.env.folder);
b19097 1273   };
T 1274
4e17e6 1275
T 1276   /*********************************************************/
1277   /*********     (message) list functionality      *********/
1278   /*********************************************************/
1279
1280
1281   // when user doble-clicks on a row
b19097 1282   this.show_message = function(id, safe, preview)
4e17e6 1283     {
T 1284     var add_url = '';
b19097 1285     var action = preview ? 'preview': 'show';
4e17e6 1286     var target = window;
b19097 1287     if (preview && this.env.contentframe && window.frames && window.frames[this.env.contentframe])
4e17e6 1288       {
T 1289       target = window.frames[this.env.contentframe];
1290       add_url = '&_framed=1';
1291       }
6b47de 1292
4e17e6 1293     if (safe)
T 1294       add_url = '&_safe=1';
1295
1f020b 1296     // also send search request to get the right messages
S 1297     if (this.env.search_request)
1298       add_url += '&_search='+this.env.search_request;
1299
4e17e6 1300     if (id)
T 1301       {
b19097 1302       var url = '&_action='+action+'&_uid='+id+'&_mbox='+urlencode(this.env.mailbox)+add_url;
T 1303       if (action == 'preview' && String(target.location.href).indexOf(url) >= 0)
f11541 1304         this.show_contentframe(true);
b19097 1305       else
T 1306         {
1307         this.set_busy(true, 'loading');
1308         target.location.href = this.env.comm_path+url;
1309         }
4e17e6 1310       }
T 1311     };
1312
b19097 1313
f11541 1314   this.show_contentframe = function(show)
b19097 1315     {
T 1316     var frm;
1317     if (this.env.contentframe && (frm = rcube_find_object(this.env.contentframe)))
1318       {
75b1a5 1319       if (!show && window.frames[this.env.contentframe])
A 1320         {
1321         if (window.frames[this.env.contentframe].location.href.indexOf(this.env.blankpage)<0)
d22455 1322           window.frames[this.env.contentframe].location.href = this.env.blankpage;
T 1323         }
75b1a5 1324       else if (!bw.safari)
f11541 1325         frm.style.display = show ? 'block' : 'none';
b19097 1326       }
T 1327       
1328     if (!show && this.busy)
1329       this.set_busy(false);
1330     };
4e17e6 1331
T 1332
1333   // list a specific page
1334   this.list_page = function(page)
1335     {
1336     if (page=='next')
1337       page = this.env.current_page+1;
d17008 1338     if (page=='last')
S 1339       page = this.env.pagecount;
4e17e6 1340     if (page=='prev' && this.env.current_page>1)
T 1341       page = this.env.current_page-1;
d17008 1342     if (page=='first' && this.env.current_page>1)
S 1343       page = 1;
4e17e6 1344       
T 1345     if (page > 0 && page <= this.env.pagecount)
1346       {
1347       this.env.current_page = page;
1348       
1349       if (this.task=='mail')
1350         this.list_mailbox(this.env.mailbox, page);
1351       else if (this.task=='addressbook')
f11541 1352         this.list_contacts(this.env.source, page);
4e17e6 1353       }
T 1354     };
1355
1356
1357   // list messages of a specific mailbox
f3b659 1358   this.list_mailbox = function(mbox, page, sort)
4e17e6 1359     {
cbd62d 1360     this.last_selected = 0;
4e17e6 1361     var add_url = '';
T 1362     var target = window;
1363
1364     if (!mbox)
1365       mbox = this.env.mailbox;
1366
f3b659 1367     // add sort to url if set
T 1368     if (sort)
1369       add_url += '&_sort=' + sort;
f11541 1370
T 1371     // also send search request to get the right messages
1372     if (this.env.search_request)
1373       add_url += '&_search='+this.env.search_request;
f3b659 1374       
4e17e6 1375     // set page=1 if changeing to another mailbox
T 1376     if (!page && mbox != this.env.mailbox)
1377       {
1378       page = 1;
1379       this.env.current_page = page;
bef5ca 1380       if (this.message_list)
T 1381         this.message_list.clear_selection();
f11541 1382       this.show_contentframe(false);
4e17e6 1383       }
4647e1 1384     
06895c 1385     if (mbox != this.env.mailbox || (mbox == this.env.mailbox && !page && !sort))
T 1386       add_url += '&_refresh=1';
1387     
f11541 1388     this.select_folder(mbox, this.env.mailbox);
T 1389     this.env.mailbox = mbox;
4e17e6 1390
T 1391     // load message list remotely
1392     if (this.gui_objects.messagelist)
1393       {
9fee0e 1394       this.list_mailbox_remote(mbox, page, add_url);
4e17e6 1395       return;
T 1396       }
1397     
1398     if (this.env.contentframe && window.frames && window.frames[this.env.contentframe])
1399       {
1400       target = window.frames[this.env.contentframe];
9fee0e 1401       add_url += '&_framed=1';
4e17e6 1402       }
T 1403
1404     // load message list to target frame/window
1405     if (mbox)
1406       {
1407       this.set_busy(true, 'loading');
4d4264 1408       target.location.href = this.env.comm_path+'&_mbox='+urlencode(mbox)+(page ? '&_page='+page : '')+add_url;
4e17e6 1409       }
T 1410     };
1411
1412
1413   // send remote request to load message list
9fee0e 1414   this.list_mailbox_remote = function(mbox, page, add_url)
4e17e6 1415     {
15a9d1 1416     // clear message list first
6b47de 1417     this.message_list.clear();
15a9d1 1418
T 1419     // send request to server
4d4264 1420     var url = '_mbox='+urlencode(mbox)+(page ? '&_page='+page : '');
15a9d1 1421     this.set_busy(true, 'loading');
T 1422     this.http_request('list', url+add_url, true);
c8c1e0 1423     };
24053e 1424
15a9d1 1425
T 1426   this.expunge_mailbox = function(mbox)
1427     {
1428     var lock = false;
1429     var add_url = '';
1430     
1431     // lock interface if it's the active mailbox
1432     if (mbox == this.env.mailbox)
1433        {
1434        lock = true;
1435        this.set_busy(true, 'loading');
1436        add_url = '&_reload=1';
1437        }
4e17e6 1438
T 1439     // send request to server
4d4264 1440     var url = '_mbox='+urlencode(mbox);
8d0758 1441     this.http_post('expunge', url+add_url, lock);
4e17e6 1442     };
T 1443
1444
5e3512 1445   this.purge_mailbox = function(mbox)
T 1446     {
1447     var lock = false;
1448     var add_url = '';
1449     
1450     if (!confirm(this.get_label('purgefolderconfirm')))
1451       return false;
1452     
1453     // lock interface if it's the active mailbox
1454     if (mbox == this.env.mailbox)
1455        {
1456        lock = true;
1457        this.set_busy(true, 'loading');
1458        add_url = '&_reload=1';
1459        }
1460
1461     // send request to server
4d4264 1462     var url = '_mbox='+urlencode(mbox);
8d0758 1463     this.http_post('purge', url+add_url, lock);
1c5853 1464     return true;
5e3512 1465     };
f11541 1466
fe79b1 1467   
4e17e6 1468   // move selected messages to the specified mailbox
T 1469   this.move_messages = function(mbox)
1470     {
e4bbb2 1471     // exit if current or no mailbox specified or if selection is empty
faebf4 1472     if (!mbox || mbox == this.env.mailbox || (!this.env.uid && (!this.message_list || !this.message_list.get_selection().length)))
aa9836 1473       return;
e4bbb2 1474
ecf759 1475     var lock = false;
cfdf04 1476     var add_url = '&_target_mbox='+urlencode(mbox)+'&_from='+(this.env.action ? this.env.action : '');
4e17e6 1477
T 1478     // show wait message
1479     if (this.env.action=='show')
ecf759 1480       {
T 1481       lock = true;
4e17e6 1482       this.set_busy(true, 'movingmessage');
ecf759 1483       }
d87fc2 1484     else if (!this.env.flag_for_deletion)
f11541 1485       this.show_contentframe(false);
6b47de 1486
faebf4 1487     // Hide message command buttons until a message is selected
T 1488     this.enable_command('reply', 'reply-all', 'forward', 'delete', 'mark', 'print', false);
1489
d87fc2 1490     this._with_selected_messages('moveto', lock, add_url, (this.env.flag_for_deletion ? false : true));
4e17e6 1491     };
T 1492
857a38 1493   // delete selected messages from the current mailbox
S 1494   this.delete_messages = function()
1495     {
1c7b97 1496     var selection = this.message_list ? this.message_list.get_selection() : new Array();
3d3531 1497
857a38 1498     // exit if no mailbox specified or if selection is empty
1c7b97 1499     if (!this.env.uid && !selection.length)
e4bbb2 1500         return;
6b47de 1501
857a38 1502     // if there is a trash mailbox defined and we're not currently in it:
1c7b97 1503     if (this.env.trash_mailbox && String(this.env.mailbox).toLowerCase() != String(this.env.trash_mailbox).toLowerCase())
cfdf04 1504       {
31c171 1505       // if shift was pressed delete it immediately
086377 1506       if (this.message_list && this.message_list.shiftkey)
31c171 1507         {
S 1508         if (confirm(this.get_label('deletemessagesconfirm')))
1509           this.permanently_remove_messages();
1510         }
1511       else
1512         this.move_messages(this.env.trash_mailbox);
cfdf04 1513       }
857a38 1514     // if there is a trash mailbox defined but we *are* in it:
S 1515     else if (this.env.trash_mailbox && String(this.env.mailbox).toLowerCase() == String(this.env.trash_mailbox).toLowerCase())
1516       this.permanently_remove_messages();
1517     // if there isn't a defined trash mailbox and the config is set to flag for deletion
6b47de 1518     else if (!this.env.trash_mailbox && this.env.flag_for_deletion)
T 1519       {
1c7b97 1520       this.mark_message('delete');
6b47de 1521       if(this.env.action=="show")
dab065 1522         this.command('nextmessage','',this);
6b47de 1523       else if (selection.length == 1)
T 1524         this.message_list.select_next();
dab065 1525       }
857a38 1526     // if there isn't a defined trash mailbox and the config is set NOT to flag for deletion
6b47de 1527     else if (!this.env.trash_mailbox) 
857a38 1528       this.permanently_remove_messages();
S 1529   };
cfdf04 1530
T 1531
1532   // delete the selected messages permanently
1533   this.permanently_remove_messages = function()
1534     {
1535     // exit if no mailbox specified or if selection is empty
1536     if (!this.env.uid && (!this.message_list || !this.message_list.get_selection().length))
1537       return;
1c7b97 1538       
f11541 1539     this.show_contentframe(false);
d87fc2 1540     this._with_selected_messages('delete', false, '&_from='+(this.env.action ? this.env.action : ''), true);
cfdf04 1541     };
T 1542
1543   // Send a specifc request with UIDs of all selected messages
1544   // @private
d87fc2 1545   this._with_selected_messages = function(action, lock, add_url, remove)
d22455 1546   {
cfdf04 1547     var a_uids = new Array();
3d3531 1548
cfdf04 1549     if (this.env.uid)
3d3531 1550       a_uids[0] = this.env.uid;
cfdf04 1551     else
d22455 1552     {
cfdf04 1553       var selection = this.message_list.get_selection();
d87fc2 1554       var rows = this.message_list.rows;
cfdf04 1555       var id;
T 1556       for (var n=0; n<selection.length; n++)
1557         {
1558         id = selection[n];
1559         a_uids[a_uids.length] = id;
3d3531 1560
d22455 1561         if (remove)
d87fc2 1562           this.message_list.remove_row(id, (n == selection.length-1));
A 1563         else
d22455 1564         {
T 1565           rows[id].deleted = true;
d87fc2 1566         
A 1567           if (rows[id].classname.indexOf('deleted')<0)
d22455 1568           {
d87fc2 1569             rows[id].classname += ' deleted';
A 1570             this.set_classname(rows[id].obj, 'deleted', true);
d22455 1571           }
T 1572           if (this.env.read_when_deleted)
1573           {
1574             rows[id].classname = rows[id].classname.replace(/\s*unread/, '');
1575             this.set_classname(rows[id].obj, 'unread', false);
1576           }
d87fc2 1577         
d22455 1578           if (rows[id].icon && this.env.deletedicon)
d87fc2 1579             rows[id].icon.src = this.env.deletedicon;
cfdf04 1580         }
T 1581       }
d22455 1582     }
3d3531 1583     
f11541 1584     // also send search request to get the right messages 
T 1585     if (this.env.search_request) 
cfdf04 1586       add_url += '&_search='+this.env.search_request;
T 1587
1588     // send request to server
8d0758 1589     this.http_post(action, '_uid='+a_uids.join(',')+'&_mbox='+urlencode(this.env.mailbox)+add_url, lock);
d22455 1590   };
4e17e6 1591
T 1592
1593   // set a specific flag to one or more messages
1594   this.mark_message = function(flag, uid)
1595     {
1596     var a_uids = new Array();
5d97ac 1597     var r_uids = new Array();
b19097 1598     var selection = this.message_list ? this.message_list.get_selection() : new Array();
3d3531 1599
4e17e6 1600     if (uid)
T 1601       a_uids[0] = uid;
1602     else if (this.env.uid)
1603       a_uids[0] = this.env.uid;
1c7b97 1604     else if (this.message_list)
4e17e6 1605       {
3d3531 1606       for (var n=0; n<selection.length; n++)
4e17e6 1607         {
e189a6 1608           a_uids[a_uids.length] = selection[n];
4e17e6 1609         }
5d97ac 1610       }
A 1611
3d3531 1612     if (!this.message_list)
A 1613       r_uids = a_uids;
1614     else
1615       for (var id, n=0; n<a_uids.length; n++)
5d97ac 1616       {
A 1617         id = a_uids[n];
1618         if ((flag=='read' && this.message_list.rows[id].unread) 
d22455 1619             || (flag=='unread' && !this.message_list.rows[id].unread)
T 1620             || (flag=='delete' && !this.message_list.rows[id].deleted)
1621             || (flag=='undelete' && this.message_list.rows[id].deleted)
1622             || (flag=='flagged' && !this.message_list.rows[id].flagged)
1623             || (flag=='unflagged' && this.message_list.rows[id].flagged))
1624         {
1625           r_uids[r_uids.length] = id;
1626         }
4e17e6 1627       }
3d3531 1628
1a98a6 1629     // nothing to do
5d97ac 1630     if (!r_uids.length)
1a98a6 1631       return;
3d3531 1632
6b47de 1633     switch (flag)
T 1634       {
857a38 1635         case 'read':
S 1636         case 'unread':
5d97ac 1637           this.toggle_read_status(flag, r_uids);
857a38 1638           break;
S 1639         case 'delete':
1640         case 'undelete':
5d97ac 1641           this.toggle_delete_status(r_uids);
e189a6 1642           break;
A 1643         case 'flagged':
1644         case 'unflagged':
1645           this.toggle_flagged_status(flag, a_uids);
857a38 1646           break;
S 1647       }
1648     };
4e17e6 1649
857a38 1650   // set class to read/unread
6b47de 1651   this.toggle_read_status = function(flag, a_uids)
T 1652   {
4e17e6 1653     // mark all message rows as read/unread
T 1654     var icn_src;
6b47de 1655     var rows = this.message_list.rows;
4e17e6 1656     for (var i=0; i<a_uids.length; i++)
T 1657       {
1658       uid = a_uids[i];
5d97ac 1659       if (rows[uid])
4e17e6 1660         {
6b47de 1661         rows[uid].unread = (flag=='unread' ? true : false);
4e17e6 1662         
6b47de 1663         if (rows[uid].classname.indexOf('unread')<0 && rows[uid].unread)
4e17e6 1664           {
6b47de 1665           rows[uid].classname += ' unread';
T 1666           this.set_classname(rows[uid].obj, 'unread', true);
fd660a 1667
4e17e6 1668           if (this.env.unreadicon)
T 1669             icn_src = this.env.unreadicon;
1670           }
6b47de 1671         else if (!rows[uid].unread)
4e17e6 1672           {
6b47de 1673           rows[uid].classname = rows[uid].classname.replace(/\s*unread/, '');
T 1674           this.set_classname(rows[uid].obj, 'unread', false);
4e17e6 1675
9d6f8e 1676           if (this.env.messageicon)
4e17e6 1677             icn_src = this.env.messageicon;
T 1678           }
1679
9d6f8e 1680         if (rows[uid].icon && icn_src 
d22455 1681             && !(rows[uid].replied && this.env.repliedicon)
9d6f8e 1682             && !(rows[uid].deleted && this.env.deletedicon))
6b47de 1683           rows[uid].icon.src = icn_src;
4e17e6 1684         }
T 1685       }
4bca67 1686
5d97ac 1687     this.http_post('mark', '_uid='+a_uids.join(',')+'&_flag='+flag);
6b47de 1688   };
6d2714 1689
A 1690   // set class to read/unread
1691   this.mark_as_read_from_preview = function(uid)
1692   {
1693     var icn_src;
1694     var rows = parent.rcmail.message_list.rows;
1695     if(rows[uid].unread)
1696       {
1697         rows[uid].unread = false;
1698         rows[uid].classname = rows[uid].classname.replace(/\s*unread/, '');
1699         parent.rcmail.set_classname(rows[uid].obj, 'unread', false);
1700
1701         if (rows[uid].replied && parent.rcmail.env.repliedicon)
d22455 1702           icn_src = parent.rcmail.env.repliedicon;
9d6f8e 1703         else if (rows[uid].deleted && parent.rcmail.env.deletedicon)
d22455 1704           icn_src = parent.rcmail.env.deletedicon;
6d2714 1705         else if (parent.rcmail.env.messageicon)
A 1706           icn_src = parent.rcmail.env.messageicon;
1707       
d22455 1708         if (rows[uid].icon && icn_src)
6d2714 1709           rows[uid].icon.src = icn_src;
A 1710       }
1711   }
1712   
e189a6 1713   
A 1714   // set image to flagged or unflagged
1715   this.toggle_flagged_status = function(flag, a_uids)
1716   {
1717     // mark all message rows as flagged/unflagged
1718     var icn_src;
1719     var rows = this.message_list.rows;
1720     for (var i=0; i<a_uids.length; i++)
1721       {
1722       uid = a_uids[i];
1723       if (rows[uid])
1724         {
1725         rows[uid].flagged = (flag=='flagged' ? true : false);
1726
1727         if (rows[uid].flagged && this.env.flaggedicon)
1728           icn_src = this.env.flaggedicon;
1729         else if (this.env.unflaggedicon)
1730           icn_src = this.env.unflaggedicon;
1731
1732         if (rows[uid].flagged_icon && icn_src)
1733           rows[uid].flagged_icon.src = icn_src;
1734         }
1735       }
1736
1737     this.http_post('mark', '_uid='+a_uids.join(',')+'&_flag='+flag);
1738   };
857a38 1739   
S 1740   // mark all message rows as deleted/undeleted
6b47de 1741   this.toggle_delete_status = function(a_uids)
T 1742   {
3d3531 1743     var rows = this.message_list ? this.message_list.rows : new Array();
A 1744     
1c7b97 1745     if (a_uids.length==1)
T 1746     {
3d3531 1747       if (!rows.length || (rows[a_uids[0]] && rows[a_uids[0]].classname.indexOf('deleted') < 0))
6b47de 1748         this.flag_as_deleted(a_uids);
T 1749       else
1750         this.flag_as_undeleted(a_uids);
1751
1c5853 1752       return true;
S 1753     }
1754     
1755     var all_deleted = true;
1c7b97 1756     for (var i=0; i<a_uids.length; i++)
T 1757     {
857a38 1758       uid = a_uids[i];
6b47de 1759       if (rows[uid]) {
1c7b97 1760         if (rows[uid].classname.indexOf('deleted')<0)
T 1761         {
1c5853 1762           all_deleted = false;
S 1763           break;
857a38 1764         }
S 1765       }
1c5853 1766     }
S 1767     
1768     if (all_deleted)
1769       this.flag_as_undeleted(a_uids);
1770     else
1771       this.flag_as_deleted(a_uids);
1772     
1773     return true;
6b47de 1774   };
4e17e6 1775
6b47de 1776
T 1777   this.flag_as_undeleted = function(a_uids)
1778   {
1c5853 1779     var icn_src;
3d3531 1780     var rows = this.message_list ? this.message_list.rows : new Array();
1c5853 1781       
1c7b97 1782     for (var i=0; i<a_uids.length; i++)
T 1783     {
1c5853 1784       uid = a_uids[i];
6b47de 1785       if (rows[uid]) {
T 1786         rows[uid].deleted = false;
1c5853 1787         
1c7b97 1788         if (rows[uid].classname.indexOf('deleted') > 0)
T 1789         {
6b47de 1790           rows[uid].classname = rows[uid].classname.replace(/\s*deleted/, '');
T 1791           this.set_classname(rows[uid].obj, 'deleted', false);
1c5853 1792         }
6b47de 1793         if (rows[uid].unread && this.env.unreadicon)
1c5853 1794           icn_src = this.env.unreadicon;
6b47de 1795         else if (rows[uid].replied && this.env.repliedicon)
1c5853 1796           icn_src = this.env.repliedicon;
S 1797         else if (this.env.messageicon)
1798           icn_src = this.env.messageicon;
3d3531 1799
6b47de 1800         if (rows[uid].icon && icn_src)
T 1801           rows[uid].icon.src = icn_src;
1c5853 1802       }
S 1803     }
6b47de 1804
8d0758 1805     this.http_post('mark', '_uid='+a_uids.join(',')+'&_flag=undelete');
1c5853 1806     return true;
6b47de 1807   };
T 1808
1c5853 1809   
6b47de 1810   this.flag_as_deleted = function(a_uids)
T 1811   {
3d3531 1812     var add_url = '';
A 1813     var r_uids = new Array();
1814     var rows = this.message_list ? this.message_list.rows : new Array();
1815     
1c7b97 1816     for (var i=0; i<a_uids.length; i++)
3d3531 1817       {
1c5853 1818       uid = a_uids[i];
3d3531 1819       if (rows[uid])
A 1820         {
6b47de 1821         rows[uid].deleted = true;
1c5853 1822         
3d3531 1823         if (rows[uid].classname.indexOf('deleted')<0)
d22455 1824           {
6b47de 1825           rows[uid].classname += ' deleted';
T 1826           this.set_classname(rows[uid].obj, 'deleted', true);
3d3531 1827           }
d22455 1828         if (this.env.read_when_deleted)
T 1829         {
1830           rows[uid].classname = rows[uid].classname.replace(/\s*unread/, '');
1831           this.set_classname(rows[uid].obj, 'unread', false);
1832         }
1833           
1834         if (rows[uid].icon && this.env.deletedicon)
6b47de 1835           rows[uid].icon.src = this.env.deletedicon;
T 1836
d22455 1837         if (rows[uid].unread)
T 1838           r_uids[r_uids.length] = uid;
3d3531 1839         }
A 1840       }
1841
1842     if (r_uids.length)
1843       add_url = '&_ruid='+r_uids.join(',');
1844
1845     this.http_post('mark', '_uid='+a_uids.join(',')+'&_flag=delete'+add_url);
1c5853 1846     return true;  
6b47de 1847   };
fe79b1 1848
3d3531 1849
A 1850   // flag as read without mark request (called from backend)
1851   // argument should be a coma-separated list of uids
1852   this.flag_deleted_as_read = function(uids)
1853   {
1854     var icn_src;
1855     var rows = this.message_list ? this.message_list.rows : new Array();
1856     var str = String(uids);
1857     var a_uids = new Array();
1858
1859     a_uids = str.split(',');
1860
1861     for (var uid, i=0; i<a_uids.length; i++)
1862       {
1863       uid = a_uids[i];
1864       if (rows[uid])
1865         {
1866         rows[uid].unread = false;
d22455 1867         rows[uid].read = true;
3d3531 1868         
A 1869         rows[uid].classname = rows[uid].classname.replace(/\s*unread/, '');
1870         this.set_classname(rows[uid].obj, 'unread', false);
1871
1872         if (rows[uid].icon)
1873           rows[uid].icon.src = this.env.deletedicon;
1874         }
1875       }
1876   };
fe79b1 1877
b566ff 1878   /*********************************************************/
S 1879   /*********           login form methods          *********/
1880   /*********************************************************/
1881
1882   // handler for keyboard events on the _user field
65444b 1883   this.login_user_keyup = function(e)
b566ff 1884   {
9bbb17 1885     var key = rcube_event.get_keycode(e);
T 1886     var elm;
b566ff 1887
S 1888     // enter
9bbb17 1889     if ((key==13) && (elm = rcube_find_object('_pass')))
b566ff 1890     {
9bbb17 1891       elm.focus();
b566ff 1892       return false;
S 1893     }
1894   };
f11541 1895
4e17e6 1896
T 1897   /*********************************************************/
1898   /*********        message compose methods        *********/
1899   /*********************************************************/
1cded8 1900   
T 1901   
977a29 1902   // checks the input fields before sending a message
T 1903   this.check_compose_input = function()
1904     {
1905     // check input fields
1906     var input_to = rcube_find_object('_to');
e8f8fe 1907     var input_cc = rcube_find_object('_cc');
T 1908     var input_bcc = rcube_find_object('_bcc');
977a29 1909     var input_subject = rcube_find_object('_subject');
T 1910     var input_message = rcube_find_object('_message');
1911
1912     // check for empty recipient
e8f8fe 1913     var recipients = input_to.value ? input_to.value : (input_cc.value ? input_cc.value : input_bcc.value);
T 1914     if (!rcube_check_email(recipients.replace(/^\s+/, '').replace(/[\s,;]+$/, ''), true))
977a29 1915       {
T 1916       alert(this.get_label('norecipientwarning'));
1917       input_to.focus();
1918       return false;
1919       }
1920
1921     // display localized warning for missing subject
1922     if (input_subject && input_subject.value == '')
1923       {
1924       var subject = prompt(this.get_label('nosubjectwarning'), this.get_label('nosubject'));
1925
1926       // user hit cancel, so don't send
1927       if (!subject && subject !== '')
1928         {
1929         input_subject.focus();
1930         return false;
1931         }
1932       else
1933         {
1934         input_subject.value = subject ? subject : this.get_label('nosubject');            
1935         }
1936       }
1937
1938     // check for empty body
4ca10b 1939     if ((!window.tinyMCE || !tinyMCE.get('compose-body')) && input_message.value == '' && !confirm(this.get_label('nobodywarning')))
977a29 1940       {
31d9ef 1941       input_message.focus();
T 1942       return false;
977a29 1943       }
4ca10b 1944     else if (window.tinyMCE && tinyMCE.get('compose-body') && !tinyMCE.get('compose-body').getContent() && !confirm(this.get_label('nobodywarning')))
5f0724 1945       {
A 1946       tinyMCE.get('compose-body').focus();
1947       return false;
1948       }
977a29 1949
T 1950     return true;
1951     };
41fa0b 1952
4ca10b 1953   this.display_spellcheck_controls = function(vis)
T 1954   {
1955     if (this.env.spellcheck) {
1956       this.env.spellcheck.check_link.style.visibility = vis ? 'visible' : 'hidden';
1957       this.env.spellcheck.switch_lan_pic.style.visibility = vis ? 'visible' : 'hidden';
1958     }
1959   };
41fa0b 1960
e170b4 1961   this.set_spellcheck_state = function(s)
T 1962     {
86958f 1963     this.spellcheck_ready = (s=='check_spelling' || s=='ready');
e170b4 1964     this.enable_command('spellcheck', this.spellcheck_ready);
86958f 1965     };
e170b4 1966
T 1967
f11541 1968   this.set_draft_id = function(id)
T 1969     {
1970     var f;
1971     if (f = rcube_find_object('_draft_saveid'))
1972       f.value = id;
1973     };
1974
f0f98f 1975   this.auto_save_start = function()
S 1976     {
9a5261 1977     if (this.env.draft_autosave)
cfdf04 1978       this.save_timer = self.setTimeout(function(){ ref.command("savedraft"); }, this.env.draft_autosave * 1000);
4b9efb 1979
S 1980     // Unlock interface now that saving is complete
1981     this.busy = false;
41fa0b 1982     };
T 1983
1984
f11541 1985   this.compose_field_hash = function(save)
977a29 1986     {
T 1987     // check input fields
1988     var input_to = rcube_find_object('_to');
c17991 1989     var input_cc = rcube_find_object('_cc');
S 1990     var input_bcc = rcube_find_object('_bcc');
977a29 1991     var input_subject = rcube_find_object('_subject');
c5fb69 1992     var editor, input_message;
977a29 1993     var str = '';
c5fb69 1994     
977a29 1995     if (input_to && input_to.value)
T 1996       str += input_to.value+':';
1997     if (input_cc && input_cc.value)
1998       str += input_cc.value+':';
1999     if (input_bcc && input_bcc.value)
2000       str += input_bcc.value+':';
2001     if (input_subject && input_subject.value)
2002       str += input_subject.value+':';
c5fb69 2003     
A 2004     if (editor = tinyMCE.get('compose-body'))
2005       str += editor.getContent();
2006     else
2007       {
2008       input_message = rcube_find_object('_message');
977a29 2009       str += input_message.value;
c5fb69 2010       }
f11541 2011     
T 2012     if (save)
2013       this.cmp_hash = str;
2014     
977a29 2015     return str;
T 2016     };
2017     
2018   
1cded8 2019   this.change_identity = function(obj)
T 2020     {
2021     if (!obj || !obj.options)
2022       return false;
2023
2024     var id = obj.options[obj.selectedIndex].value;
2025     var input_message = rcube_find_object('_message');
2026     var message = input_message ? input_message.value : '';
a0109c 2027     var is_html = (rcube_find_object('_is_html').value == '1');
749b07 2028     var sig, p;
1cded8 2029
1966c5 2030     if (!this.env.identity)
S 2031       this.env.identity = id
a0109c 2032   
S 2033     if (!is_html)
1cded8 2034       {
a0109c 2035       // remove the 'old' signature
S 2036       if (this.env.identity && this.env.signatures && this.env.signatures[this.env.identity])
2037         {
53bd8f 2038         if (this.env.signatures[this.env.identity]['is_html'])
A 2039           sig = this.env.signatures[this.env.identity]['plain_text'];
2040         else
2041       sig = this.env.signatures[this.env.identity]['text'];
2042         
2043     if (sig.indexOf('-- ')!=0)
dd792e 2044           sig = '-- \n'+sig;
S 2045
a0109c 2046         p = message.lastIndexOf(sig);
S 2047         if (p>=0)
2048           message = message.substring(0, p-1) + message.substring(p+sig.length, message.length);
2049         }
dd792e 2050
a0109c 2051       // add the new signature string
S 2052       if (this.env.signatures && this.env.signatures[id])
2053         {
2054         sig = this.env.signatures[id]['text'];
dd792e 2055         if (this.env.signatures[id]['is_html'])
S 2056           {
2057           sig = this.env.signatures[id]['plain_text'];
2058           }
2059         if (sig.indexOf('-- ')!=0)
2060           sig = '-- \n'+sig;
a0109c 2061         message += '\n'+sig;
S 2062         }
1cded8 2063       }
a0109c 2064     else
1cded8 2065       {
d9344f 2066       var editor = tinyMCE.get('compose-body');
a0109c 2067
910d07 2068       if (this.env.signatures)
dd792e 2069         {
910d07 2070         // Append the signature as a div within the body
d9344f 2071         var sigElem = editor.dom.get("_rc_sig");
910d07 2072     var newsig = '';
A 2073     var htmlsig = true;
2074     
dd792e 2075         if (!sigElem)
a0109c 2076           {
910d07 2077           sigElem = editor.getDoc().createElement("div");
dd792e 2078           sigElem.setAttribute("id", "_rc_sig");
d9344f 2079           editor.getBody().appendChild(sigElem);
a0109c 2080           }
910d07 2081
A 2082     if (this.env.signatures[id])
2083       {
2084       newsig = this.env.signatures[id]['text'];
2085       htmlsig = this.env.signatures[id]['is_html'];
2086       }
2087
2088         if (htmlsig)
2089           sigElem.innerHTML = newsig;
dd792e 2090         else
910d07 2091           sigElem.innerHTML = '<pre>' + newsig + '</pre>';
dd792e 2092         }
1cded8 2093       }
T 2094
749b07 2095     if (input_message)
1cded8 2096       input_message.value = message;
a0109c 2097
1cded8 2098     this.env.identity = id;
1c5853 2099     return true;
1cded8 2100     };
4e17e6 2101
T 2102
2103   this.show_attachment_form = function(a)
2104     {
2105     if (!this.gui_objects.uploadbox)
2106       return false;
2107       
2108     var elm, list;
2109     if (elm = this.gui_objects.uploadbox)
2110       {
2111       if (a &&  (list = this.gui_objects.attachmentlist))
2112         {
2113         var pos = rcube_get_object_pos(list);
2114         var left = pos.x;
2115         var top = pos.y + list.offsetHeight + 10;
2116       
2117         elm.style.top = top+'px';
2118         elm.style.left = left+'px';
2119         }
2120       
2121       elm.style.visibility = a ? 'visible' : 'hidden';
2122       }
2123       
2124     // clear upload form
480f5d 2125     try {
T 2126       if (!a && this.gui_objects.attachmentform != this.gui_objects.messageform)
2127           this.gui_objects.attachmentform.reset();
2128     }
2129     catch(e){}  // ignore errors
1c5853 2130     
S 2131     return true;  
4e17e6 2132     };
T 2133
2134
2135   // upload attachment file
2136   this.upload_file = function(form)
2137     {
2138     if (!form)
2139       return false;
2140       
2141     // get file input fields
2142     var send = false;
2143     for (var n=0; n<form.elements.length; n++)
2144       if (form.elements[n].type=='file' && form.elements[n].value)
2145         {
2146         send = true;
2147         break;
2148         }
2149     
2150     // create hidden iframe and post upload form
2151     if (send)
2152       {
2153       var ts = new Date().getTime();
2154       var frame_name = 'rcmupload'+ts;
2155
2156       // have to do it this way for IE
2157       // otherwise the form will be posted to a new window
ee0da5 2158       if(document.all)
4e17e6 2159         {
T 2160         var html = '<iframe name="'+frame_name+'" src="program/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>';
2161         document.body.insertAdjacentHTML('BeforeEnd',html);
2162         }
2163       else  // for standards-compilant browsers
2164         {
2165         var frame = document.createElement('IFRAME');
2166         frame.name = frame_name;
ee0da5 2167         frame.style.border = 'none';
A 2168         frame.style.width = 0;
2169         frame.style.height = 0;
4e17e6 2170         frame.style.visibility = 'hidden';
T 2171         document.body.appendChild(frame);
2172         }
2173
2174       form.target = frame_name;
2175       form.action = this.env.comm_path+'&_action=upload';
2176       form.setAttribute('enctype', 'multipart/form-data');
2177       form.submit();
2178       }
2179     
2180     // set reference to the form object
2181     this.gui_objects.attachmentform = form;
1c5853 2182     return true;
4e17e6 2183     };
T 2184
2185
2186   // add file name to attachment list
2187   // called from upload page
9a5261 2188   this.add2attachment_list = function(name, content)
4e17e6 2189     {
T 2190     if (!this.gui_objects.attachmentlist)
2191       return false;
aade7b 2192       
4e17e6 2193     var li = document.createElement('LI');
a894ba 2194     li.id = name;
S 2195     li.innerHTML = content;
4e17e6 2196     this.gui_objects.attachmentlist.appendChild(li);
1c5853 2197     return true;
4e17e6 2198     };
T 2199
a894ba 2200   this.remove_from_attachment_list = function(name)
S 2201     {
2202     if (!this.gui_objects.attachmentlist)
2203       return false;
2204
2205     var list = this.gui_objects.attachmentlist.getElementsByTagName("li");
2206     for (i=0;i<list.length;i++)
2207       if (list[i].id == name)
9a5261 2208         this.gui_objects.attachmentlist.removeChild(list[i]);
41fa0b 2209     };
a894ba 2210
S 2211   this.remove_attachment = function(name)
2212     {
2213     if (name)
8d0758 2214       this.http_post('remove-attachment', '_file='+urlencode(name));
a894ba 2215
S 2216     return true;
41fa0b 2217     };
4e17e6 2218
T 2219   // send remote request to add a new contact
2220   this.add_contact = function(value)
2221     {
2222     if (value)
f11541 2223       this.http_post('addcontact', '_address='+value);
1c5853 2224     
S 2225     return true;
4e17e6 2226     };
T 2227
f11541 2228   // send remote request to search mail or contacts
T 2229   this.qsearch = function(value)
4647e1 2230     {
f11541 2231     if (value != '')
4647e1 2232       {
f11541 2233       if (this.message_list)
T 2234         this.message_list.clear();
2235       else if (this.contact_list) {
2236         this.contact_list.clear(true);
2237         this.show_contentframe(false);
2238       }
2239
2240       // reset vars
2241       this.env.current_page = 1;
4647e1 2242       this.set_busy(true, 'searching');
c5418b 2243       this.http_request('search', '_q='+urlencode(value)+(this.env.mailbox ? '&_mbox='+urlencode(this.env.mailbox) : '')+(this.env.source ? '&_source='+urlencode(this.env.source) : ''), true);
4647e1 2244       }
1c5853 2245     return true;
4647e1 2246     };
T 2247
2248   // reset quick-search form
2249   this.reset_qsearch = function()
2250     {
2251     if (this.gui_objects.qsearchbox)
2252       this.gui_objects.qsearchbox.value = '';
2253       
2254     this.env.search_request = null;
1c5853 2255     return true;
4647e1 2256     };
41fa0b 2257
T 2258
9a5762 2259   this.sent_successfully = function(type, msg)
41fa0b 2260     {
T 2261     this.list_mailbox();
9a5762 2262     this.display_message(msg, type, true);
41fa0b 2263     }
T 2264
4e17e6 2265
T 2266   /*********************************************************/
2267   /*********     keyboard live-search methods      *********/
2268   /*********************************************************/
2269
2270
2271   // handler for keyboard events on address-fields
2272   this.ksearch_keypress = function(e, obj)
2273     {
2274     if (typeof(this.env.contacts)!='object' || !this.env.contacts.length)
2275       return true;
2276
2277     if (this.ksearch_timer)
2278       clearTimeout(this.ksearch_timer);
2279
2280     var highlight;
9bbb17 2281     var key = rcube_event.get_keycode(e);
T 2282     var mod = rcube_event.get_modifier(e);
4e17e6 2283
T 2284     switch (key)
2285       {
2286       case 38:  // key up
2287       case 40:  // key down
2288         if (!this.ksearch_pane)
2289           break;
2290           
2291         var dir = key==38 ? 1 : 0;
2292         var next;
2293         
2294         highlight = document.getElementById('rcmksearchSelected');
2295         if (!highlight)
2296           highlight = this.ksearch_pane.ul.firstChild;
2297         
2298         if (highlight && (next = dir ? highlight.previousSibling : highlight.nextSibling))
2299           {
2300           highlight.removeAttribute('id');
2301           this.set_classname(highlight, 'selected', false);
2302           }
2303
2304         if (next)
2305           {
2306           next.setAttribute('id', 'rcmksearchSelected');
2307           this.set_classname(next, 'selected', true);
2308           this.ksearch_selected = next._rcm_id;
2309           }
2310
86958f 2311         return rcube_event.cancel(e);
4e17e6 2312
T 2313       case 9:  // tab
9bbb17 2314         if(mod == SHIFT_KEY)
4e17e6 2315           break;
T 2316
2317       case 13:  // enter     
2318         if (this.ksearch_selected===null || !this.ksearch_input || !this.ksearch_value)
2319           break;
2320
86958f 2321         // insert selected address and hide ksearch pane
T 2322         this.insert_recipient(this.ksearch_selected);
4e17e6 2323         this.ksearch_hide();
86958f 2324
T 2325         return rcube_event.cancel(e);
4e17e6 2326
T 2327       case 27:  // escape
2328         this.ksearch_hide();
2329         break;
2330
2331       }
2332
2333     // start timer
dbbd1f 2334     this.ksearch_timer = window.setTimeout(function(){ ref.ksearch_get_results(); }, 200);
4e17e6 2335     this.ksearch_input = obj;
T 2336     
2337     return true;
2338     };
86958f 2339
T 2340
2341   this.insert_recipient = function(id)
2342   {
2343     if (!this.env.contacts[id] || !this.ksearch_input)
2344       return;
2345     
2346     // get cursor pos
2347     var inp_value = this.ksearch_input.value.toLowerCase();
2348     var cpos = this.get_caret_pos(this.ksearch_input);
2349     var p = inp_value.lastIndexOf(this.ksearch_value, cpos);
2350     
2351     // replace search string with full address
2352     var pre = this.ksearch_input.value.substring(0, p);
2353     var end = this.ksearch_input.value.substring(p+this.ksearch_value.length, this.ksearch_input.value.length);
2354     var insert  = this.env.contacts[id]+', ';
2355     this.ksearch_input.value = pre + insert + end;
2356     
2357     // set caret to insert pos
2358     cpos = p+insert.length;
2359     if (this.ksearch_input.setSelectionRange)
2360       this.ksearch_input.setSelectionRange(cpos, cpos);
2361   };
4e17e6 2362
T 2363
2364   // address search processor
2365   this.ksearch_get_results = function()
2366     {
2367     var inp_value = this.ksearch_input ? this.ksearch_input.value : null;
2368     if (inp_value===null)
2369       return;
2370
2371     // get string from current cursor pos to last comma
2372     var cpos = this.get_caret_pos(this.ksearch_input);
2373     var p = inp_value.lastIndexOf(',', cpos-1);
2374     var q = inp_value.substring(p+1, cpos);
2375
2376     // trim query string
2377     q = q.replace(/(^\s+|\s+$)/g, '').toLowerCase();
2378
2379     if (!q.length || q==this.ksearch_value)
2380       {
2381       if (!q.length && this.ksearch_pane && this.ksearch_pane.visible)
2382         this.ksearch_pane.show(0);
2383
2384       return;
2385       }
2386
2387     this.ksearch_value = q;
2388     
2389     // start searching the contact list
2390     var a_results = new Array();
2391     var a_result_ids = new Array();
2392     var c=0;
2393     for (var i=0; i<this.env.contacts.length; i++)
2394       {
2395       if (this.env.contacts[i].toLowerCase().indexOf(q)>=0)
2396         {
2397         a_results[c] = this.env.contacts[i];
2398         a_result_ids[c++] = i;
2399         
2400         if (c==15)  // limit search results
2401           break;
2402         }
2403       }
2404
2405     // display search results
2406     if (c && a_results.length)
2407       {
2408       var p, ul, li;
2409       
2410       // create results pane if not present
2411       if (!this.ksearch_pane)
2412         {
2413         ul = document.createElement('UL');
2414         this.ksearch_pane = new rcube_layer('rcmKSearchpane', {vis:0, zindex:30000});
2415         this.ksearch_pane.elm.appendChild(ul);
2416         this.ksearch_pane.ul = ul;
2417         }
2418       else
2419         ul = this.ksearch_pane.ul;
2420
2421       // remove all search results
2422       ul.innerHTML = '';
2423             
2424       // add each result line to list
2425       for (i=0; i<a_results.length; i++)
2426         {
2427         li = document.createElement('LI');
2428         li.innerHTML = a_results[i].replace(/</, '&lt;').replace(/>/, '&gt;');
2429         li._rcm_id = a_result_ids[i];
2430         ul.appendChild(li);
2431         }
2432
2433       // check if last selected item is still in result list
2434       if (this.ksearch_selected!==null)
2435         {
2436         p = find_in_array(this.ksearch_selected, a_result_ids);
2437         if (p>=0 && ul.childNodes)
2438           {
2439           ul.childNodes[p].setAttribute('id', 'rcmksearchSelected');
2440           this.set_classname(ul.childNodes[p], 'selected', true);
2441           }
2442         else
2443           this.ksearch_selected = null;
2444         }
2445       
2446       // if no item selected, select the first one
2447       if (this.ksearch_selected===null)
2448         {
2449         ul.firstChild.setAttribute('id', 'rcmksearchSelected');
2450         this.set_classname(ul.firstChild, 'selected', true);
2451         this.ksearch_selected = a_result_ids[0];
2452         }
2453
2454       // move the results pane right under the input box and make it visible
2455       var pos = rcube_get_object_pos(this.ksearch_input);
2456       this.ksearch_pane.move(pos.x, pos.y+this.ksearch_input.offsetHeight);
2457       this.ksearch_pane.show(1); 
2458       }
2459     // hide results pane
2460     else
2461       this.ksearch_hide();
2462     };
2463
2464
2465   this.ksearch_blur = function(e, obj)
2466     {
2467     if (this.ksearch_timer)
2468       clearTimeout(this.ksearch_timer);
2469
2470     this.ksearch_value = '';      
2471     this.ksearch_input = null;
2472     
2473     this.ksearch_hide();
2474     };
2475
2476
2477   this.ksearch_hide = function()
2478     {
2479     this.ksearch_selected = null;
2480     
2481     if (this.ksearch_pane)
2482       this.ksearch_pane.show(0);    
2483     };
2484
2485
2486
2487   /*********************************************************/
2488   /*********         address book methods          *********/
2489   /*********************************************************/
2490
2491
6b47de 2492   this.contactlist_keypress = function(list)
T 2493     {
2494       if (list.key_pressed == list.DELETE_KEY)
2495         this.command('delete');
2496     };
2497
2498
2499   this.contactlist_select = function(list)
2500     {
f11541 2501       if (this.preview_timer)
T 2502         clearTimeout(this.preview_timer);
2503
2504       var id, frame, ref = this;
6b47de 2505       if (id = list.get_single_selection())
26f5b0 2506         this.preview_timer = window.setTimeout(function(){ ref.load_contact(id, 'show'); }, 200);
f11541 2507       else if (this.env.contentframe)
T 2508         this.show_contentframe(false);
6b47de 2509
f11541 2510       this.enable_command('compose', list.selection.length > 0);
f74b28 2511       this.enable_command('edit', (id && this.env.address_sources && !this.env.address_sources[this.env.source].readonly) ? true : false);
f11541 2512       this.enable_command('delete', list.selection.length && this.env.address_sources && !this.env.address_sources[this.env.source].readonly);
6b47de 2513
f11541 2514       return false;
6b47de 2515     };
T 2516
2517
f11541 2518   this.list_contacts = function(src, page)
4e17e6 2519     {
T 2520     var add_url = '';
2521     var target = window;
2522     
f11541 2523     if (!src)
T 2524       src = this.env.source;
2525     
2526     if (page && this.current_page==page && src == this.env.source)
4e17e6 2527       return false;
f11541 2528       
T 2529     if (src != this.env.source)
2530       {
2531       page = 1;
2532       this.env.current_page = page;
6b603d 2533       this.reset_qsearch();
f11541 2534       }
T 2535
2536     this.select_folder(src, this.env.source);
2537     this.env.source = src;
4e17e6 2538
T 2539     // load contacts remotely
2540     if (this.gui_objects.contactslist)
2541       {
f11541 2542       this.list_contacts_remote(src, page);
4e17e6 2543       return;
T 2544       }
2545
2546     if (this.env.contentframe && window.frames && window.frames[this.env.contentframe])
2547       {
2548       target = window.frames[this.env.contentframe];
2549       add_url = '&_framed=1';
2550       }
2551
f11541 2552     // also send search request to get the correct listing
T 2553     if (this.env.search_request)
2554       add_url += '&_search='+this.env.search_request;
2555
4e17e6 2556     this.set_busy(true, 'loading');
f11541 2557     target.location.href = this.env.comm_path+(src ? '&_source='+urlencode(src) : '')+(page ? '&_page='+page : '')+add_url;
4e17e6 2558     };
T 2559
2560
2561   // send remote request to load contacts list
f11541 2562   this.list_contacts_remote = function(src, page)
4e17e6 2563     {
6b47de 2564     // clear message list first
f11541 2565     this.contact_list.clear(true);
T 2566     this.show_contentframe(false);
2567     this.enable_command('delete', 'compose', false);
4e17e6 2568
T 2569     // send request to server
fc7374 2570     var url = (src ? '_source='+urlencode(src) : '') + (page ? (src?'&':'') + '_page='+page : '');
f11541 2571     this.env.source = src;
T 2572     
2573     // also send search request to get the right messages 
2574     if (this.env.search_request) 
2575       url += '&_search='+this.env.search_request;
2576
4e17e6 2577     this.set_busy(true, 'loading');
ecf759 2578     this.http_request('list', url, true);
4e17e6 2579     };
T 2580
2581
2582   // load contact record
2583   this.load_contact = function(cid, action, framed)
2584     {
2585     var add_url = '';
2586     var target = window;
2587     if (this.env.contentframe && window.frames && window.frames[this.env.contentframe])
2588       {
2589       add_url = '&_framed=1';
2590       target = window.frames[this.env.contentframe];
f11541 2591       this.show_contentframe(true);
4e17e6 2592       }
T 2593     else if (framed)
2594       return false;
f11541 2595       
T 2596     if (action && (cid || action=='add') && !this.drag_active)
4e17e6 2597       {
T 2598       this.set_busy(true);
f11541 2599       target.location.href = this.env.comm_path+'&_action='+action+'&_source='+urlencode(this.env.source)+'&_cid='+urlencode(cid) + add_url;
4e17e6 2600       }
1c5853 2601     return true;
4e17e6 2602     };
f11541 2603
T 2604   // copy a contact to the specified target (group or directory)
2605   this.copy_contact = function(cid, to)
2606   {
2607     if (!cid)
2608       cid = this.contact_list.get_selection().join(',');
2609
2610     if (to != this.env.source && cid && this.env.address_sources[to] && !this.env.address_sources[to].readonly)
2611       this.http_post('copy', '_cid='+urlencode(cid)+'&_source='+urlencode(this.env.source)+'&_to='+urlencode(to));
2612   };
4e17e6 2613
T 2614
2615   this.delete_contacts = function()
2616     {
2617     // exit if no mailbox specified or if selection is empty
6b47de 2618     var selection = this.contact_list.get_selection();
T 2619     if (!(selection.length || this.env.cid) || !confirm(this.get_label('deletecontactconfirm')))
4e17e6 2620       return;
5e3512 2621       
4e17e6 2622     var a_cids = new Array();
b15568 2623     var qs = '';
4e17e6 2624
T 2625     if (this.env.cid)
2626       a_cids[a_cids.length] = this.env.cid;
2627     else
2628       {
2629       var id;
6b47de 2630       for (var n=0; n<selection.length; n++)
4e17e6 2631         {
6b47de 2632         id = selection[n];
4e17e6 2633         a_cids[a_cids.length] = id;
f4f8c6 2634         this.contact_list.remove_row(id, (n == selection.length-1));
4e17e6 2635         }
T 2636
2637       // hide content frame if we delete the currently displayed contact
f11541 2638       if (selection.length == 1)
T 2639         this.show_contentframe(false);
4e17e6 2640       }
T 2641
b15568 2642     // also send search request to get the right records from the next page
T 2643     if (this.env.search_request) 
2644       qs += '&_search='+this.env.search_request;
2645
4e17e6 2646     // send request to server
4f9c83 2647     this.http_post('delete', '_cid='+urlencode(a_cids.join(','))+'&_source='+urlencode(this.env.source)+'&_from='+(this.env.action ? this.env.action : '')+qs);
1c5853 2648     return true;
4e17e6 2649     };
T 2650
2651
2652   // update a contact record in the list
2653   this.update_contact_row = function(cid, cols_arr)
2654     {
6b47de 2655     var row;
T 2656     if (this.contact_list.rows[cid] && (row = this.contact_list.rows[cid].obj))
2657       {
2658       for (var c=0; c<cols_arr.length; c++)
2659         if (row.cells[c])
2660           row.cells[c].innerHTML = cols_arr[c];
2661
2662       return true;
2663       }
2664
2665     return false;
4e17e6 2666     };
T 2667
2668
2669   /*********************************************************/
2670   /*********        user settings methods          *********/
2671   /*********************************************************/
2672
b0dbf3 2673   this.init_subscription_list = function()
S 2674     {
2675     var p = this;
68b6a9 2676     this.subscription_list = new rcube_list_widget(this.gui_objects.subscriptionlist, {multiselect:false, draggable:true, keyboard:false, toggleselect:true});
b0dbf3 2677     this.subscription_list.addEventListener('select', function(o){ p.subscription_select(o); });
S 2678     this.subscription_list.addEventListener('dragstart', function(o){ p.drag_active = true; });
2679     this.subscription_list.addEventListener('dragend', function(o){ p.subscription_move_folder(o); });
68b6a9 2680     this.subscription_list.row_init = function (row)
S 2681       {
2682       var anchors = row.obj.getElementsByTagName('A');
2683       if (anchors[0])
0aa430 2684         anchors[0].onclick = function() { p.rename_folder(row.id); return false; };
68b6a9 2685       if (anchors[1])
0aa430 2686         anchors[1].onclick = function() { p.delete_folder(row.id); return false; };
68b6a9 2687       row.obj.onmouseover = function() { p.focus_subscription(row.id); };
S 2688       row.obj.onmouseout = function() { p.unfocus_subscription(row.id); };
2689       }
b0dbf3 2690     this.subscription_list.init();
S 2691     }
2692
6b47de 2693   this.identity_select = function(list)
T 2694     {
2695     var id;
2696     if (id = list.get_single_selection())
2697       this.load_identity(id, 'edit-identity');
2698     };
4e17e6 2699
T 2700   // load contact record
2701   this.load_identity = function(id, action)
2702     {
2703     if (action=='edit-identity' && (!id || id==this.env.iid))
1c5853 2704       return false;
4e17e6 2705
T 2706     var add_url = '';
2707     var target = window;
2708     if (this.env.contentframe && window.frames && window.frames[this.env.contentframe])
2709       {
2710       add_url = '&_framed=1';
2711       target = window.frames[this.env.contentframe];
2712       document.getElementById(this.env.contentframe).style.visibility = 'inherit';
2713       }
2714
2715     if (action && (id || action=='add-identity'))
2716       {
2717       this.set_busy(true);
2718       target.location.href = this.env.comm_path+'&_action='+action+'&_iid='+id+add_url;
2719       }
1c5853 2720     return true;
4e17e6 2721     };
T 2722
2723
2724   this.delete_identity = function(id)
2725     {
2726     // exit if no mailbox specified or if selection is empty
6b47de 2727     var selection = this.identity_list.get_selection();
T 2728     if (!(selection.length || this.env.iid))
4e17e6 2729       return;
T 2730     
2731     if (!id)
6b47de 2732       id = this.env.iid ? this.env.iid : selection[0];
4e17e6 2733
T 2734     // if (this.env.framed && id)
6b47de 2735     this.goto_url('delete-identity', '_iid='+id, true);
1c5853 2736     return true;
b0dbf3 2737     };
S 2738
2739
2740   this.focus_subscription = function(id)
2741     {
68b6a9 2742     var row, folder;
b0dbf3 2743     var reg = RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$');
3e71ab 2744
681a59 2745     if (this.drag_active && this.env.folder && (row = document.getElementById(id)))
3e71ab 2746       if (this.env.subscriptionrows[id] &&
S 2747           (folder = this.env.subscriptionrows[id][0]))
b0dbf3 2748         {
3e71ab 2749         if (this.check_droptarget(folder) &&
681a59 2750             !this.env.subscriptionrows[this.get_folder_row_id(this.env.folder)][2] &&    
A 2751         (folder != this.env.folder.replace(reg, '')) &&
3e71ab 2752             (!folder.match(new RegExp('^'+RegExp.escape(this.env.folder+this.env.delimiter)))))
b0dbf3 2753           {
3e71ab 2754           this.set_env('dstfolder', folder);
S 2755           this.set_classname(row, 'droptarget', true);
b0dbf3 2756           }
S 2757         }
3e71ab 2758       else if (this.env.folder.match(new RegExp(RegExp.escape(this.env.delimiter))))
b0dbf3 2759         {
3e71ab 2760         this.set_env('dstfolder', this.env.delimiter);
S 2761         this.set_classname(this.subscription_list.frame, 'droptarget', true);
b0dbf3 2762         }
S 2763     }
2764
2765
2766   this.unfocus_subscription = function(id)
2767     {
3e71ab 2768       var row;
b0dbf3 2769       this.set_env('dstfolder', null);
3e71ab 2770       if (this.env.subscriptionrows[id] &&
S 2771           (row = document.getElementById(id)))
b0dbf3 2772         this.set_classname(row, 'droptarget', false);
3e71ab 2773       else
S 2774         this.set_classname(this.subscription_list.frame, 'droptarget', false);
b0dbf3 2775     }
S 2776
2777
2778   this.subscription_select = function(list)
2779     {
68b6a9 2780     var id, folder;
S 2781     if ((id = list.get_single_selection()) &&
2782         this.env.subscriptionrows['rcmrow'+id] &&
681a59 2783         (folder = this.env.subscriptionrows['rcmrow'+id][0]))
68b6a9 2784       this.set_env('folder', folder);
S 2785     else
2786       this.set_env('folder', null);
a8d23d 2787       
T 2788     if (this.gui_objects.createfolderhint)
2789       this.gui_objects.createfolderhint.innerHTML = this.env.folder ? this.get_label('addsubfolderhint') : '';
b0dbf3 2790     };
S 2791
2792
2793   this.subscription_move_folder = function(list)
2794     {
2795     var reg = RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$');
2796     if (this.env.folder && this.env.dstfolder && (this.env.dstfolder != this.env.folder) &&
2797         (this.env.dstfolder != this.env.folder.replace(reg, '')))
2798       {
2799       var reg = new RegExp('[^'+RegExp.escape(this.env.delimiter)+']*['+RegExp.escape(this.env.delimiter)+']', 'g');
2800       var basename = this.env.folder.replace(reg, '');
2801       var newname = this.env.dstfolder==this.env.delimiter ? basename : this.env.dstfolder+this.env.delimiter+basename;
2802       this.http_post('rename-folder', '_folder_oldname='+urlencode(this.env.folder)+'&_folder_newname='+urlencode(newname));
2803       }
2804     this.drag_active = false;
68b6a9 2805     this.unfocus_subscription(this.get_folder_row_id(this.env.dstfolder));
4e17e6 2806     };
T 2807
2808
24053e 2809   // tell server to create and subscribe a new mailbox
4e17e6 2810   this.create_folder = function(name)
T 2811     {
a8d23d 2812     if (this.edit_folder)
T 2813       this.reset_folder_rename();
24053e 2814
4e17e6 2815     var form;
T 2816     if ((form = this.gui_objects.editform) && form.elements['_folder_name'])
6eaac2 2817       {
4e17e6 2818       name = form.elements['_folder_name'].value;
T 2819
6eaac2 2820       if (name.indexOf(this.env.delimiter)>=0)
A 2821         {
134eaf 2822         alert(this.get_label('forbiddencharacter')+' ('+this.env.delimiter+')');
6eaac2 2823         return false;
A 2824         }
2825
2826       if (this.env.folder && name != '')
2827         name = this.env.folder+this.env.delimiter+name;
2828
8d0758 2829       this.http_post('create-folder', '_name='+urlencode(name), true);
6eaac2 2830       }
4e17e6 2831     else if (form.elements['_folder_name'])
T 2832       form.elements['_folder_name'].focus();
2833     };
2834
24053e 2835
d19426 2836   // start renaming the mailbox name.
24053e 2837   // this will replace the name string with an input field
68b6a9 2838   this.rename_folder = function(id)
4e17e6 2839     {
24053e 2840     var temp, row, form;
T 2841
2842     // reset current renaming
681a59 2843     if (temp = this.edit_folder)
A 2844       {
2845       this.reset_folder_rename();
2846       if (temp == id)
2847         return;
2848       }
24053e 2849
0aa430 2850     if (id && this.env.subscriptionrows[id] && (row = document.getElementById(id)))
4e17e6 2851       {
b0dbf3 2852       var reg = new RegExp('.*['+RegExp.escape(this.env.delimiter)+']');
24053e 2853       this.name_input = document.createElement('INPUT');
681a59 2854       this.name_input.value = this.env.subscriptionrows[id][0].replace(reg, '');
24053e 2855       this.name_input.style.width = '100%';
681a59 2856
b0dbf3 2857       reg = new RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$');
0aa430 2858       this.name_input.__parent = this.env.subscriptionrows[id][0].replace(reg, '');
24053e 2859       this.name_input.onkeypress = function(e){ rcmail.name_input_keypress(e); };
T 2860       
2861       row.cells[0].replaceChild(this.name_input, row.cells[0].firstChild);
2862       this.edit_folder = id;
2863       this.name_input.select();
2864       
2865       if (form = this.gui_objects.editform)
2866         form.onsubmit = function(){ return false; };
4e17e6 2867       }
1cded8 2868     };
T 2869
2870
24053e 2871   // remove the input field and write the current mailbox name to the table cell
T 2872   this.reset_folder_rename = function()
1cded8 2873     {
24053e 2874     var cell = this.name_input ? this.name_input.parentNode : null;
681a59 2875
e170b4 2876     if (cell && this.edit_folder && this.env.subscriptionrows[this.edit_folder])
681a59 2877       cell.innerHTML = this.env.subscriptionrows[this.edit_folder][1];
24053e 2878       
T 2879     this.edit_folder = null;
2880     };
2881
2882
2883   // handler for keyboard events on the input field
2884   this.name_input_keypress = function(e)
2885     {
9bbb17 2886     var key = rcube_event.get_keycode(e);
24053e 2887
T 2888     // enter
2889     if (key==13)
2890       {
2891       var newname = this.name_input ? this.name_input.value : null;
2892       if (this.edit_folder && newname)
b0dbf3 2893         {
134eaf 2894         if (newname.indexOf(this.env.delimiter)>=0)
6eaac2 2895           {
134eaf 2896           alert(this.get_label('forbiddencharacter')+' ('+this.env.delimiter+')');
6eaac2 2897           return false;
A 2898           }
2899
0aa430 2900         if (this.name_input.__parent)
T 2901           newname = this.name_input.__parent + this.env.delimiter + newname;
134eaf 2902
4e59f6 2903         this.http_post('rename-folder', '_folder_oldname='+urlencode(this.env.subscriptionrows[this.edit_folder][0])+'&_folder_newname='+urlencode(newname), true);
b0dbf3 2904         }
24053e 2905       }
T 2906     // escape
2907     else if (key==27)
2908       this.reset_folder_rename();
2909     };
2910
2911
2912   // delete a specific mailbox with all its messages
68b6a9 2913   this.delete_folder = function(id)
24053e 2914     {
68b6a9 2915     var folder = this.env.subscriptionrows[id][0];
S 2916
41841b 2917     if (this.edit_folder)
S 2918       this.reset_folder_rename();
fdbb19 2919
68b6a9 2920     if (folder && confirm(this.get_label('deletefolderconfirm')))
S 2921       {
2922       this.http_post('delete-folder', '_mboxes='+urlencode(folder));
2923       this.set_env('folder', null);
0ed265 2924
T 2925       if (this.gui_objects.createfolderhint)
2926         this.gui_objects.createfolderhint.innerHTML = '';
68b6a9 2927       }
24053e 2928     };
T 2929
2930
2931   // add a new folder to the subscription list by cloning a folder row
681a59 2932   this.add_folder_row = function(name, display_name, replace, before)
24053e 2933     {
T 2934     if (!this.gui_objects.subscriptionlist)
2935       return false;
2936
681a59 2937     // find not protected folder    
24053e 2938     for (var refid in this.env.subscriptionrows)
681a59 2939       if (this.env.subscriptionrows[refid]!=null && !this.env.subscriptionrows[refid][2])
1cded8 2940         break;
T 2941
24053e 2942     var refrow, form;
T 2943     var tbody = this.gui_objects.subscriptionlist.tBodies[0];
e8a89e 2944     var id = 'rcmrow'+(tbody.childNodes.length+1);
1f064b 2945     var selection = this.subscription_list.get_single_selection();
e8a89e 2946     
T 2947     if (replace && replace.id)
2948     {
2949       id = replace.id;
2950       refid = replace.id;
2951     }
24053e 2952
T 2953     if (!id || !(refrow = document.getElementById(refid)))
2954       {
2955       // Refresh page if we don't have a table row to clone
6b47de 2956       this.goto_url('folders');
24053e 2957       }
T 2958     else
2959       {
2960       // clone a table row if there are existing rows
2961       var row = this.clone_table_row(refrow);
68b6a9 2962       row.id = id;
681a59 2963
A 2964       if (before && (before = this.get_folder_row_id(before)))
2965     tbody.insertBefore(row, document.getElementById(before));
24053e 2966       else
681a59 2967         tbody.appendChild(row);      
A 2968       
2969       if (replace)
2970     tbody.removeChild(replace);
24053e 2971       }
681a59 2972
24053e 2973     // add to folder/row-ID map
681a59 2974     this.env.subscriptionrows[row.id] = [name, display_name, 0];
24053e 2975
T 2976     // set folder name
4d4264 2977     row.cells[0].innerHTML = display_name;
e8a89e 2978     
T 2979     // set messages count to zero
2980     if (!replace)
2981       row.cells[1].innerHTML = '*';
2982     
2983     if (!replace && row.cells[2] && row.cells[2].firstChild.tagName=='INPUT')
24053e 2984       {
e8a89e 2985       row.cells[2].firstChild.value = name;
T 2986       row.cells[2].firstChild.checked = true;
24053e 2987       }
e8a89e 2988     
24053e 2989     // add new folder to rename-folder list and clear input field
f9c107 2990     if (!replace && (form = this.gui_objects.editform))
24053e 2991       {
f9c107 2992       if (form.elements['_folder_oldname'])
T 2993         form.elements['_folder_oldname'].options[form.elements['_folder_oldname'].options.length] = new Option(name,name);
2994       if (form.elements['_folder_name'])
2995         form.elements['_folder_name'].value = ''; 
24053e 2996       }
T 2997
b0dbf3 2998     this.init_subscription_list();
b119e2 2999     if (selection && document.getElementById('rcmrow'+selection))
1f064b 3000       this.subscription_list.select_row(selection);
b0dbf3 3001
68b6a9 3002     if (document.getElementById(id).scrollIntoView)
S 3003       document.getElementById(id).scrollIntoView();
24053e 3004     };
T 3005
3006
3007   // replace an existing table row with a new folder line
681a59 3008   this.replace_folder_row = function(oldfolder, newfolder, display_name, before)
24053e 3009     {
T 3010     var id = this.get_folder_row_id(oldfolder);
3011     var row = document.getElementById(id);
3012     
3013     // replace an existing table row (if found)
681a59 3014     this.add_folder_row(newfolder, display_name, row, before);
24053e 3015     
T 3016     // rename folder in rename-folder dropdown
3017     var form, elm;
3018     if ((form = this.gui_objects.editform) && (elm = form.elements['_folder_oldname']))
3019       {
3020       for (var i=0;i<elm.options.length;i++)
3021         {
3022         if (elm.options[i].value == oldfolder)
3023           {
4d4264 3024           elm.options[i].text = display_name;
24053e 3025           elm.options[i].value = newfolder;
T 3026           break;
3027           }
3028         }
3029
3030       form.elements['_folder_newname'].value = '';
3031       }
3032     };
681a59 3033
24053e 3034
T 3035   // remove the table row of a specific mailbox from the table
3036   // (the row will not be removed, just hidden)
3037   this.remove_folder_row = function(folder)
3038     {
1cded8 3039     var row;
24053e 3040     var id = this.get_folder_row_id(folder);
1cded8 3041     if (id && (row = document.getElementById(id)))
681a59 3042       row.style.display = 'none';
c8c1e0 3043
S 3044     // remove folder from rename-folder list
3045     var form;
3046     if ((form = this.gui_objects.editform) && form.elements['_folder_oldname'])
3047       {
3048       for (var i=0;i<form.elements['_folder_oldname'].options.length;i++)
3049         {
3050         if (form.elements['_folder_oldname'].options[i].value == folder) 
24053e 3051           {
c8c1e0 3052           form.elements['_folder_oldname'].options[i] = null;
24053e 3053           break;
c8c1e0 3054           }
S 3055         }
3056       }
24053e 3057     
f9c107 3058     if (form && form.elements['_folder_newname'])
T 3059       form.elements['_folder_newname'].value = '';
4e17e6 3060     };
T 3061
3062
3063   this.subscribe_folder = function(folder)
3064     {
c5097c 3065     if (folder)
A 3066       this.http_post('subscribe', '_mbox='+urlencode(folder));
4e17e6 3067     };
T 3068
3069
3070   this.unsubscribe_folder = function(folder)
3071     {
c5097c 3072     if (folder)
A 3073       this.http_post('unsubscribe', '_mbox='+urlencode(folder));
4e17e6 3074     };
T 3075     
3076
24053e 3077   // helper method to find a specific mailbox row ID
T 3078   this.get_folder_row_id = function(folder)
3079     {
3080     for (var id in this.env.subscriptionrows)
4d4264 3081       if (this.env.subscriptionrows[id] && this.env.subscriptionrows[id][0] == folder)
24053e 3082         break;
T 3083         
3084     return id;
3085     };
4e17e6 3086
T 3087   // duplicate a specific table row
3088   this.clone_table_row = function(row)
3089     {
3090     var cell, td;
3091     var new_row = document.createElement('TR');
3092     for(var n=0; n<row.childNodes.length; n++)
3093       {
3094       cell = row.childNodes[n];
3095       td = document.createElement('TD');
3096
3097       if (cell.className)
3098         td.className = cell.className;
3099       if (cell.align)
3100         td.setAttribute('align', cell.align);
3101         
3102       td.innerHTML = cell.innerHTML;
3103       new_row.appendChild(td);
3104       }
3105     
3106     return new_row;
9bebdf 3107     };
S 3108
4e17e6 3109
T 3110   /*********************************************************/
3111   /*********           GUI functionality           *********/
3112   /*********************************************************/
3113
3114
3115   // eable/disable buttons for page shifting
3116   this.set_page_buttons = function()
3117     {
3118     this.enable_command('nextpage', (this.env.pagecount > this.env.current_page));
d17008 3119     this.enable_command('lastpage', (this.env.pagecount > this.env.current_page));
4e17e6 3120     this.enable_command('previouspage', (this.env.current_page > 1));
d17008 3121     this.enable_command('firstpage', (this.env.current_page > 1));
4e17e6 3122     }
T 3123
3124
3125   // set button to a specific state
3126   this.set_button = function(command, state)
3127     {
3128     var a_buttons = this.buttons[command];
3129     var button, obj;
3130
3131     if(!a_buttons || !a_buttons.length)
4da1d7 3132       return false;
4e17e6 3133
T 3134     for(var n=0; n<a_buttons.length; n++)
3135       {
3136       button = a_buttons[n];
3137       obj = document.getElementById(button.id);
3138
3139       // get default/passive setting of the button
104ee3 3140       if (obj && button.type=='image' && !button.status) {
4e17e6 3141         button.pas = obj._original_src ? obj._original_src : obj.src;
104ee3 3142         // respect PNG fix on IE browsers
T 3143         if (obj.runtimeStyle && obj.runtimeStyle.filter && obj.runtimeStyle.filter.match(/src=['"]([^'"]+)['"]/))
3144           button.pas = RegExp.$1;
3145       }
4e17e6 3146       else if (obj && !button.status)
T 3147         button.pas = String(obj.className);
3148
3149       // set image according to button state
3150       if (obj && button.type=='image' && button[state])
3151         {
3152         button.status = state;        
3153         obj.src = button[state];
3154         }
3155       // set class name according to button state
3156       else if (obj && typeof(button[state])!='undefined')
3157         {
3158         button.status = state;        
3159         obj.className = button[state];        
3160         }
3161       // disable/enable input buttons
3162       if (obj && button.type=='input')
3163         {
3164         button.status = state;
3165         obj.disabled = !state;
3166         }
3167       }
3168     };
3169
eb6842 3170   // display a specific alttext
T 3171   this.set_alttext = function(command, label)
3172     {
3173       if (!this.buttons[command] || !this.buttons[command].length)
3174         return;
3175       
3176       var button, obj, link;
3177       for (var n=0; n<this.buttons[command].length; n++)
3178       {
3179         button = this.buttons[command][n];
3180         obj = document.getElementById(button.id);
3181         
3182         if (button.type=='image' && obj)
3183         {
3184           obj.setAttribute('alt', this.get_label(label));
3185           if ((link = obj.parentNode) && link.tagName == 'A')
3186             link.setAttribute('title', this.get_label(label));
3187         }
3188         else if (obj)
3189           obj.setAttribute('title', this.get_label(label));
3190       }
3191     };
4e17e6 3192
T 3193   // mouse over button
3194   this.button_over = function(command, id)
3195     {
3196     var a_buttons = this.buttons[command];
3197     var button, img;
3198
3199     if(!a_buttons || !a_buttons.length)
4da1d7 3200       return false;
4e17e6 3201
T 3202     for(var n=0; n<a_buttons.length; n++)
3203       {
3204       button = a_buttons[n];
3205       if(button.id==id && button.status=='act')
3206         {
3207         img = document.getElementById(button.id);
3208         if (img && button.over)
3209           img.src = button.over;
3210         }
3211       }
4da1d7 3212       
4e17e6 3213     };
T 3214
c8c1e0 3215   // mouse down on button
S 3216   this.button_sel = function(command, id)
3217     {
3218     var a_buttons = this.buttons[command];
3219     var button, img;
3220
3221     if(!a_buttons || !a_buttons.length)
3222       return;
3223
3224     for(var n=0; n<a_buttons.length; n++)
3225       {
3226       button = a_buttons[n];
3227       if(button.id==id && button.status=='act')
3228         {
3229         img = document.getElementById(button.id);
3230         if (img && button.sel)
3231           img.src = button.sel;
3232         }
3233       }
3234     };
4e17e6 3235
T 3236   // mouse out of button
3237   this.button_out = function(command, id)
3238     {
3239     var a_buttons = this.buttons[command];
3240     var button, img;
3241
3242     if(!a_buttons || !a_buttons.length)
3243       return;
3244
3245     for(var n=0; n<a_buttons.length; n++)
3246       {
3247       button = a_buttons[n];
3248       if(button.id==id && button.status=='act')
3249         {
3250         img = document.getElementById(button.id);
3251         if (img && button.act)
3252           img.src = button.act;
3253         }
3254       }
3255     };
3256
3257
3258   // set/unset a specific class name
3259   this.set_classname = function(obj, classname, set)
3260     {
3261     var reg = new RegExp('\s*'+classname, 'i');
3262     if (!set && obj.className.match(reg))
3263       obj.className = obj.className.replace(reg, '');
3264     else if (set && !obj.className.match(reg))
3265       obj.className += ' '+classname;
3266     };
3267
3268
5eee00 3269   // write to the document/window title
T 3270   this.set_pagetitle = function(title)
3271   {
3272     if (title && document.title)
3273       document.title = title;
3274   }
3275
3276
4e17e6 3277   // display a system message
T 3278   this.display_message = function(msg, type, hold)
3279     {
3280     if (!this.loaded)  // save message in order to display after page loaded
3281       {
3282       this.pending_message = new Array(msg, type);
3283       return true;
3284       }
b716bd 3285
T 3286     // pass command to parent window
3287     if (this.env.framed && parent.rcmail)
3288       return parent.rcmail.display_message(msg, type, hold);
3289
4e17e6 3290     if (!this.gui_objects.message)
T 3291       return false;
f9c107 3292
4e17e6 3293     if (this.message_timer)
T 3294       clearTimeout(this.message_timer);
3295     
3296     var cont = msg;
3297     if (type)
3298       cont = '<div class="'+type+'">'+cont+'</div>';
a95e0e 3299
b716bd 3300     var _rcube = this;
4e17e6 3301     this.gui_objects.message.innerHTML = cont;
T 3302     this.gui_objects.message.style.display = 'block';
b716bd 3303     
a95e0e 3304     if (type!='loading')
b716bd 3305       this.gui_objects.message.onmousedown = function(){ _rcube.hide_message(); return true; };
4e17e6 3306     
T 3307     if (!hold)
dbbd1f 3308       this.message_timer = window.setTimeout(function(){ ref.hide_message(); }, this.message_time);
4e17e6 3309     };
T 3310
3311
3312   // make a message row disapear
3313   this.hide_message = function()
3314     {
3315     if (this.gui_objects.message)
a95e0e 3316       {
4e17e6 3317       this.gui_objects.message.style.display = 'none';
a95e0e 3318       this.gui_objects.message.onmousedown = null;
T 3319       }
4e17e6 3320     };
T 3321
3322
3323   // mark a mailbox as selected and set environment variable
f11541 3324   this.select_folder = function(name, old)
T 3325   {
3326     if (this.gui_objects.folderlist)
4e17e6 3327     {
f11541 3328       var current_li, target_li;
597170 3329       
f11541 3330       if ((current_li = this.get_folder_li(old)))
T 3331       {
6a35c8 3332         this.set_classname(current_li, 'selected', false);
952860 3333         this.set_classname(current_li, 'unfocused', false);
4e17e6 3334       }
6b47de 3335
f11541 3336       if ((target_li = this.get_folder_li(name)))
fa4cd2 3337       {
f11541 3338         this.set_classname(target_li, 'unfocused', false);
T 3339         this.set_classname(target_li, 'selected', true);
fa4cd2 3340       }
f11541 3341     }
T 3342   };
3343
3344   // helper method to find a folder list item
3345   this.get_folder_li = function(name)
3346   {
3347     if (this.gui_objects.folderlist)
3348     {
3349       name = String(name).replace(this.identifier_expr, '');
3350       return document.getElementById('rcmli'+name);
3351     }
3352
3353     return null;
3354   };
4e17e6 3355
24053e 3356
25d8ba 3357   // for reordering column array, Konqueror workaround
S 3358   this.set_message_coltypes = function(coltypes) 
3359   { 
24053e 3360     this.coltypes = coltypes;
T 3361     
3362     // set correct list titles
3363     var cell, col;
3364     var thead = this.gui_objects.messagelist ? this.gui_objects.messagelist.tHead : null;
3365     for (var n=0; thead && n<this.coltypes.length; n++) 
3366       {
3367       col = this.coltypes[n];
3368       if ((cell = thead.rows[0].cells[n+1]) && (col=='from' || col=='to'))
3369         {
3370         // if we have links for sorting, it's a bit more complicated...
3371         if (cell.firstChild && cell.firstChild.tagName=='A')
3372           {
3373           cell.firstChild.innerHTML = this.get_label(this.coltypes[n]);
3374           cell.firstChild.onclick = function(){ return rcmail.command('sort', this.__col, this); };
3375           cell.firstChild.__col = col;
3376           }
3377         else
3378           cell.innerHTML = this.get_label(this.coltypes[n]);
3379
3380         cell.id = 'rcmHead'+col;
3381         }
e189a6 3382       else if (col == 'subject' && this.message_list)
d24d20 3383         this.message_list.subject_col = n+1;
e189a6 3384       else if (col == 'flag' && this.env.unflaggedicon)
A 3385         {
3386       cell.innerHTML = '<img src="'+this.env.unflaggedicon+'" alt="" />';
3387     }
24053e 3388       }
T 3389   };
4e17e6 3390
T 3391   // create a table row in the message list
15a9d1 3392   this.add_message_row = function(uid, cols, flags, attachment, attop)
4e17e6 3393     {
6b47de 3394     if (!this.gui_objects.messagelist || !this.message_list)
4e17e6 3395       return false;
6b47de 3396
4e17e6 3397     var tbody = this.gui_objects.messagelist.tBodies[0];
T 3398     var rowcount = tbody.rows.length;
3399     var even = rowcount%2;
3400     
857a38 3401     this.env.messages[uid] = {deleted:flags.deleted?1:0,
S 3402                               replied:flags.replied?1:0,
e189a6 3403                               unread:flags.unread?1:0,
A 3404                               flagged:flags.flagged?1:0};
4e17e6 3405     
T 3406     var row = document.createElement('TR');
3407     row.id = 'rcmrow'+uid;
15a9d1 3408     row.className = 'message '+(even ? 'even' : 'odd')+(flags.unread ? ' unread' : '')+(flags.deleted ? ' deleted' : '');
6b47de 3409
T 3410     if (this.message_list.in_selection(uid))
4e17e6 3411       row.className += ' selected';
T 3412
857a38 3413     var icon = flags.deleted && this.env.deletedicon ? this.env.deletedicon:
S 3414                (flags.unread && this.env.unreadicon ? this.env.unreadicon :
3415                (flags.replied && this.env.repliedicon ? this.env.repliedicon : this.env.messageicon));
4e17e6 3416
T 3417     var col = document.createElement('TD');
3418     col.className = 'icon';
e189a6 3419     col.innerHTML = icon ? '<img src="'+icon+'" alt="" />' : '';
4e17e6 3420     row.appendChild(col);
T 3421
3422     // add each submitted col
25d8ba 3423     for (var n = 0; n < this.coltypes.length; n++) 
S 3424       { 
3425       var c = this.coltypes[n];
4e17e6 3426       col = document.createElement('TD');
T 3427       col.className = String(c).toLowerCase();
e189a6 3428       
A 3429       if (c=='flag')
3430         {
3431         if (flags.flagged && this.env.flaggedicon)
3432           col.innerHTML = '<img src="'+this.env.flaggedicon+'" alt="" />';
3433         else if(this.env.unflaggedicon)
3434           col.innerHTML = '<img src="'+this.env.unflaggedicon+'" alt="" />';
3435     }
3436       else
3437         col.innerHTML = cols[c];
3438
4e17e6 3439       row.appendChild(col);
T 3440       }
3441
3442     col = document.createElement('TD');
3443     col.className = 'icon';
e189a6 3444     col.innerHTML = attachment && this.env.attachmenticon ? '<img src="'+this.env.attachmenticon+'" alt="" />' : '';
4e17e6 3445     row.appendChild(col);
6b47de 3446
T 3447     this.message_list.insert_row(row, attop);
4e17e6 3448     };
T 3449
3450
3451   // replace content of row count display
3452   this.set_rowcount = function(text)
3453     {
3454     if (this.gui_objects.countdisplay)
3455       this.gui_objects.countdisplay.innerHTML = text;
3456
3457     // update page navigation buttons
3458     this.set_page_buttons();
3459     };
3460
6d2714 3461
ac5d15 3462   // replace content of mailboxname display
T 3463   this.set_mailboxname = function(content)
3464     {
3465     if (this.gui_objects.mailboxname && content)
3466       this.gui_objects.mailboxname.innerHTML = content;
3467     };
3468
58e360 3469   // replace content of quota display
6d2714 3470   this.set_quota = function(content)
f11541 3471     {
6d2714 3472     if (this.gui_objects.quotadisplay && content)
A 3473       this.gui_objects.quotadisplay.innerHTML = content;
3474     };
6b47de 3475
4e17e6 3476
T 3477   // update the mailboxlist
15a9d1 3478   this.set_unread_count = function(mbox, count, set_title)
4e17e6 3479     {
T 3480     if (!this.gui_objects.mailboxlist)
3481       return false;
25d8ba 3482
ce102f 3483     var reg, text_obj, item;
T 3484     if (item = this.get_folder_li(mbox))
4e17e6 3485       {
7f9d71 3486       item.setAttribute('count', count);
S 3487       this.set_unread_count_display(mbox, set_title);
3488       }
3489     }
3490
3491
3492   // update the mailbox count display
3493   this.set_unread_count_display = function(mbox, set_title)
3494     {
cca626 3495     var reg, text_obj, item, mycount, childcount, div, children;
7f9d71 3496     if (item = this.get_folder_li(mbox))
S 3497       {
cca626 3498       mycount = parseInt(item.getAttribute('count') ? item.getAttribute('count') : 0);
acbc48 3499       text_obj = item.getElementsByTagName('a')[0];
15a9d1 3500       reg = /\s+\([0-9]+\)$/i;
7f9d71 3501
S 3502       div = item.getElementsByTagName('div')[0];
cca626 3503       childcount = 0;
7f9d71 3504       if (div.className.match(/collapsed/))
S 3505         {
3506         // add children's counters
3507         children = item.getElementsByTagName('li');
3508         for (var i=0; i<children.length; i++)
cca626 3509           childcount = childcount+parseInt(children[i].getAttribute('count') ? children[i].getAttribute('count') : 0);
7f9d71 3510         }
4e17e6 3511
cca626 3512       if (mycount && text_obj.innerHTML.match(reg))
S 3513         text_obj.innerHTML = text_obj.innerHTML.replace(reg, ' ('+mycount+')');
3514       else if (mycount)
3515         text_obj.innerHTML += ' ('+mycount+')';
15a9d1 3516       else
T 3517         text_obj.innerHTML = text_obj.innerHTML.replace(reg, '');
25d8ba 3518
7f9d71 3519       // set parent's display
S 3520       reg = new RegExp(RegExp.escape(this.env.delimiter) + '[^' + RegExp.escape(this.env.delimiter) + ']+');
3521       if (mbox.match(reg))
3522         this.set_unread_count_display(mbox.replace(reg, ''), false);
3523
15a9d1 3524       // set the right classes
cca626 3525       this.set_classname(item, 'unread', (mycount+childcount)>0 ? true : false);
15a9d1 3526       }
T 3527
3528     // set unread count to window title
01c86f 3529     reg = /^\([0-9]+\)\s+/i;
25d8ba 3530     if (set_title && document.title)
15a9d1 3531       {
T 3532       var doc_title = String(document.title);
5eee00 3533       var new_title = "";
15a9d1 3534
T 3535       if (count && doc_title.match(reg))
5eee00 3536         new_title = doc_title.replace(reg, '('+count+') ');
15a9d1 3537       else if (count)
5eee00 3538         new_title = '('+count+') '+doc_title;
15a9d1 3539       else
5eee00 3540         new_title = doc_title.replace(reg, '');
T 3541         
3542       this.set_pagetitle(new_title);
01c86f 3543       }
4e17e6 3544     };
T 3545
6d2714 3546   // update parent's mailboxlist (from preview)
A 3547   this.set_unread_count_from_preview = function(mbox, count, set_title)
3548   {
3549     parent.rcmail.set_unread_count(mbox, count, set_title);
3550   }
3551   
4e17e6 3552   // add row to contacts list
6b47de 3553   this.add_contact_row = function(cid, cols, select)
4e17e6 3554     {
T 3555     if (!this.gui_objects.contactslist || !this.gui_objects.contactslist.tBodies[0])
3556       return false;
3557     
3558     var tbody = this.gui_objects.contactslist.tBodies[0];
3559     var rowcount = tbody.rows.length;
3560     var even = rowcount%2;
3561     
3562     var row = document.createElement('TR');
3563     row.id = 'rcmrow'+cid;
3564     row.className = 'contact '+(even ? 'even' : 'odd');
3565     
6b47de 3566     if (this.contact_list.in_selection(cid))
4e17e6 3567       row.className += ' selected';
T 3568
3569     // add each submitted col
3570     for (var c in cols)
3571       {
3572       col = document.createElement('TD');
3573       col.className = String(c).toLowerCase();
3574       col.innerHTML = cols[c];
3575       row.appendChild(col);
3576       }
3577     
6b47de 3578     this.contact_list.insert_row(row);
4e17e6 3579     };
T 3580
3581
d9344f 3582   this.toggle_editor = function(checkbox, textAreaId)
a0109c 3583     {
S 3584     var ischecked = checkbox.checked;
3585     if (ischecked)
3586       {
d9344f 3587         tinyMCE.execCommand('mceAddControl', true, textAreaId);
a0109c 3588       }
S 3589     else
3590       {
d9344f 3591         tinyMCE.execCommand('mceRemoveControl', true, textAreaId);
a0109c 3592       }
4e17e6 3593     };
T 3594
3595
712b30 3596   this.toggle_prefer_html = function(checkbox)
A 3597     {
3598     var addrbook_show_images;
3599     if (addrbook_show_images = document.getElementById('rcmfd_addrbook_show_images'))
3600       addrbook_show_images.disabled = !checkbox.checked;
3601     }
3602
3603
4e17e6 3604
T 3605   /********************************************************/
3606   /*********        remote request methods        *********/
3607   /********************************************************/
6b47de 3608
4b9efb 3609   this.redirect = function(url, lock)
f11541 3610     {
719a25 3611     if (lock || lock === null)
4b9efb 3612       this.set_busy(true);
S 3613
f11541 3614     if (this.env.framed && window.parent)
T 3615       parent.location.href = url;
3616     else  
3617       location.href = url;
3618     };
6b47de 3619
T 3620   this.goto_url = function(action, query, lock)
3621     {
3622     var querystring = query ? '&'+query : '';
4b9efb 3623     this.redirect(this.env.comm_path+'&_action='+action+querystring, lock);
6b47de 3624     };
4e17e6 3625
T 3626
ecf759 3627   this.http_sockets = new Array();
T 3628   
3629   // find a non-busy socket or create a new one
3630   this.get_request_obj = function()
4e17e6 3631     {
ecf759 3632     for (var n=0; n<this.http_sockets.length; n++)
4e17e6 3633       {
ecf759 3634       if (!this.http_sockets[n].busy)
T 3635         return this.http_sockets[n];
4e17e6 3636       }
ecf759 3637     
T 3638     // create a new XMLHTTP object
3639     var i = this.http_sockets.length;
3640     this.http_sockets[i] = new rcube_http_request();
4e17e6 3641
ecf759 3642     return this.http_sockets[i];
T 3643     };
3644   
3645
3646   // send a http request to the server
3647   this.http_request = function(action, querystring, lock)
3648     {
3649     var request_obj = this.get_request_obj();
b19097 3650     querystring += (querystring ? '&' : '') + '_remote=1';
4e17e6 3651     
T 3652     // add timestamp to request url to avoid cacheing problems in Safari
3653     if (bw.safari)
3654       querystring += '&_ts='+(new Date().getTime());
3655
3656     // send request
ecf759 3657     if (request_obj)
4e17e6 3658       {
f11541 3659       console.log('HTTP request: '+this.env.comm_path+'&_action='+action+'&'+querystring);
ecf759 3660
T 3661       if (lock)
3662         this.set_busy(true);
3663
f11541 3664       var rcm = this;
ecf759 3665       request_obj.__lock = lock ? true : false;
T 3666       request_obj.__action = action;
86958f 3667       request_obj.onerror = function(o){ ref.http_error(o); };
T 3668       request_obj.oncomplete = function(o){ ref.http_response(o); };
4d4264 3669       request_obj.GET(this.env.comm_path+'&_action='+action+'&'+querystring);
4e17e6 3670       }
T 3671     };
3672
f11541 3673     // send a http POST request to the server
T 3674     this.http_post = function(action, postdata, lock)
3675       {
3676       var request_obj;
3677       if (postdata && typeof(postdata) == 'object')
3678         postdata._remote = 1;
3679       else
3680         postdata += (postdata ? '&' : '') + '_remote=1';
3681
3682       // send request
3683       if (request_obj = this.get_request_obj())
3684         {
3685         console.log('HTTP POST: '+this.env.comm_path+'&_action='+action);
3686
3687         if (lock)
3688           this.set_busy(true);
3689
3690         var rcm = this;
3691         request_obj.__lock = lock ? true : false;
3692         request_obj.__action = action;
3693         request_obj.onerror = function(o){ rcm.http_error(o); };
3694         request_obj.oncomplete = function(o){ rcm.http_response(o); };
3695         request_obj.POST(this.env.comm_path+'&_action='+action, postdata);
3696         }
3697       };
4e17e6 3698
ecf759 3699   // handle HTTP response
T 3700   this.http_response = function(request_obj)
4e17e6 3701     {
ecf759 3702     var ctype = request_obj.get_header('Content-Type');
e1cf7c 3703     if (ctype){
ecf759 3704       ctype = String(ctype).toLowerCase();
e1cf7c 3705       var ctype_array=ctype.split(";");
S 3706       ctype = ctype_array[0];
3707     }
4e17e6 3708
5eee00 3709     if (request_obj.__lock)
T 3710         this.set_busy(false);
4e17e6 3711
f11541 3712     console.log(request_obj.get_text());
4e17e6 3713
ecf759 3714     // if we get javascript code from server -> execute it
c03095 3715     if (request_obj.get_text() && (ctype=='text/javascript' || ctype=='application/x-javascript'))
T 3716       eval(request_obj.get_text());
4e17e6 3717
ecf759 3718     // process the response data according to the sent action
T 3719     switch (request_obj.__action)
3720       {
d41d67 3721
ecf759 3722       case 'delete':
f74b28 3723     if (this.task == 'addressbook')
A 3724       {
3725         var uid = this.contact_list.get_selection();
3726         this.enable_command('compose', (uid && this.contact_list.rows[uid]));
3727         this.enable_command('delete', 'edit', (uid && this.contact_list.rows[uid] && this.env.address_sources && !this.env.address_sources[this.env.source].readonly));
3728         break;  
3729       }
ecf759 3730       case 'moveto':
T 3731         if (this.env.action=='show')
3732           this.command('list');
b19097 3733         else if (this.message_list)
T 3734           this.message_list.init();
f74b28 3735       
2eb032 3736       case 'purge':
3d3531 3737       case 'expunge':      
f74b28 3738     if (!this.env.messagecount && this.task == 'mail')
3d3531 3739           {
A 3740         // clear preview pane content
3741         if (this.env.contentframe)
3742           this.show_contentframe(false);
3743         // disable commands useless when mailbox is empty
3744         this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'delete', 'mark', 'viewsource',
3745           'print', 'load-attachment', 'purge', 'expunge', 'select-all', 'select-none', 'sort', false);
3746       }
3747     break;
d41d67 3748
ecf759 3749       case 'list':
3d3531 3750     this.msglist_select(this.message_list);
fdccdb 3751
d41d67 3752       case 'check-recent':
fdccdb 3753       case 'getunread':
f74b28 3754     if (this.task == 'mail')
A 3755     {
3756       this.enable_command('show', 'expunge', 'select-all', 'select-none', 'sort', (this.env.messagecount > 0));
3757       var mailboxtest = (this.env.mailbox == this.env.trash_mailbox || this.env.mailbox == this.env.junk_mailbox 
ddd776 3758         || this.env.mailbox.match('^' + RegExp.escape(this.env.trash_mailbox) + RegExp.escape(this.env.delimiter)) 
A 3759         || this.env.mailbox.match('^' + RegExp.escape(this.env.junk_mailbox) + RegExp.escape(this.env.delimiter))) ? true : false;
3760     
f74b28 3761       this.enable_command('purge', (this.env.messagecount && mailboxtest));
A 3762     }
3d3531 3763     break;
fdccdb 3764
4e17e6 3765       }
ecf759 3766
T 3767     request_obj.reset();
4e17e6 3768     };
ecf759 3769
T 3770
3771   // handle HTTP request errors
3772   this.http_error = function(request_obj)
3773     {
9a5261 3774     //alert('Error sending request: '+request_obj.url);
ecf759 3775
T 3776     if (request_obj.__lock)
3777       this.set_busy(false);
3778
3779     request_obj.reset();
3780     request_obj.__lock = false;
3781     };
3782
3783
3784   // use an image to send a keep-alive siganl to the server
3785   this.send_keep_alive = function()
3786     {
3787     var d = new Date();
3788     this.http_request('keep-alive', '_t='+d.getTime());
3789     };
15a9d1 3790
ecf759 3791     
15a9d1 3792   // send periodic request to check for recent messages
T 3793   this.check_for_recent = function()
3794     {
aade7b 3795     if (this.busy)
T 3796       return;
3797
c8c1e0 3798     this.set_busy(true, 'checkingmail');
110748 3799     this.http_request('check-recent', (this.env.search_request ? '_search='+this.env.search_request+'&' : '') + '_t='+(new Date().getTime()), true);
15a9d1 3800     };
4e17e6 3801
T 3802
3803   /********************************************************/
3804   /*********            helper methods            *********/
3805   /********************************************************/
3806   
3807   // check if we're in show mode or if we have a unique selection
3808   // and return the message uid
3809   this.get_single_uid = function()
3810     {
6b47de 3811     return this.env.uid ? this.env.uid : (this.message_list ? this.message_list.get_single_selection() : null);
4e17e6 3812     };
T 3813
3814   // same as above but for contacts
3815   this.get_single_cid = function()
3816     {
6b47de 3817     return this.env.cid ? this.env.cid : (this.contact_list ? this.contact_list.get_single_selection() : null);
4e17e6 3818     };
T 3819
3820
3821   this.get_caret_pos = function(obj)
3822     {
3823     if (typeof(obj.selectionEnd)!='undefined')
3824       return obj.selectionEnd;
3825
3826     else if (document.selection && document.selection.createRange)
3827       {
3828       var range = document.selection.createRange();
3829       if (range.parentElement()!=obj)
3830         return 0;
3831
3832       var gm = range.duplicate();
3833       if (obj.tagName=='TEXTAREA')
3834         gm.moveToElementText(obj);
3835       else
3836         gm.expand('textedit');
3837       
3838       gm.setEndPoint('EndToStart', range);
3839       var p = gm.text.length;
3840
3841       return p<=obj.value.length ? p : -1;
3842       }
3843
3844     else
3845       return obj.value.length;
3846     };
3847
3848
3849   this.set_caret2start = function(obj)
3850     {
3851     if (obj.createTextRange)
3852       {
3853       var range = obj.createTextRange();
3854       range.collapse(true);
3855       range.select();
3856       }
3857     else if (obj.setSelectionRange)
3858       obj.setSelectionRange(0,0);
3859
3860     obj.focus();
3861     };
3862
3863
3864   // set all fields of a form disabled
3865   this.lock_form = function(form, lock)
3866     {
3867     if (!form || !form.elements)
3868       return;
3869     
3870     var type;
3871     for (var n=0; n<form.elements.length; n++)
3872       {
3873       type = form.elements[n];
3874       if (type=='hidden')
3875         continue;
3876         
3877       form.elements[n].disabled = lock;
3878       }
3879     };
3880     
3881   }  // end object rcube_webmail
3882
3883
3884
6b47de 3885 /**
T 3886  * Class for sending HTTP requests
3887  * @constructor
3888  */
ecf759 3889 function rcube_http_request()
T 3890   {
3891   this.url = '';
3892   this.busy = false;
3893   this.xmlhttp = null;
3894
3895
3896   // reset object properties
3897   this.reset = function()
3898     {
3899     // set unassigned event handlers
3900     this.onloading = function(){ };
3901     this.onloaded = function(){ };
3902     this.oninteractive = function(){ };
3903     this.oncomplete = function(){ };
3904     this.onabort = function(){ };
3905     this.onerror = function(){ };
3906     
3907     this.url = '';
3908     this.busy = false;
3909     this.xmlhttp = null;
3910     }
3911
3912
3913   // create HTMLHTTP object
3914   this.build = function()
3915     {
3916     if (window.XMLHttpRequest)
3917       this.xmlhttp = new XMLHttpRequest();
3918     else if (window.ActiveXObject)
f11541 3919       {
T 3920       try { this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
3921       catch(e) { this.xmlhttp = null; }
3922       }
ecf759 3923     else
T 3924       {
3925       
3926       }
3927     }
3928
a0109c 3929   // send GET request
ecf759 3930   this.GET = function(url)
T 3931     {
3932     this.build();
3933
3934     if (!this.xmlhttp)
3935       {
3936       this.onerror(this);
3937       return false;
3938       }
3939
719a25 3940     var _ref = this;
ecf759 3941     this.url = url;
T 3942     this.busy = true;
3943
719a25 3944     this.xmlhttp.onreadystatechange = function(){ _ref.xmlhttp_onreadystatechange(); };
ecf759 3945     this.xmlhttp.open('GET', url);
234c0d 3946     this.xmlhttp.setRequestHeader('X-RoundCube-Referer', bw.get_cookie('roundcube_sessid'));
ecf759 3947     this.xmlhttp.send(null);
T 3948     };
3949
3950
a0109c 3951   this.POST = function(url, body, contentType)
ecf759 3952     {
a0109c 3953     // default value for contentType if not provided
f11541 3954     if (typeof(contentType) == 'undefined')
T 3955       contentType = 'application/x-www-form-urlencoded';
a0109c 3956
S 3957     this.build();
3958     
3959     if (!this.xmlhttp)
3960     {
3961        this.onerror(this);
3962        return false;
3963     }
f11541 3964     
T 3965     var req_body = body;
3966     if (typeof(body) == 'object')
3967     {
3968       req_body = '';
3969       for (var p in body)
3970         req_body += (req_body ? '&' : '') + p+'='+urlencode(body[p]);
3971     }
a0109c 3972
f11541 3973     var ref = this;
a0109c 3974     this.url = url;
S 3975     this.busy = true;
3976     
3977     this.xmlhttp.onreadystatechange = function() { ref.xmlhttp_onreadystatechange(); };
3978     this.xmlhttp.open('POST', url, true);
3979     this.xmlhttp.setRequestHeader('Content-Type', contentType);
234c0d 3980     this.xmlhttp.setRequestHeader('X-RoundCube-Referer', bw.get_cookie('roundcube_sessid'));
f11541 3981     this.xmlhttp.send(req_body);
ecf759 3982     };
T 3983
3984
3985   // handle onreadystatechange event
3986   this.xmlhttp_onreadystatechange = function()
3987     {
3988     if(this.xmlhttp.readyState == 1)
3989       this.onloading(this);
3990
3991     else if(this.xmlhttp.readyState == 2)
3992       this.onloaded(this);
3993
3994     else if(this.xmlhttp.readyState == 3)
3995       this.oninteractive(this);
3996
3997     else if(this.xmlhttp.readyState == 4)
3998       {
9a5261 3999       try {
T 4000         if (this.xmlhttp.status == 0)
4001           this.onabort(this);
4002         else if(this.xmlhttp.status == 200)
4003           this.oncomplete(this);
4004         else
4005           this.onerror(this);
4006
4007         this.busy = false;
4008         }
4009       catch(err)
4010         {
ecf759 4011         this.onerror(this);
9a5261 4012         this.busy = false;
T 4013         }
ecf759 4014       }
T 4015     }
4016
4017   // getter method for HTTP headers
4018   this.get_header = function(name)
4019     {
4020     return this.xmlhttp.getResponseHeader(name);
4021     };
4022
c03095 4023   this.get_text = function()
T 4024     {
4025     return this.xmlhttp.responseText;
4026     };
4027
4028   this.get_xml = function()
4029     {
4030     return this.xmlhttp.responseXML;
4031     };
ecf759 4032
T 4033   this.reset();
4034   
4035   }  // end class rcube_http_request
4036
4037
e170b4 4038 // helper function to call the init method with a delay
T 4039 function call_init(o)
4040   {
dbbd1f 4041     window.setTimeout('if (window[\''+o+'\'] && window[\''+o+'\'].init) { '+o+'.init(); }',
S 4042                       bw.win ? 500 : 200);
4e17e6 4043   }
T 4044