]> git.donarmstrong.com Git - roundcube.git/blobdiff - program/js/app.js
Imported Upstream version 0.1.1
[roundcube.git] / program / js / app.js
index 57d473aef914b5fad97e1047ad9a311f1cee7080..1ddb6da689b3c767d3192da42d5029f68353c1ee 100644 (file)
@@ -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                                            |
  |                                                                       |
  +-----------------------------------------------------------------------+
@@ -13,7 +13,7 @@
  | Requires: common.js, list.js                                          |
  +-----------------------------------------------------------------------+
 
-  $Id: app.js 615 2007-06-13 05:57:44Z thomasb $
+  $Id: app.js 1255 2008-04-05 12:49:21Z thomasb $
 */
 
 
@@ -35,7 +35,7 @@ function rcube_webmail()
  
   // webmail client settings
   this.dblclick_time = 500;
-  this.message_time = 5000;
+  this.message_time = 3000;
   
   this.identifier_expr = new RegExp('[^0-9a-z\-_]', 'gi');
   
@@ -132,7 +132,7 @@ function rcube_webmail()
           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 @@ function rcube_webmail()
           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);
@@ -164,6 +170,9 @@ function rcube_webmail()
             this.enable_command('firstmessage', true);
             }
           }
+
+        if (this.env.trash_mailbox && this.env.mailbox != this.env.trash_mailbox)
+          this.set_alttext('delete', 'movemessagetotrash');
         
         // make preview/message frame visible
         if (this.env.action == 'preview' && this.env.framed && parent.rcmail)
@@ -193,15 +202,18 @@ function rcube_webmail()
           }
 
         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')
@@ -217,6 +229,16 @@ function rcube_webmail()
           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;
 
@@ -283,13 +305,16 @@ function rcube_webmail()
             this.identity_list.highlight_row(this.env.iid);
           }
 
+        if (this.gui_objects.subscriptionlist)
+          this.init_subscription_list();
+
         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)
@@ -463,7 +488,7 @@ function rcube_webmail()
         break;
 
       case 'logout':
-        this.goto_url('logout');
+        this.goto_url('logout', true);
         break;      
 
       // commands to switch task
@@ -478,10 +503,13 @@ function rcube_webmail()
       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);
+
+          if (this.env.trash_mailbox)
+            this.set_alttext('delete', this.env.mailbox != this.env.trash_mailbox ? 'movemessagetotrash' : 'deletemessage');
           }
         else if (this.task=='addressbook')
           {
@@ -651,7 +679,12 @@ function rcube_webmail()
         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;
@@ -662,7 +695,7 @@ function rcube_webmail()
         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';
@@ -679,7 +712,7 @@ function rcube_webmail()
         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)
@@ -694,7 +727,7 @@ function rcube_webmail()
             }
           }
 
-        this.goto_url('get', qstring+'&_download=1');
+        this.goto_url('get', qstring+'&_download=1', false);
         break;
         
       case 'select-all':
@@ -798,6 +831,7 @@ function rcube_webmail()
         this.set_busy(true, 'savingmessage');
         var form = this.gui_objects.messageform;
         form.target = "savetarget";
+        form._draft.value = '1';
         form.submit();
         break;
 
@@ -807,7 +841,7 @@ function rcube_webmail()
 
         if (!this.check_compose_input())
           break;
-          
+
         // Reset the auto-save timer
         self.clearTimeout(this.save_timer);
 
@@ -852,11 +886,15 @@ function rcube_webmail()
       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.mark_message('read', uid);
           }
+        }
         break;
 
       case 'viewsource':
@@ -928,8 +966,7 @@ function rcube_webmail()
         break;
 
       case 'delete-folder':
-        if (confirm(this.get_label('deletefolderconfirm')))
-          this.delete_folder(props);
+        this.delete_folder(props);
         break;
 
       }
@@ -1063,8 +1100,6 @@ function rcube_webmail()
       this.unfocus_folder(id);
       this.command('moveto', id);
       }
-  
-    return false;
     };
 
   this.click_on_list = function(e)
@@ -1088,19 +1123,22 @@ function rcube_webmail()
       clearTimeout(this.preview_timer);
 
     var selected = list.selection.length==1;
+
+    // Hide certain command buttons when Drafts folder is selected
     if (this.env.mailbox == this.env.drafts_mailbox)
       {
+      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);
@@ -1126,6 +1164,8 @@ function rcube_webmail()
       this.command('show');
     else if (list.key_pressed == list.DELETE_KEY)
       this.command('delete');
+    else
+      list.shiftkey = false;
     };
 
 
@@ -1145,6 +1185,8 @@ function rcube_webmail()
       return (id != this.env.mailbox);
     else if (this.task == 'addressbook')
       return (id != this.env.source && this.env.address_sources[id] && !this.env.address_sources[id].readonly);
+    else if (this.task == 'settings')
+      return (id != this.env.folder);
   };
 
 
@@ -1168,6 +1210,10 @@ function rcube_webmail()
     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)
       {
       var url = '&_action='+action+'&_uid='+id+'&_mbox='+urlencode(this.env.mailbox)+add_url;
@@ -1337,11 +1383,8 @@ function rcube_webmail()
   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 : '');
@@ -1355,6 +1398,9 @@ function rcube_webmail()
     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);
     };
 
@@ -1423,10 +1469,8 @@ function rcube_webmail()
         {
         id = selection[n];
         a_uids[a_uids.length] = id;
-        this.message_list.remove_row(id);
+        this.message_list.remove_row(id, (n == selection.length-1));
         }
-
-      this.message_list.select_next();
       }
       
     // also send search request to get the right messages 
@@ -1442,6 +1486,7 @@ function rcube_webmail()
   this.mark_message = function(flag, uid)
     {
     var a_uids = new Array();
+    var r_uids = new Array();
     var selection = this.message_list ? this.message_list.get_selection() : new Array();
     
     if (uid)
@@ -1452,26 +1497,35 @@ function rcube_webmail()
       {
       for (var id, n=0; n<selection.length; n++)
         {
-        id = selection[n];
-        if ((flag=='read' && this.message_list.rows[id].unread) || (flag=='unread' && !this.message_list.rows[id].unread)
-            || (flag=='delete' && !this.message_list.rows[id].deleted) || (flag=='undelete' && this.message_list.rows[id].deleted))
-          a_uids[a_uids.length] = id;
+         a_uids[a_uids.length] = selection[n];
         }
       }
+
+    for (var id, n=0; n<a_uids.length; n++)
+      {
+        id = a_uids[n];
+        if ((flag=='read' && this.message_list.rows[id].unread) 
+           || (flag=='unread' && !this.message_list.rows[id].unread)
+            || (flag=='delete' && !this.message_list.rows[id].deleted)
+           || (flag=='undelete' && this.message_list.rows[id].deleted))
+         {
+           r_uids[r_uids.length] = id;
+         }
+      }
     
     // nothing to do
-    if (!a_uids.length)
+    if (!r_uids.length)
       return;
       
     switch (flag)
       {
         case 'read':
         case 'unread':
-          this.toggle_read_status(flag, a_uids);
+          this.toggle_read_status(flag, r_uids);
           break;
         case 'delete':
         case 'undelete':
-          this.toggle_delete_status(a_uids);
+          this.toggle_delete_status(r_uids);
           break;
       }
     };
@@ -1512,7 +1566,7 @@ function rcube_webmail()
           rows[uid].icon.src = icn_src;
         }
       }
-      
+
     this.http_post('mark', '_uid='+a_uids.join(',')+'&_flag='+flag);
   };
   
@@ -1520,7 +1574,7 @@ function rcube_webmail()
   this.toggle_delete_status = function(a_uids)
   {
     if (this.env.read_when_deleted)
-      this.toggle_read_status('read',a_uids);
+      this.mark_message('read',a_uids);
 
     // if deleting message from "view message" don't bother with delete icon
     if (this.env.action == "show")
@@ -1627,7 +1681,7 @@ function rcube_webmail()
   /*********************************************************/
 
   // 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;
@@ -1651,11 +1705,14 @@ function rcube_webmail()
     {
     // 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();
@@ -1680,13 +1737,10 @@ function rcube_webmail()
       }
 
     // check for empty body
-    if (input_message.value=='')
+    if ((input_message.value == '' && (!window.tinyMCE || tinyMCE.getContent() == '')) && !confirm(this.get_label('nobodywarning')))
       {
-      if (!confirm(this.get_label('nobodywarning')))
-        {
-        input_message.focus();
-        return false;
-        }
+      input_message.focus();
+      return false;
       }
 
     return true;
@@ -1711,6 +1765,9 @@ function rcube_webmail()
     {
     if (this.env.draft_autosave)
       this.save_timer = self.setTimeout(function(){ ref.command("savedraft"); }, this.env.draft_autosave * 1000);
+
+    // Unlock interface now that saving is complete
+    this.busy = false;
     };
 
 
@@ -1788,6 +1845,10 @@ function rcube_webmail()
       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;
 
@@ -1842,8 +1903,11 @@ function rcube_webmail()
       }
       
     // 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;  
     };
@@ -1852,7 +1916,6 @@ function rcube_webmail()
   // upload attachment file
   this.upload_file = function(form)
     {
-    
     if (!form)
       return false;
       
@@ -1957,7 +2020,7 @@ function rcube_webmail()
       // 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;
     };
@@ -2250,6 +2313,7 @@ function rcube_webmail()
       {
       page = 1;
       this.env.current_page = page;
+      this.reset_qsearch();
       }
 
     this.select_folder(src, this.env.source);
@@ -2286,7 +2350,7 @@ function rcube_webmail()
     this.enable_command('delete', 'compose', false);
 
     // send request to server
-    var url = (src ? '&_source='+urlencode(src) : '') + (page ? '&_page='+page : '');
+    var url = (src ? '_source='+urlencode(src) : '') + (page ? (src?'&':'') + '_page='+page : '');
     this.env.source = src;
     
     // also send search request to get the right messages 
@@ -2339,6 +2403,7 @@ function rcube_webmail()
       return;
       
     var a_cids = new Array();
+    var qs = '';
 
     if (this.env.cid)
       a_cids[a_cids.length] = this.env.cid;
@@ -2349,7 +2414,7 @@ function rcube_webmail()
         {
         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
@@ -2357,8 +2422,12 @@ function rcube_webmail()
         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;
     };
 
@@ -2384,6 +2453,26 @@ function rcube_webmail()
   /*********        user settings methods          *********/
   /*********************************************************/
 
+  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, 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();
+    }
+
   this.identity_select = function(list)
     {
     var id;
@@ -2431,15 +2520,86 @@ function rcube_webmail()
     };
 
 
+  this.focus_subscription = function(id)
+    {
+    var row, folder;
+    var reg = RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$');
+
+    if (this.drag_active && (row = document.getElementById(id)))
+      if (this.env.subscriptionrows[id] &&
+          (folder = this.env.subscriptionrows[id][0]))
+        {
+        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', folder);
+          this.set_classname(row, 'droptarget', true);
+          }
+        }
+      else if (this.env.folder.match(new RegExp(RegExp.escape(this.env.delimiter))))
+        {
+        this.set_env('dstfolder', this.env.delimiter);
+        this.set_classname(this.subscription_list.frame, 'droptarget', true);
+        }
+    }
+
+
+  this.unfocus_subscription = function(id)
+    {
+      var row;
+      this.set_env('dstfolder', null);
+      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, 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') : '';
+    };
+
+
+  this.subscription_move_folder = function(list)
+    {
+    var reg = RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$');
+    if (this.env.folder && this.env.dstfolder && (this.env.dstfolder != this.env.folder) &&
+        (this.env.dstfolder != this.env.folder.replace(reg, '')))
+      {
+      var reg = new RegExp('[^'+RegExp.escape(this.env.delimiter)+']*['+RegExp.escape(this.env.delimiter)+']', 'g');
+      var basename = this.env.folder.replace(reg, '');
+      var newname = this.env.dstfolder==this.env.delimiter ? basename : this.env.dstfolder+this.env.delimiter+basename;
+      this.http_post('rename-folder', '_folder_oldname='+urlencode(this.env.folder)+'&_folder_newname='+urlencode(newname));
+      }
+    this.drag_active = false;
+    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 && name != '')
+      name = this.env.folder+this.env.delimiter+name;
 
     if (name)
       this.http_post('create-folder', '_name='+urlencode(name), true);
@@ -2448,33 +2608,11 @@ function rcube_webmail()
     };
 
 
-  // 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)
@@ -2484,11 +2622,15 @@ function rcube_webmail()
       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 = this.env.subscriptionrows[id][1];
+      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.__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);
@@ -2506,7 +2648,10 @@ function rcube_webmail()
     {
     var cell = this.name_input ? this.name_input.parentNode : null;
     if (cell && this.edit_folder && this.env.subscriptionrows[this.edit_folder])
-      cell.innerHTML = this.env.subscriptionrows[this.edit_folder][1];
+      {
+      var reg = new RegExp('[^'+RegExp.escape(this.env.delimiter)+']*['+RegExp.escape(this.env.delimiter)+']', 'g');
+      cell.innerHTML = this.env.subscriptionrows[this.edit_folder][1].replace(reg, '&nbsp;&nbsp;&nbsp;&nbsp;');
+      }
       
     this.edit_folder = null;
     };
@@ -2522,7 +2667,11 @@ function rcube_webmail()
       {
       var newname = this.name_input ? this.name_input.value : null;
       if (this.edit_folder && 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
     else if (key==27)
@@ -2531,13 +2680,22 @@ function rcube_webmail()
 
 
   // 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 = '';
+
+      }
     };
 
 
@@ -2554,7 +2712,14 @@ function rcube_webmail()
 
     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)))
       {
@@ -2565,29 +2730,29 @@ function rcube_webmail()
       {
       // 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))
       {
@@ -2598,6 +2763,12 @@ function rcube_webmail()
       }
 
     this.sort_subscription_list();
+    this.init_subscription_list();
+    if (selection && document.getElementById('rcmrow'+selection))
+      this.subscription_list.select_row(selection);
+
+    if (document.getElementById(id).scrollIntoView)
+      document.getElementById(id).scrollIntoView();
     };
 
 
@@ -2609,7 +2780,6 @@ function rcube_webmail()
     
     // 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;
@@ -2660,60 +2830,18 @@ function rcube_webmail()
 
   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)
     {
@@ -2752,19 +2880,19 @@ function rcube_webmail()
     var index = new Array();
     var tbody = this.gui_objects.subscriptionlist.tBodies[0];
     var swapped = false;
-    for (var i = 0; i<(tbody.childNodes.length-1); i++)
+    for (var i = 0; i<tbody.childNodes.length; i++)
       if (this.env.subscriptionrows[tbody.childNodes[i].id]!=null)
         index.push(i);
     for (i = 0; i<(index.length-1); i++)
       {
-      if (this.env.subscriptionrows[tbody.childNodes[index[i]].id][0]>
-          this.env.subscriptionrows[tbody.childNodes[index[i+1]].id][0])
+      var one = tbody.childNodes[index[i]];
+      var two = tbody.childNodes[index[i+1]];
+      if (this.env.subscriptionrows[one.id][0].toLowerCase()>
+          this.env.subscriptionrows[two.id][0].toLowerCase())
         {
-        var swap = tbody.replaceChild(tbody.childNodes[index[i]], tbody.childNodes[index[i+1]]);
-        if (typeof(tbody.childNodes[index[i]]) != 'undefined')
-          tbody.insertBefore(swap, tbody.childNodes[index[i]])
-        else
-          tbody.appendChild(swap);
+        var swap = one.cloneNode(true);
+        tbody.replaceChild(swap, two);
+        tbody.replaceChild(two, one);
         swapped = true;
         }
       }
@@ -2803,8 +2931,12 @@ function rcube_webmail()
       obj = document.getElementById(button.id);
 
       // get default/passive setting of the button
-      if (obj && button.type=='image' && !button.status)
+      if (obj && button.type=='image' && !button.status) {
         button.pas = obj._original_src ? obj._original_src : obj.src;
+        // respect PNG fix on IE browsers
+        if (obj.runtimeStyle && obj.runtimeStyle.filter && obj.runtimeStyle.filter.match(/src=['"]([^'"]+)['"]/))
+          button.pas = RegExp.$1;
+      }
       else if (obj && !button.status)
         button.pas = String(obj.className);
 
@@ -2829,6 +2961,28 @@ function rcube_webmail()
       }
     };
 
+  // display a specific alttext
+  this.set_alttext = function(command, label)
+    {
+      if (!this.buttons[command] || !this.buttons[command].length)
+        return;
+      
+      var button, obj, link;
+      for (var n=0; n<this.buttons[command].length; n++)
+      {
+        button = this.buttons[command][n];
+        obj = document.getElementById(button.id);
+        
+        if (button.type=='image' && obj)
+        {
+          obj.setAttribute('alt', this.get_label(label));
+          if ((link = obj.parentNode) && link.tagName == 'A')
+            link.setAttribute('title', this.get_label(label));
+        }
+        else if (obj)
+          obj.setAttribute('title', this.get_label(label));
+      }
+    };
 
   // mouse over button
   this.button_over = function(command, id)
@@ -2905,27 +3059,27 @@ function rcube_webmail()
     };
 
 
-  // display a specific alttext
-  this.alttext = function(text)
-    {
-    
-    };
+  // write to the document/window title
+  this.set_pagetitle = function(title)
+  {
+    if (title && document.title)
+      document.title = title;
+  }
 
 
   // display a system message
   this.display_message = function(msg, type, hold)
     {
-    // pass command to parent window
-    if (this.env.framed && parent.rcmail )
-      return parent.rcmail.display_message(msg, type, hold);
-
-    this.set_busy(false);
     if (!this.loaded)  // save message in order to display after page loaded
       {
       this.pending_message = new Array(msg, type);
       return true;
       }
-  
+
+    // pass command to parent window
+    if (this.env.framed && parent.rcmail)
+      return parent.rcmail.display_message(msg, type, hold);
+
     if (!this.gui_objects.message)
       return false;
 
@@ -2936,12 +3090,12 @@ function rcube_webmail()
     if (type)
       cont = '<div class="'+type+'">'+cont+'</div>';
 
-    this.gui_objects.message._rcube = this;
+    var _rcube = this;
     this.gui_objects.message.innerHTML = cont;
     this.gui_objects.message.style.display = 'block';
+    
     if (type!='loading')
-      this.gui_objects.message.onmousedown = function(){ this._rcube.hide_message(); return true; };
+      this.gui_objects.message.onmousedown = function(){ _rcube.hide_message(); return true; };
     
     if (!hold)
       this.message_timer = setTimeout(function(){ ref.hide_message(); }, this.message_time);
@@ -3018,8 +3172,10 @@ function rcube_webmail()
 
         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
@@ -3099,14 +3255,8 @@ function rcube_webmail()
     if (!this.gui_objects.mailboxlist)
       return false;
 
-    if (mbox==this.env.mailbox)
-      set_title = true;
-
-    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;
@@ -3128,13 +3278,16 @@ function rcube_webmail()
     if (set_title && document.title)
       {
       var doc_title = String(document.title);
+      var new_title = "";
 
       if (count && doc_title.match(reg))
-        document.title = doc_title.replace(reg, '('+count+') ');
+        new_title = doc_title.replace(reg, '('+count+') ');
       else if (count)
-        document.title = '('+count+') '+doc_title;
+        new_title = '('+count+') '+doc_title;
       else
-        document.title = doc_title.replace(reg, '');
+        new_title = doc_title.replace(reg, '');
+        
+      this.set_pagetitle(new_title);
       }
     };
 
@@ -3188,9 +3341,11 @@ function rcube_webmail()
   /*********        remote request methods        *********/
   /********************************************************/
 
-  this.redirect = function(url)
+  this.redirect = function(url, lock)
     {
-    this.set_busy(true);
+    if (lock || lock === null)
+      this.set_busy(true);
+
     if (this.env.framed && window.parent)
       parent.location.href = url;
     else  
@@ -3199,11 +3354,8 @@ function rcube_webmail()
 
   this.goto_url = function(action, query, lock)
     {
-    if (lock)
-    this.set_busy(true);
-
     var querystring = query ? '&'+query : '';
-    this.redirect(this.env.comm_path+'&_action='+action+querystring);
+    this.redirect(this.env.comm_path+'&_action='+action+querystring, lock);
     };
 
 
@@ -3289,7 +3441,8 @@ function rcube_webmail()
       ctype = ctype_array[0];
     }
 
-    this.set_busy(false);
+    if (request_obj.__lock)
+        this.set_busy(false);
 
     console.log(request_obj.get_text());
 
@@ -3310,11 +3463,17 @@ function rcube_webmail()
 
       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();
@@ -3346,14 +3505,10 @@ function rcube_webmail()
   this.check_for_recent = function()
     {
     if (this.busy)
-      {
-      this.send_keep_alive();
       return;
-      }
 
     this.set_busy(true, 'checkingmail');
-    var d = new Date();
-    this.http_request('check-recent', '_t='+d.getTime());
+    this.http_request('check-recent', (this.env.search_request ? '_search='+this.env.search_request+'&' : '') + '_t='+(new Date().getTime()), true);
     };
 
 
@@ -3494,12 +3649,13 @@ function rcube_http_request()
       return false;
       }
 
-    var ref = this;
+    var _ref = this;
     this.url = url;
     this.busy = true;
 
-    this.xmlhttp.onreadystatechange = function(){ ref.xmlhttp_onreadystatechange(); };
+    this.xmlhttp.onreadystatechange = function(){ _ref.xmlhttp_onreadystatechange(); };
     this.xmlhttp.open('GET', url);
+    this.xmlhttp.setRequestHeader('X-RoundCube-Referer', bw.get_cookie('roundcube_sessid'));
     this.xmlhttp.send(null);
     };
 
@@ -3533,6 +3689,7 @@ function rcube_http_request()
     this.xmlhttp.onreadystatechange = function() { ref.xmlhttp_onreadystatechange(); };
     this.xmlhttp.open('POST', url, true);
     this.xmlhttp.setRequestHeader('Content-Type', contentType);
+    this.xmlhttp.setRequestHeader('X-RoundCube-Referer', bw.get_cookie('roundcube_sessid'));
     this.xmlhttp.send(req_body);
     };