From ef4998c11084b2c99f8af9976f9860d5f7709a0f Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Thu, 22 Sep 2011 04:48:05 -0400
Subject: [PATCH] Fix compose command from other tasks than mail and address book; skip common request parameters

---
 program/js/app.js |  108 ++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 76 insertions(+), 32 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index 44d5823..6acb48d 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -847,6 +847,8 @@
 
           break;
         }
+        else if (props)
+          url += '&_to='+urlencode(props);
 
         this.redirect(url);
         break;
@@ -1641,6 +1643,10 @@
     if (!this.gui_objects.messagelist || !this.message_list)
       return false;
 
+    // Prevent from adding messages from different folder (#1487752)
+    if (flags.mbox != this.env.mailbox && !flags.skip_mbox_check)
+      return false;
+
     if (!this.env.messages[uid])
       this.env.messages[uid] = {};
 
@@ -2091,8 +2097,12 @@
   };
 
   // Initializes threads indicators/expanders after list update
-  this.init_threads = function(roots)
+  this.init_threads = function(roots, mbox)
   {
+    // #1487752
+    if (mbox && mbox != this.env.mailbox)
+      return false;
+
     for (var n=0, len=roots.length; n<len; n++)
       this.add_tree_icons(roots[n]);
     this.expand_threads();
@@ -3156,7 +3166,7 @@
         sig = this.env.signatures[sig].is_html ? this.env.signatures[sig].plain_text : this.env.signatures[sig].text;
         sig = sig.replace(/\r\n/g, '\n');
 
-        if (!sig.match(/^--[ -]\n/))
+        if (!sig.match(/^--[ -]\n/m))
           sig = sig_separator + '\n' + sig;
 
         p = this.env.sig_above ? message.indexOf(sig) : message.lastIndexOf(sig);
@@ -3168,7 +3178,7 @@
         sig = this.env.signatures[id]['is_html'] ? this.env.signatures[id]['plain_text'] : this.env.signatures[id]['text'];
         sig = sig.replace(/\r\n/g, '\n');
 
-        if (!sig.match(/^--[ -]\n/))
+        if (!sig.match(/^--[ -]\n/m))
           sig = sig_separator + '\n' + sig;
 
         if (this.env.sig_above) {
@@ -3237,12 +3247,12 @@
       if (this.env.signatures[id]) {
         if (this.env.signatures[id].is_html) {
           sig = this.env.signatures[id].text;
-          if (!this.env.signatures[id].plain_text.match(/^--[ -]\r?\n/))
+          if (!this.env.signatures[id].plain_text.match(/^--[ -]\r?\n/m))
             sig = sig_separator + '<br />' + sig;
         }
         else {
           sig = this.env.signatures[id].text;
-          if (!sig.match(/^--[ -]\r?\n/))
+          if (!sig.match(/^--[ -]\r?\n/m))
             sig = sig_separator + '\n' + sig;
           sig = '<pre>' + sig + '</pre>';
         }
@@ -3495,13 +3505,15 @@
 
         return rcube_event.cancel(e);
 
-      case 9:  // tab
-        if (mod == SHIFT_KEY)
-          break;
+      case 9:   // tab
+        if (mod == SHIFT_KEY || !this.ksearch_visible()) {
+          this.ksearch_hide();
+          return;
+        }
 
       case 13:  // enter
-        if (this.ksearch_selected === null || !this.ksearch_value)
-          break;
+        if (!this.ksearch_visible())
+          return false;
 
         // insert selected address and hide ksearch pane
         this.insert_recipient(this.ksearch_selected);
@@ -3524,6 +3536,11 @@
     this.ksearch_input = obj;
 
     return true;
+  };
+
+  this.ksearch_visible = function()
+  {
+    return (this.ksearch_selected !== null && this.ksearch_selected !== undefined && this.ksearch_value);
   };
 
   this.ksearch_select = function(node)
@@ -3612,21 +3629,18 @@
     if (q == this.ksearch_value)
       return;
 
+    this.ksearch_destroy();
+
     if (q.length && q.length < min) {
-      if (!this.env.acinfo) {
-        this.env.acinfo = this.display_message(
+      if (!this.ksearch_info) {
+        this.ksearch_info = this.display_message(
           this.get_label('autocompletechars').replace('$min', min));
       }
       return;
     }
-    else if (this.env.acinfo) {
-      this.hide_message(this.env.acinfo);
-    }
 
     var old_value = this.ksearch_value;
     this.ksearch_value = q;
-
-    this.ksearch_destroy();
 
     // ...string is empty
     if (!q.length)
@@ -3668,7 +3682,9 @@
       return;
 
     // display search results
-    var p, ul, li, text, init, s_val = this.ksearch_value,
+    var ul, li, text, init,
+      value = this.ksearch_value,
+      data = this.ksearch_data,
       maxlen = this.env.autocomplete_max ? this.env.autocomplete_max : 15;
 
     // create results pane if not present
@@ -3701,7 +3717,7 @@
       for (i=0; i < results.length && maxlen > 0; i++) {
         text = typeof results[i] === 'object' ? results[i].name : 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.innerHTML = text.replace(new RegExp('('+RegExp.escape(value)+')', 'ig'), '##$1%%').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/##([^%]+)%%/g, '<b>$1</b>');
         li.onmouseover = function(){ ref.ksearch_select(this); };
         li.onmouseup = function(){ ref.ksearch_click(this) };
         li._rcm_id = this.env.contacts.length + i;
@@ -3723,15 +3739,23 @@
       this.env.contacts = this.env.contacts.concat(results);
 
     // run next parallel search
-    if (maxlen > 0 && this.ksearch_data.id == reqid && this.ksearch_data.sources.length) {
-      var lock, xhr, props = this.ksearch_data, source = props.sources.shift();
-      if (source) {
-        lock = this.display_message(this.get_label('searching'), 'loading');
-        xhr = this.http_post(props.action, '_search='+urlencode(s_val)+'&_id='+reqid
-          +'&_source='+urlencode(source), lock);
+    if (data.id == reqid) {
+      if (maxlen > 0 && data.sources.length) {
+        var lock, xhr, source = data.sources.shift();
+        if (source) {
+          lock = this.display_message(this.get_label('searching'), 'loading');
+          xhr = this.http_post(data.action, '_search='+urlencode(value)+'&_id='+reqid
+            +'&_source='+urlencode(source), lock);
 
-        this.ksearch_data.locks.push(lock);
-        this.ksearch_data.requests.push(xhr);
+          this.ksearch_data.locks.push(lock);
+          this.ksearch_data.requests.push(xhr);
+        }
+      }
+      else if (!maxlen) {
+        if (!this.ksearch_msg)
+          this.ksearch_msg = this.display_message(this.get_label('autocompletemore'));
+        // abort pending searches
+        this.ksearch_abort();
       }
     }
   };
@@ -3765,8 +3789,24 @@
     this.ksearch_destroy();
   };
 
-  // Aborts pending autocomplete requests
+  // Clears autocomplete data/requests
   this.ksearch_destroy = function()
+  {
+    this.ksearch_abort();
+
+    if (this.ksearch_info)
+      this.hide_message(this.ksearch_info);
+
+    if (this.ksearch_msg)
+      this.hide_message(this.ksearch_msg);
+
+    this.ksearch_data = null;
+    this.ksearch_info = null;
+    this.ksearch_msg = null;
+  }
+
+  // Aborts pending autocomplete requests
+  this.ksearch_abort = function()
   {
     var i, len, ac = this.ksearch_data;
 
@@ -3775,9 +3815,8 @@
 
     for (i=0, len=ac.locks.length; i<len; i++)
       this.abort_request({request: ac.requests[i], lock: ac.locks[i]});
+  };
 
-    this.ksearch_data = null;
-  }
 
   /*********************************************************/
   /*********         address book methods          *********/
@@ -3979,7 +4018,8 @@
   {
     // exit if no mailbox specified or if selection is empty
     var selection = this.contact_list.get_selection();
-    if (!(selection.length || this.env.cid) || !confirm(this.get_label('deletecontactconfirm')))
+    var undelete = this.env.address_sources[this.env.source].undelete;
+    if (!(selection.length || this.env.cid) || (!undelete && !confirm(this.get_label('deletecontactconfirm'))))
       return;
 
     var id, n, a_cids = [], qs = '';
@@ -5433,8 +5473,12 @@
   };
 
   // replace content of row count display
-  this.set_rowcount = function(text)
+  this.set_rowcount = function(text, mbox)
   {
+    // #1487752
+    if (mbox && mbox != this.env.mailbox)
+      return false;
+
     $(this.gui_objects.countdisplay).html(text);
 
     // update page navigation buttons

--
Gitblit v1.9.1