From 6884f3f1f7542eb1dab8bb39cab33888d3fd84c5 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Mon, 20 Jan 2014 05:41:58 -0500
Subject: [PATCH] Re-submit search query when switching folders

---
 program/steps/mail/search.inc |    2 ++
 program/js/app.js             |   28 ++++++++++++++++++----------
 skins/larry/ui.js             |    2 +-
 3 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index 2401e1e..e276f6f 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -697,9 +697,17 @@
         break;
 
       case 'list':
-        // TODO: don't reset search but re-send for the new folder
-        if (props && props != '')
-          this.reset_qsearch();
+        // re-send for the selected folder
+        if (props && props != '' && this.env.search_request) {
+          var oldmbox = this.env.search_scope == 'all' ? '*' : this.env.mailbox;
+          this.env.search_mods[props] = this.env.search_mods[oldmbox];  // copy search mods from active search
+          this.env.mailbox = props;
+          this.env.search_scope = 'base';
+          this.qsearch(this.gui_objects.qsearchbox.value);
+          this.select_folder(this.env.mailbox, '', true);
+          break;
+        }
+
         if (this.env.action == 'compose' && this.env.extwin)
           window.close();
         else if (this.task == 'mail') {
@@ -4100,11 +4108,11 @@
   };
 
   // send remote request to search mail or contacts
-  this.qsearch = function(value)
+  this.qsearch = function(value, mods)
   {
     if (value != '') {
       var r, lock = this.set_busy(true, 'searching'),
-        url = this.search_params(value);
+        url = this.search_params(value, null, mods);
 
       if (this.message_list)
         this.clear_message_list();
@@ -4128,7 +4136,7 @@
   };
 
   // build URL params for search
-  this.search_params = function(search, filter)
+  this.search_params = function(search, filter, smods)
   {
     var n, url = {}, mods_arr = [],
       mods = this.env.search_mods,
@@ -4147,11 +4155,11 @@
     if (search) {
       url._q = search;
 
-      if (mods && this.message_list)
-        mods = mods[mbox] ? mods[mbox] : mods['*'];
+      if (!smods && mods && this.message_list)
+        smods = mods[mbox] || mods['*'];
 
-      if (mods) {
-        for (n in mods)
+      if (smods) {
+        for (n in smods)
           mods_arr.push(n);
         url._headers = mods_arr.join(',');
       }
diff --git a/program/steps/mail/search.inc b/program/steps/mail/search.inc
index 88bbe6e..51dab7d 100644
--- a/program/steps/mail/search.inc
+++ b/program/steps/mail/search.inc
@@ -21,6 +21,8 @@
 
 $REMOTE_REQUEST = TRUE;
 
+@set_time_limit(170);  // extend default max_execution_time to ~3 minutes
+
 // reset list_page and old search results
 $RCMAIL->storage->set_page(1);
 $RCMAIL->storage->set_search_set(NULL);
diff --git a/skins/larry/ui.js b/skins/larry/ui.js
index 2030b05..e5fce91 100644
--- a/skins/larry/ui.js
+++ b/skins/larry/ui.js
@@ -769,7 +769,7 @@
           mbox = '*';
         mods = mods[mbox] ? mods[mbox] : mods['*'];
         all = 'text';
-        $('#s_scope_'+scope).prop('checked', true);
+        $('#s_scope_'+scope).attr('checked',true);
       }
       else {
         all = '*';

--
Gitblit v1.9.1