From fdccdb4afee82fe8ac4d2853ab806f4a7f90d13d Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Wed, 02 Apr 2008 15:48:27 -0400
Subject: [PATCH] fixed r1237 commit

---
 program/js/app.js |  372 +++++++++++++++++++++++++++-------------------------
 1 files changed, 195 insertions(+), 177 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index f3b47df..94b329d 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -3,7 +3,7 @@
  | RoundCube Webmail Client Script                                       |
  |                                                                       |
  | This file is part of the RoundCube Webmail client                     |
- | Copyright (C) 2005-2007, RoundCube Dev, - Switzerland                 |
+ | Copyright (C) 2005-2008, RoundCube Dev, - Switzerland                 |
  | Licensed under the GNU GPL                                            |
  |                                                                       |
  +-----------------------------------------------------------------------+
@@ -132,7 +132,7 @@
           this.message_list.addEventListener('dblclick', function(o){ p.msglist_dbl_click(o); });
           this.message_list.addEventListener('keypress', function(o){ p.msglist_keypress(o); });
           this.message_list.addEventListener('select', function(o){ p.msglist_select(o); });
-          this.message_list.addEventListener('dragstart', function(o){ p.drag_active = true; });
+          this.message_list.addEventListener('dragstart', function(o){ p.drag_active = true; if (p.preview_timer) clearTimeout(p.preview_timer); });
           this.message_list.addEventListener('dragend', function(o){ p.drag_active = false; });
 
           this.message_list.init();
@@ -146,13 +146,19 @@
           else
             this.message_list.focus();
           }
+          
+        if (this.env.coltypes)
+          this.set_message_coltypes(this.env.coltypes);
 
         // enable mail commands
         this.enable_command('list', 'checkmail', 'compose', 'add-contact', 'search', 'reset-search', true);
+
+        if (this.env.search_text != null && document.getElementById('quicksearchbox') != null)
+          document.getElementById('quicksearchbox').value = this.env.search_text;
         
         if (this.env.action=='show' || this.env.action=='preview')
           {
-          this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'delete', 'viewsource', 'print', 'load-attachment', true);
+          this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'delete', 'mark', 'viewsource', 'print', 'load-attachment', true);
           if (this.env.next_uid)
             {
             this.enable_command('nextmessage', true);
@@ -196,15 +202,18 @@
           }
 
         if (this.env.messagecount)
-          this.enable_command('select-all', 'select-none', 'sort', 'expunge', true);
+          this.enable_command('select-all', 'select-none', 'expunge', true);
 
         if (this.env.messagecount && (this.env.mailbox==this.env.trash_mailbox || this.env.mailbox==this.env.junk_mailbox))
           this.enable_command('purge', true);
 
         this.set_page_buttons();
 
-        // focus this window
-        window.focus();
+        // focus main window
+        if (this.env.framed && window.parent)
+          window.parent.focus();
+        else
+          window.focus();
 
         // init message compose form
         if (this.env.action=='compose')
@@ -219,6 +228,16 @@
         {
           this.gui_objects.folderlist = this.gui_objects.mailboxlist;
           this.http_request('getunread', '');
+        }
+        
+        // ask user to send MDN
+        if (this.env.mdn_request && this.env.uid)
+        {
+          var mdnurl = '_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox);
+          if (confirm(this.get_label('mdnrequest')))
+            this.http_post('sendmdn', mdnurl);
+          else
+            this.http_post('mark', mdnurl+'&_flag=mdnsent');
         }
 
         break;
@@ -292,10 +311,10 @@
         break;
 
       case 'login':
-        var input_user = rcube_find_object('_user');
-        var input_pass = rcube_find_object('_pass');
+        var input_user = rcube_find_object('rcmloginuser');
+        var input_pass = rcube_find_object('rcmloginpwd');
         if (input_user)
-          input_user.onkeypress = function(e){ return rcmail.login_user_keypress(e); };
+          input_user.onkeyup = function(e){ return rcmail.login_user_keyup(e); };
         if (input_user && input_user.value=='')
           input_user.focus();
         else if (input_pass)
@@ -484,7 +503,7 @@
       case 'list':
         if (this.task=='mail')
           {
-          if (this.env.search_request<0 || (this.env.search_request && props != this.env.mailbox))
+          if (this.env.search_request<0 || (props != '' && (this.env.search_request && props != this.env.mailbox)))
             this.reset_qsearch();
 
           this.list_mailbox(props);
@@ -660,7 +679,12 @@
         else if (this.task == 'addressbook' && this.drag_active)
           this.copy_contact(null, props);
         break;
-        
+
+      case 'mark':
+        if (props)
+          this.mark_message(props);
+        break;
+      
       case 'toggle_status':
         if (props && !props._row)
           break;
@@ -671,7 +695,7 @@
         if (props._row.uid)
           {
           uid = props._row.uid;
-          this.message_list.dont_select = true;
+          
           // toggle read/unread
           if (this.message_list.rows[uid].deleted) {
             flag = 'undelete';
@@ -688,7 +712,7 @@
         break;
 
       case 'load-attachment':
-        var qstring = '_mbox='+this.env.mailbox+'&_uid='+this.env.uid+'&_part='+props.part;
+        var qstring = '_mbox='+urlencode(this.env.mailbox)+'&_uid='+this.env.uid+'&_part='+props.part;
         
         // open attachment in frame if it's of a supported mimetype
         if (this.env.uid && props.mimetype && find_in_array(props.mimetype, this.mimetypes)>=0)
@@ -817,7 +841,7 @@
 
         if (!this.check_compose_input())
           break;
-          
+
         // Reset the auto-save timer
         self.clearTimeout(this.save_timer);
 
@@ -862,11 +886,15 @@
       case 'print':
         var uid;
         if (uid = this.get_single_uid())
-          {
+        {
           ref.printwin = window.open(this.env.comm_path+'&_action=print&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)+(this.env.safemode ? '&_safe=1' : ''));
           if (this.printwin)
+          {
             setTimeout(function(){ ref.printwin.focus(); }, 20);
+            if (this.env.action != 'show')
+              this.toggle_read_status('read', [uid]);
           }
+        }
         break;
 
       case 'viewsource':
@@ -938,8 +966,7 @@
         break;
 
       case 'delete-folder':
-        if (confirm(this.get_label('deletefolderconfirm')))
-          this.delete_folder(props);
+        this.delete_folder(props);
         break;
 
       }
@@ -1073,10 +1100,6 @@
       this.unfocus_folder(id);
       this.command('moveto', id);
       }
-
-    // Hide message command buttons until a message is selected 
-    this.enable_command('reply', 'reply-all', 'forward', 'delete', 'print', false); 
-    return false;
     };
 
   this.click_on_list = function(e)
@@ -1106,16 +1129,16 @@
       {
       this.enable_command('reply', 'reply-all', 'forward', false);
       this.enable_command('show', selected);
-      this.enable_command('delete', 'moveto', (list.selection.length > 0 ? true : false));
+      this.enable_command('delete', 'moveto', 'mark', (list.selection.length > 0 ? true : false));
       }
     else
       {
       this.enable_command('show', 'reply', 'reply-all', 'forward', 'print', selected);
-      this.enable_command('delete', 'moveto', (list.selection.length > 0 ? true : false));
+      this.enable_command('delete', 'moveto', 'mark', (list.selection.length > 0 ? true : false));
       }
 
     // start timer for message preview (wait for double click)
-    if (selected && this.env.contentframe)
+    if (selected && this.env.contentframe && !list.multi_selecting)
       this.preview_timer = setTimeout(function(){ ref.msglist_get_preview(); }, this.dblclick_time + 10);
     else if (this.env.contentframe)
       this.show_contentframe(false);
@@ -1141,6 +1164,8 @@
       this.command('show');
     else if (list.key_pressed == list.DELETE_KEY)
       this.command('delete');
+    else
+      list.shiftkey = false;
     };
 
 
@@ -1184,6 +1209,10 @@
 
     if (safe)
       add_url = '&_safe=1';
+
+    // also send search request to get the right messages
+    if (this.env.search_request)
+      add_url += '&_search='+this.env.search_request;
 
     if (id)
       {
@@ -1354,11 +1383,8 @@
   this.move_messages = function(mbox)
     {
     // exit if current or no mailbox specified or if selection is empty
-    if (!mbox || !this.env.uid || mbox==this.env.mailbox)
-      {
-      if (!this.message_list || !this.message_list.get_selection().length)
-        return;
-      }
+    if (!mbox || mbox == this.env.mailbox || (!this.env.uid && (!this.message_list || !this.message_list.get_selection().length)))
+      return;
 
     var lock = false;
     var add_url = '&_target_mbox='+urlencode(mbox)+'&_from='+(this.env.action ? this.env.action : '');
@@ -1371,6 +1397,9 @@
       }
     else
       this.show_contentframe(false);
+
+    // Hide message command buttons until a message is selected
+    this.enable_command('reply', 'reply-all', 'forward', 'delete', 'mark', 'print', false);
 
     this._with_selected_messages('moveto', lock, add_url);
     };
@@ -1496,12 +1525,16 @@
   {
     // mark all message rows as read/unread
     var icn_src;
+    var res_uids = new Array(); 
     var rows = this.message_list.rows;
     for (var i=0; i<a_uids.length; i++)
       {
       uid = a_uids[i];
-      if (rows[uid])
+      // check if flag isn't set yet 
+      if (rows[uid] && ((flag=='unread' && !rows[uid].unread) || (flag=='read' && rows[uid].unread)))
         {
+        res_uids[res_uids.length] = uid;
+
         rows[uid].unread = (flag=='unread' ? true : false);
         
         if (rows[uid].classname.indexOf('unread')<0 && rows[uid].unread)
@@ -1527,8 +1560,9 @@
           rows[uid].icon.src = icn_src;
         }
       }
-      
-    this.http_post('mark', '_uid='+a_uids.join(',')+'&_flag='+flag);
+
+    if (res_uids.length)
+      this.http_post('mark', '_uid='+res_uids.join(',')+'&_flag='+flag);
   };
   
   // mark all message rows as deleted/undeleted
@@ -1642,7 +1676,7 @@
   /*********************************************************/
 
   // handler for keyboard events on the _user field
-  this.login_user_keypress = function(e)
+  this.login_user_keyup = function(e)
   {
     var key = rcube_event.get_keycode(e);
     var elm;
@@ -1666,11 +1700,14 @@
     {
     // check input fields
     var input_to = rcube_find_object('_to');
+    var input_cc = rcube_find_object('_cc');
+    var input_bcc = rcube_find_object('_bcc');
     var input_subject = rcube_find_object('_subject');
     var input_message = rcube_find_object('_message');
 
     // check for empty recipient
-    if (input_to && !rcube_check_email(input_to.value, true))
+    var recipients = input_to.value ? input_to.value : (input_cc.value ? input_cc.value : input_bcc.value);
+    if (!rcube_check_email(recipients.replace(/^\s+/, '').replace(/[\s,;]+$/, ''), true))
       {
       alert(this.get_label('norecipientwarning'));
       input_to.focus();
@@ -1803,6 +1840,10 @@
       var eid = tinyMCE.getEditorId('_message');
       // editor is a TinyMCE_Control object
       var editor = tinyMCE.getInstanceById(eid);
+      // if this is null, we should exit
+      if (editor == null) {
+        return false;
+      }
       var msgDoc = editor.getDoc();
       var msgBody = msgDoc.body;
 
@@ -1857,8 +1898,11 @@
       }
       
     // clear upload form
-    if (!a && this.gui_objects.attachmentform && this.gui_objects.attachmentform!=this.gui_objects.messageform)
-      this.gui_objects.attachmentform.reset();
+	try {
+      if (!a && this.gui_objects.attachmentform != this.gui_objects.messageform)
+      	this.gui_objects.attachmentform.reset();
+	}
+	catch(e){}  // ignore errors
     
     return true;  
     };
@@ -1867,7 +1911,6 @@
   // upload attachment file
   this.upload_file = function(form)
     {
-    
     if (!form)
       return false;
       
@@ -1972,7 +2015,7 @@
       // reset vars
       this.env.current_page = 1;
       this.set_busy(true, 'searching');
-      this.http_request('search', '_q='+urlencode(value)+(this.env.mailbox ? '&_mbox='+this.env.mailbox : '')+(this.env.source ? '&_source='+urlencode(this.env.source) : ''), true);
+      this.http_request('search', '_q='+urlencode(value)+(this.env.mailbox ? '&_mbox='+urlencode(this.env.mailbox) : '')+(this.env.source ? '&_source='+urlencode(this.env.source) : ''), true);
       }
     return true;
     };
@@ -2355,6 +2398,7 @@
       return;
       
     var a_cids = new Array();
+    var qs = '';
 
     if (this.env.cid)
       a_cids[a_cids.length] = this.env.cid;
@@ -2365,7 +2409,7 @@
         {
         id = selection[n];
         a_cids[a_cids.length] = id;
-        this.contact_list.remove_row(id);
+        this.contact_list.remove_row(id, (n == selection.length-1));
         }
 
       // hide content frame if we delete the currently displayed contact
@@ -2373,8 +2417,12 @@
         this.show_contentframe(false);
       }
 
+    // also send search request to get the right records from the next page
+    if (this.env.search_request) 
+      qs += '&_search='+this.env.search_request;
+
     // send request to server
-    this.http_post('delete', '_cid='+urlencode(a_cids.join(','))+'&_from='+(this.env.action ? this.env.action : ''));
+    this.http_post('delete', '_cid='+urlencode(a_cids.join(','))+'&_from='+(this.env.action ? this.env.action : '')+qs);
     return true;
     };
 
@@ -2403,10 +2451,20 @@
   this.init_subscription_list = function()
     {
     var p = this;
-    this.subscription_list = new rcube_list_widget(this.gui_objects.subscriptionlist, {multiselect:false, draggable:true, keyboard:false});
+    this.subscription_list = new rcube_list_widget(this.gui_objects.subscriptionlist, {multiselect:false, draggable:true, keyboard:false, toggleselect:true});
     this.subscription_list.addEventListener('select', function(o){ p.subscription_select(o); });
     this.subscription_list.addEventListener('dragstart', function(o){ p.drag_active = true; });
     this.subscription_list.addEventListener('dragend', function(o){ p.subscription_move_folder(o); });
+    this.subscription_list.row_init = function (row)
+      {
+      var anchors = row.obj.getElementsByTagName('A');
+      if (anchors[0])
+        anchors[0].onclick = function() { p.rename_folder(row.id); return false; };
+      if (anchors[1])
+        anchors[1].onclick = function() { p.delete_folder(row.id); return false; };
+      row.obj.onmouseover = function() { p.focus_subscription(row.id); };
+      row.obj.onmouseout = function() { p.unfocus_subscription(row.id); };
+      }
     this.subscription_list.init();
     }
 
@@ -2459,50 +2517,54 @@
 
   this.focus_subscription = function(id)
     {
-    var row;
+    var row, folder;
     var reg = RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$');
-    if (this.drag_active && this.check_droptarget(id) &&
-        (id != this.env.folder.replace(reg, '')) &&
-        (row = document.getElementById(this.get_folder_row_id(id))))
-      if (find_in_array(this.env.defaultfolders, id)>=0)
+
+    if (this.drag_active && (row = document.getElementById(id)))
+      if (this.env.subscriptionrows[id] &&
+          (folder = this.env.subscriptionrows[id][0]))
         {
-        if (this.env.folder.replace(reg, '')!='')
+        if (this.check_droptarget(folder) &&
+            (folder != this.env.folder.replace(reg, '')) &&
+            (!folder.match(new RegExp('^'+RegExp.escape(this.env.folder+this.env.delimiter)))))
           {
-          this.set_env('dstfolder', this.env.delimiter);
-          this.set_classname(this.subscription_list.frame, 'droptarget', true);
+          this.set_env('dstfolder', folder);
+          this.set_classname(row, 'droptarget', true);
           }
         }
-      else
+      else if (this.env.folder.match(new RegExp(RegExp.escape(this.env.delimiter))))
         {
-        this.set_env('dstfolder', id);
-        this.set_classname(row, 'droptarget', true);
+        this.set_env('dstfolder', this.env.delimiter);
+        this.set_classname(this.subscription_list.frame, 'droptarget', true);
         }
     }
 
 
   this.unfocus_subscription = function(id)
     {
-    var row;
-    if (row = document.getElementById(this.get_folder_row_id(id)))
-      {
+      var row;
       this.set_env('dstfolder', null);
-      if (find_in_array(this.env.defaultfolders, id)>=0)
-        this.set_classname(this.subscription_list.frame, 'droptarget', false);
-      else
+      if (this.env.subscriptionrows[id] &&
+          (row = document.getElementById(id)))
         this.set_classname(row, 'droptarget', false);
-      }
+      else
+        this.set_classname(this.subscription_list.frame, 'droptarget', false);
     }
 
 
   this.subscription_select = function(list)
     {
-    var id;
-    if (id = list.get_single_selection())
-      {
-      var folder = this.env.subscriptionrows['rcmrow'+id][0];
-      if (find_in_array(this.env.defaultfolders, folder)!=0)
-        this.set_env('folder', folder);
-      }
+    var id, folder;
+    if ((id = list.get_single_selection()) &&
+        this.env.subscriptionrows['rcmrow'+id] &&
+        (folder = this.env.subscriptionrows['rcmrow'+id][0]) &&
+        (find_in_array(this.env.defaultfolders, folder)!=0))
+      this.set_env('folder', folder);
+    else
+      this.set_env('folder', null);
+      
+    if (this.gui_objects.createfolderhint)
+      this.gui_objects.createfolderhint.innerHTML = this.env.folder ? this.get_label('addsubfolderhint') : '';
     };
 
 
@@ -2518,20 +2580,20 @@
       this.http_post('rename-folder', '_folder_oldname='+urlencode(this.env.folder)+'&_folder_newname='+urlencode(newname));
       }
     this.drag_active = false;
-    this.unfocus_subscription(this.env.dstfolder);
+    this.unfocus_subscription(this.get_folder_row_id(this.env.dstfolder));
     };
 
 
   // tell server to create and subscribe a new mailbox
   this.create_folder = function(name)
     {
-  if (this.edit_folder)
-    this.reset_folder_rename();
+    if (this.edit_folder)
+      this.reset_folder_rename();
 
     var form;
     if ((form = this.gui_objects.editform) && form.elements['_folder_name'])
       name = form.elements['_folder_name'].value;
-    if (this.env.folder)
+    if (this.env.folder && name != '')
       name = this.env.folder+this.env.delimiter+name;
 
     if (name)
@@ -2541,33 +2603,11 @@
     };
 
 
-  // entry point for folder renaming
-  this.rename_folder = function(props)
-    {
-    var form, oldname, newname;
-    
-    // rename a specific mailbox
-    if (props)
-      this.edit_foldername(props);
-
-    // use a dropdown and input field (old behavior)
-    else if ((form = this.gui_objects.editform) && form.elements['_folder_oldname'] && form.elements['_folder_newname'])
-      {
-      oldname = form.elements['_folder_oldname'].value;
-      newname = form.elements['_folder_newname'].value;
-      }
-
-    if (oldname && newname)
-      this.http_post('rename-folder', '_folder_oldname='+urlencode(oldname)+'&_folder_newname='+urlencode(newname));
-    };
-
-
-  // start editing the mailbox name.
+  // start renaming the mailbox name.
   // this will replace the name string with an input field
-  this.edit_foldername = function(folder)
+  this.rename_folder = function(id)
     {
     var temp, row, form;
-    var id = this.get_folder_row_id(folder);
 
     // reset current renaming
   if (temp = this.edit_folder)
@@ -2577,14 +2617,15 @@
       return;
     }
 
-    if (id && (row = document.getElementById(id)))
+    if (id && this.env.subscriptionrows[id] && (row = document.getElementById(id)))
       {
       var reg = new RegExp('.*['+RegExp.escape(this.env.delimiter)+']');
       this.name_input = document.createElement('INPUT');
-      this.name_input.value = folder.replace(reg, '');
+      this.name_input.value = this.env.subscriptionrows[id][1].replace(reg, '');
       this.name_input.style.width = '100%';
+      
       reg = new RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$');
-      this.name_input.setAttribute('parent', folder.replace(reg, ''));
+      this.name_input.__parent = this.env.subscriptionrows[id][0].replace(reg, '');
       this.name_input.onkeypress = function(e){ rcmail.name_input_keypress(e); };
       
       row.cells[0].replaceChild(this.name_input, row.cells[0].firstChild);
@@ -2622,9 +2663,9 @@
       var newname = this.name_input ? this.name_input.value : null;
       if (this.edit_folder && newname)
         {
-        if (this.name_input.getAttribute('parent') && this.name_input.getAttribute('parent')!='')
-          newname = this.name_input.getAttribute('parent')+this.env.delimiter+newname;
-          this.http_post('rename-folder', '_folder_oldname='+urlencode(this.env.subscriptionrows[this.edit_folder][0])+'&_folder_newname='+urlencode(newname));
+        if (this.name_input.__parent)
+          newname = this.name_input.__parent + this.env.delimiter + newname;
+        this.http_post('rename-folder', '_folder_oldname='+urlencode(this.env.subscriptionrows[this.edit_folder][0])+'&_folder_newname='+urlencode(newname));
         }
       }
     // escape
@@ -2634,13 +2675,22 @@
 
 
   // delete a specific mailbox with all its messages
-  this.delete_folder = function(folder)
+  this.delete_folder = function(id)
     {
-  if (this.edit_folder)
-    this.reset_folder_rename();
-    
-    if (folder)
+    var folder = this.env.subscriptionrows[id][0];
+
+    if (this.edit_folder)
+      this.reset_folder_rename();
+
+    if (folder && confirm(this.get_label('deletefolderconfirm')))
+      {
       this.http_post('delete-folder', '_mboxes='+urlencode(folder));
+      this.set_env('folder', null);
+
+      if (this.gui_objects.createfolderhint)
+        this.gui_objects.createfolderhint.innerHTML = '';
+
+      }
     };
 
 
@@ -2657,7 +2707,14 @@
 
     var refrow, form;
     var tbody = this.gui_objects.subscriptionlist.tBodies[0];
-    var id = replace && replace.id ? replace.id : tbody.childNodes.length+1;
+    var id = 'rcmrow'+(tbody.childNodes.length+1);
+    var selection = this.subscription_list.get_single_selection();
+    
+    if (replace && replace.id)
+    {
+      id = replace.id;
+      refid = replace.id;
+    }
 
     if (!id || !(refrow = document.getElementById(refid)))
       {
@@ -2668,29 +2725,29 @@
       {
       // clone a table row if there are existing rows
       var row = this.clone_table_row(refrow);
-      row.id = 'rcmrow'+id;
+      row.id = id;
       if (replace)
         tbody.replaceChild(row, replace);
       else
         tbody.appendChild(row);
       }
-
+    
     // add to folder/row-ID map
     this.env.subscriptionrows[row.id] = [name, display_name];
 
     // set folder name
     row.cells[0].innerHTML = display_name;
-    if (row.cells[1] && row.cells[1].firstChild.tagName=='INPUT')
+    
+    // set messages count to zero
+    if (!replace)
+      row.cells[1].innerHTML = '*';
+    
+    if (!replace && row.cells[2] && row.cells[2].firstChild.tagName=='INPUT')
       {
-      row.cells[1].firstChild.value = name;
-      row.cells[1].firstChild.checked = true;
+      row.cells[2].firstChild.value = name;
+      row.cells[2].firstChild.checked = true;
       }
-       
-    if (row.cells[2] && row.cells[2].firstChild.tagName=='A')
-      row.cells[2].firstChild.onclick = new Function(this.ref+".command('rename-folder','"+name.replace('\'','\\\'')+"')");
-    if (row.cells[3] && row.cells[3].firstChild.tagName=='A')
-      row.cells[3].firstChild.onclick = new Function(this.ref+".command('delete-folder','"+name.replace('\'','\\\'')+"')");
-
+    
     // add new folder to rename-folder list and clear input field
     if (!replace && (form = this.gui_objects.editform))
       {
@@ -2702,9 +2759,11 @@
 
     this.sort_subscription_list();
     this.init_subscription_list();
+    if (selection && document.getElementById('rcmrow'+selection))
+      this.subscription_list.select_row(selection);
 
-    if (document.getElementById('rcmrow'+id).scrollIntoView)
-      document.getElementById('rcmrow'+id).scrollIntoView();
+    if (document.getElementById(id).scrollIntoView)
+      document.getElementById(id).scrollIntoView();
     };
 
 
@@ -2716,7 +2775,6 @@
     
     // replace an existing table row (if found)
     this.add_folder_row(newfolder, display_name, row);
-    this.env.subscriptionrows[id] = null;
     
     // rename folder in rename-folder dropdown
     var form, elm;
@@ -2767,59 +2825,17 @@
 
   this.subscribe_folder = function(folder)
     {
-    var form;
-    if ((form = this.gui_objects.editform) && form.elements['_unsubscribed'])
-      this.change_subscription('_unsubscribed', '_subscribed', 'subscribe');
-    else if (folder)
-      this.http_post('subscribe', '_mboxes='+urlencode(folder));
+    if (folder)
+      this.http_post('subscribe', '_mbox='+urlencode(folder));
     };
 
 
   this.unsubscribe_folder = function(folder)
     {
-    var form;
-    if ((form = this.gui_objects.editform) && form.elements['_subscribed'])
-      this.change_subscription('_subscribed', '_unsubscribed', 'unsubscribe');
-    else if (folder)
-      this.http_post('unsubscribe', '_mboxes='+urlencode(folder));
+    if (folder)
+      this.http_post('unsubscribe', '_mbox='+urlencode(folder));
     };
     
-
-  this.change_subscription = function(from, to, action)
-    {
-    var form;
-    if (form = this.gui_objects.editform)
-      {
-      var a_folders = new Array();
-      var list_from = form.elements[from];
-
-      for (var i=0; list_from && i<list_from.options.length; i++)
-        {
-        if (list_from.options[i] && list_from.options[i].selected)
-          {
-          a_folders[a_folders.length] = list_from.options[i].value;
-          list_from[i] = null;
-          i--;
-          }
-        }
-
-      // yes, we have some folders selected
-      if (a_folders.length)
-        {
-        var list_to = form.elements[to];
-        var index;
-        
-        for (var n=0; n<a_folders.length; n++)
-          {
-          index = list_to.options.length;
-          list_to[index] = new Option(a_folders[n]);
-          }
-          
-        this.http_post(action, '_mboxes='+urlencode(a_folders.join(',')));
-        }
-      }
-      
-    };
 
   // helper method to find a specific mailbox row ID
   this.get_folder_row_id = function(folder)
@@ -3151,8 +3167,10 @@
 
         cell.id = 'rcmHead'+col;
         }
+        
+      if (col == 'subject' && this.message_list)
+        this.message_list.subject_col = n+1;
       }
-
   };
 
   // create a table row in the message list
@@ -3232,11 +3250,8 @@
     if (!this.gui_objects.mailboxlist)
       return false;
 
-    var reg, text_obj;
-    var item = this.get_folder_li(mbox);
-    mbox = String(mbox).toLowerCase().replace(this.identifier_expr, '');
-
-    if (item && item.className && item.className.indexOf('mailbox '+mbox)>=0)
+    var reg, text_obj, item;
+    if (item = this.get_folder_li(mbox))
       {
       // set new text
       text_obj = item.firstChild;
@@ -3443,11 +3458,17 @@
 
       case 'list':
         if (this.env.messagecount)
-          this.enable_command('purge', (this.env.mailbox==this.env.trash_mailbox || this.env.mailbox==this.env.junk_mailbox));
+	  this.enable_command('purge', (this.env.mailbox==this.env.trash_mailbox || this.env.mailbox==this.env.junk_mailbox));
+
+	this.msglist_select(this.message_list);
+
+      case 'getunread':
+	this.enable_command('sort', (this.env.messagecount > 0));
 
       case 'expunge':
         this.enable_command('select-all', 'select-none', 'expunge', this.env.messagecount ? true : false);
         break;
+
       }
 
     request_obj.reset();
@@ -3479,13 +3500,10 @@
   this.check_for_recent = function()
     {
     if (this.busy)
-      {
-      this.send_keep_alive();
       return;
-      }
 
     this.set_busy(true, 'checkingmail');
-    this.http_request('check-recent', '_t='+(new Date().getTime()), true);
+    this.http_request('check-recent', (this.env.search_request ? '_search='+this.env.search_request+'&' : '') + '_t='+(new Date().getTime()), true);
     };
 
 

--
Gitblit v1.9.1