From ab0b51a1fef87bcc643c3aaf2e635c811b28ccd8 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Tue, 15 Feb 2011 06:10:59 -0500
Subject: [PATCH] - Use only one from IMAP authentication methods to prevent login delays (1487784)

---
 program/js/app.js |   91 ++++++++++++++++++++++++---------------------
 1 files changed, 48 insertions(+), 43 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index c81212f..43be6ae 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -17,7 +17,6 @@
   $Id$
 */
 
-
 function rcube_webmail()
 {
   this.env = {};
@@ -63,7 +62,7 @@
   // set environment variable(s)
   this.set_env = function(p, value)
   {
-    if (p != null && typeof(p) == 'object' && !value)
+    if (p != null && typeof p === 'object' && !value)
       for (var n in p)
         this.env[n] = p[n];
     else
@@ -332,7 +331,7 @@
             this.selectedIndex = 0;
           });
 
-          $("input[type='text']").first().focus();
+          $("input[type='text']:visible").first().focus();
         }
         else if (this.gui_objects.qsearchbox) {
           this.enable_command('search', 'reset-search', 'moveto', true);
@@ -428,9 +427,9 @@
     // execute all foreign onload scripts
     // @deprecated
     for (var i in this.onloads) {
-      if (typeof(this.onloads[i]) == 'string')
+      if (typeof this.onloads[i] === 'string')
         eval(this.onloads[i]);
-      else if (typeof(this.onloads[i]) == 'function')
+      else if (typeof this.onloads[i] === 'function')
         this.onloads[i]();
       }
 
@@ -468,19 +467,19 @@
     }
 
     // process external commands
-    if (typeof this.command_handlers[command] == 'function') {
+    if (typeof this.command_handlers[command] === 'function') {
       var ret = this.command_handlers[command](props, obj);
-      return ret !== null ? ret : (obj ? false : true);
+      return ret !== undefined ? ret : (obj ? false : true);
     }
-    else if (typeof this.command_handlers[command] == 'string') {
+    else if (typeof this.command_handlers[command] === 'string') {
       var ret = window[this.command_handlers[command]](props, obj);
-      return ret !== null ? ret : (obj ? false : true);
+      return ret !== undefined ? ret : (obj ? false : true);
     }
 
     // trigger plugin hooks
     this.triggerEvent('actionbefore', {props:props, action:command});
     var event_ret = this.triggerEvent('before'+command, props);
-    if (typeof event_ret != 'undefined') {
+    if (event_ret !== undefined) {
       // abort if one the handlers returned false
       if (event_ret === false)
         return false;
@@ -647,7 +646,7 @@
               input_name.focus();
               break;
             }
-            else if (input_email.length && !rcube_check_email(input_email.val())) {
+            else if (this.task == 'settings' && input_email.length && !rcube_check_email(input_email.val())) {
               alert(this.get_label('noemailwarning'));
               input_email.focus();
               break;
@@ -1034,7 +1033,7 @@
       // unified command call (command name == function name)
       default:
         var func = command.replace(/-/g, '_');
-        if (this[func] && typeof this[func] == 'function')
+        if (this[func] && typeof this[func] === 'function')
           this[func](props);
         break;
     }
@@ -1410,7 +1409,7 @@
     // reset 'pressed' buttons
     if (this.buttons_sel) {
       for (var id in this.buttons_sel)
-        if (typeof id != 'function')
+        if (typeof id !== 'function')
           this.button_out(this.buttons_sel[id], id);
       this.buttons_sel = {};
     }
@@ -1696,7 +1695,7 @@
           message.expanded = true;
       }
       else if (message.has_children) {
-        if (typeof(message.expanded) == 'undefined' && (this.env.autoexpand_threads == 1 || (this.env.autoexpand_threads == 2 && message.unread_children))) {
+        if (message.expanded === undefined && (this.env.autoexpand_threads == 1 || (this.env.autoexpand_threads == 2 && message.unread_children))) {
           message.expanded = true;
         }
       }
@@ -1784,7 +1783,7 @@
   {
     var update, add_url = '';
 
-    if (typeof sort_col == 'undefined')
+    if (sort_col === undefined)
       sort_col = this.env.sort_col;
     if (!sort_order)
       sort_order = this.env.sort_order;
@@ -2380,7 +2379,7 @@
   // copy selected messages to the specified mailbox
   this.copy_messages = function(mbox)
   {
-    if (mbox && typeof mbox == 'object')
+    if (mbox && typeof mbox === 'object')
       mbox = mbox.id;
 
     // exit if current or no mailbox specified or if selection is empty
@@ -2409,7 +2408,7 @@
   // move selected messages to the specified mailbox
   this.move_messages = function(mbox)
   {
-    if (mbox && typeof mbox == 'object')
+    if (mbox && typeof mbox === 'object')
       mbox = mbox.id;
 
     // exit if current or no mailbox specified or if selection is empty
@@ -2900,7 +2899,7 @@
 
     // check if all files has been uploaded
     for (var key in this.env.attachments) {
-      if (typeof this.env.attachments[key] == 'object' && !this.env.attachments[key].complete) {
+      if (typeof this.env.attachments[key] === 'object' && !this.env.attachments[key].complete) {
         alert(this.get_label('notuploadedwarning'));
         return false;
       }
@@ -3438,13 +3437,13 @@
       end = inp_value.substring(p+this.ksearch_value.length, inp_value.length);
 
     // insert all members of a group
-    if (typeof this.env.contacts[id] == 'object' && this.env.contacts[id].id) {
+    if (typeof this.env.contacts[id] === 'object' && this.env.contacts[id].id) {
       insert += this.env.contacts[id].name + ', ';
       this.group2expand = $.extend({}, this.env.contacts[id]);
       this.group2expand.input = this.ksearch_input;
       this.http_request('group-expand', '_source='+urlencode(this.env.contacts[id].source)+'&_gid='+urlencode(this.env.contacts[id].id), false);
     }
-    else if (typeof this.env.contacts[id] == 'string')
+    else if (typeof this.env.contacts[id] === 'string')
       insert = this.env.contacts[id] + ', ';
 
     this.ksearch_input.value = pre + insert + end;
@@ -3543,7 +3542,7 @@
 
       // add each result line to list
       for (i=0; i < a_results.length; i++) {
-        text = typeof a_results[i] == 'object' ? a_results[i].name : a_results[i];
+        text = typeof a_results[i] === 'object' ? a_results[i].name : a_results[i];
         li = document.createElement('LI');
         li.innerHTML = text.replace(new RegExp('('+RegExp.escape(s_val)+')', 'ig'), '##$1%%').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/##([^%]+)%%/g, '<b>$1</b>');
         li.onmouseover = function(){ ref.ksearch_select(this); };
@@ -3766,6 +3765,9 @@
         this.show_contentframe(false);
     }
 
+    if (this.env.group)
+      qs += '&_gid='+urlencode(this.env.group);
+
     // also send search request to get the right records from the next page
     if (this.env.search_request) 
       qs += '&_search='+this.env.search_request;
@@ -3779,6 +3781,9 @@
   // update a contact record in the list
   this.update_contact_row = function(cid, cols_arr, newcid)
   {
+    cid = String(cid).replace(this.identifier_expr, '_');
+    newcid = String(newcid).replace(this.identifier_expr, '_');
+
     var row;
     if (this.contact_list.rows[cid] && (row = this.contact_list.rows[cid].obj)) {
       for (var c=0; c<cols_arr.length; c++)
@@ -3811,7 +3816,7 @@
       even = rowcount%2,
       row = document.createElement('tr');
 
-    row.id = 'rcmrow'+cid;
+    row.id = 'rcmrow'+String(cid).replace(this.identifier_expr, '_');
     row.className = 'contact '+(even ? 'even' : 'odd');
 
     if (this.contact_list.in_selection(cid))
@@ -3945,7 +3950,7 @@
     var link = $('<a>').attr('href', '#')
       .bind('click', function() { return rcmail.command('listgroup', prop, this);})
       .html(prop.name);
-    var li = $('<li>').attr('id', 'rcmli'+key)
+    var li = $('<li>').attr('id', 'rcmli'+key.replace(this.identifier_expr, '_'))
       .addClass('contactgroup')
       .append(link)
       .insertAfter(this.get_folder_li(prop.source));
@@ -3975,7 +3980,7 @@
     
     elem.focus(function(){ ref.focus_textfield(this); })
       .blur(function(){ ref.blur_textfield(this); })
-      .each(function(){ this._placeholder = ref.env.coltypes[col].label; ref.blur_textfield(this); });
+      .each(function(){ this._placeholder = this.title = ref.env.coltypes[col].label; ref.blur_textfield(this); });
   };
 
   this.insert_edit_field = function(col, section, menu)
@@ -4492,7 +4497,7 @@
   this.init_buttons = function()
   {
     for (var cmd in this.buttons) {
-      if (typeof cmd != 'string')
+      if (typeof cmd !== 'string')
         continue;
 
       for (var i=0; i< this.buttons[cmd].length; i++) {
@@ -4553,7 +4558,7 @@
         obj.src = button[state];
       }
       // set class name according to button state
-      else if (obj && typeof(button[state])!='undefined') {
+      else if (obj && button[state] !== undefined) {
         button.status = state;
         obj.className = button[state];
       }
@@ -4748,7 +4753,7 @@
     var k, n, i, msg, m = this.messages;
 
     // Hide message by object, don't use for 'loading'!
-    if (typeof(obj) == 'object') {
+    if (typeof obj === 'object') {
       $(obj)[fade?'fadeOut':'hide']();
       msg = $(obj).data('key');
       if (this.messages[msg])
@@ -4894,7 +4899,7 @@
   this.set_quota = function(content)
   {
     if (content && this.gui_objects.quotadisplay) {
-      if (typeof(content) == 'object' && content.type == 'image')
+      if (typeof content === 'object' && content.type == 'image')
         this.percent_indicator(this.gui_objects.quotadisplay, content);
       else
         $(this.gui_objects.quotadisplay).html(content);
@@ -5122,18 +5127,18 @@
   // compose a valid url with the given parameters
   this.url = function(action, query)
   {
-    var querystring = typeof(query) == 'string' ? '&' + query : '';
-    
-    if (typeof action != 'string')
+    var querystring = typeof query === 'string' ? '&' + query : '';
+
+    if (typeof action !== 'string')
       query = action;
-    else if (!query || typeof(query) != 'object')
+    else if (!query || typeof query !== 'object')
       query = {};
-    
+
     if (action)
       query._action = action;
     else
       query._action = this.env.action;
-    
+
     var base = this.env.comm_path;
 
     // overwrite task name
@@ -5141,14 +5146,14 @@
       query._action = RegExp.$2;
       base = base.replace(/\_task=[a-z]+/, '_task='+RegExp.$1);
     }
-    
+
     // remove undefined values
     var param = {};
     for (var k in query) {
-      if (typeof(query[k]) != 'undefined' && query[k] !== null)
+      if (query[k] !== undefined && query[k] !== null)
         param[k] = query[k];
     }
-    
+
     return base + '&' + $.param(param) + querystring;
   };
 
@@ -5176,7 +5181,7 @@
     // trigger plugin hook
     var result = this.triggerEvent('request'+action, query);
 
-    if (typeof result != 'undefined') {
+    if (result !== undefined) {
       // abort if one the handlers returned false
       if (result === false)
         return false;
@@ -5200,7 +5205,7 @@
   {
     var url = this.url(action);
 
-    if (postdata && typeof(postdata) == 'object') {
+    if (postdata && typeof postdata === 'object') {
       postdata._remote = 1;
       postdata._unlock = (lock ? lock : 0);
     }
@@ -5209,7 +5214,7 @@
 
     // trigger plugin hook
     var result = this.triggerEvent('request'+action, postdata);
-    if (typeof result != 'undefined') {
+    if (result !== undefined) {
       // abort if one the handlers returned false
       if (result === false)
         return false;
@@ -5243,9 +5248,9 @@
       this.set_env(response.env);
 
     // we have labels to add
-    if (typeof response.texts == 'object') {
+    if (typeof response.texts === 'object') {
       for (var name in response.texts)
-        if (typeof response.texts[name] == 'string')
+        if (typeof response.texts[name] === 'string')
           this.add_label(name, response.texts[name]);
     }
 
@@ -5441,7 +5446,7 @@
   // gets cursor position
   this.get_caret_pos = function(obj)
   {
-    if (typeof(obj.selectionEnd)!='undefined')
+    if (obj.selectionEnd !== undefined)
       return obj.selectionEnd;
     else if (document.selection && document.selection.createRange) {
       var range = document.selection.createRange();

--
Gitblit v1.9.1