From 02f762831461233809c95189b1b4e9a647e22944 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 03 Sep 2014 07:01:38 -0400
Subject: [PATCH] Fix page title when using search filter (#1490023)

---
 CHANGELOG                             |    1 +
 program/steps/mail/list.inc           |   10 +++++-----
 program/steps/mail/search.inc         |    9 +++++++--
 program/steps/mail/func.inc           |   27 ++++++++++++++++++++++-----
 program/localization/en_US/labels.inc |    2 +-
 5 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index f2dcade..d59ae5b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -47,6 +47,7 @@
 - Optimize some framed pages content for better performance (#1489792)
 - Improve text messages display and conversion to HTML (#1488937)
 - Don't remove links when html signature is converted to text (#1489621)
+- Fix page title when using search filter (#1490023)
 - Fix mbox files import
 - Fix some mime-type to extension mapping checks in Installer (#1489983)
 - Fix errors when using localStorage in Safari's private browsing mode (#1489996)
diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc
index 720d7ab..f1ef5f4 100644
--- a/program/localization/en_US/labels.inc
+++ b/program/localization/en_US/labels.inc
@@ -338,7 +338,7 @@
 $labels['spouse'] = 'Spouse';
 $labels['allfields'] = 'All fields';
 $labels['search'] = 'Search';
-$labels['searchfor'] = 'Search for "$q"';
+$labels['searchresult'] = 'Search result';
 $labels['advsearch'] = 'Advanced Search';
 $labels['advanced'] = 'Advanced';
 $labels['other'] = 'Other';
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index a7c483b..25f2e31 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -79,6 +79,8 @@
 
         if (!empty($_SESSION['search_scope']))
             $OUTPUT->set_env('search_scope', $_SESSION['search_scope']);
+
+        rcmail_list_pagetitle();
     }
 
     $threading = (bool) $RCMAIL->storage->get_threading();
@@ -119,11 +121,6 @@
             'flagged', 'unflagged', 'unread', 'deleted', 'replied', 'forwarded',
             'priority', 'withattachment', 'fileuploaderror');
     }
-
-    $pagetitle = $RCMAIL->localize_foldername($mbox_name, true);
-    $pagetitle = str_replace($delimiter, " \xC2\xBB ", $pagetitle);
-
-    $OUTPUT->set_pagetitle($pagetitle);
 }
 
 // register UI objects
@@ -218,6 +215,26 @@
 }
 
 /**
+ * Sets page title
+ */
+function rcmail_list_pagetitle()
+{
+    global $RCMAIL;
+
+    if ($RCMAIL->output->get_env('search_request')) {
+        $pagetitle = $RCMAIL->gettext('searchresult');
+    }
+    else {
+        $mbox_name = $RCMAIL->storage->get_folder();
+        $delimiter = $RCMAIL->storage->get_hierarchy_delimiter();
+        $pagetitle = $RCMAIL->localize_foldername($mbox_name, true);
+        $pagetitle = str_replace($delimiter, " \xC2\xBB ", $pagetitle);
+    }
+
+    $RCMAIL->output->set_pagetitle($pagetitle);
+}
+
+/**
  * Returns default search mods
  */
 function rcmail_search_mods()
diff --git a/program/steps/mail/list.inc b/program/steps/mail/list.inc
index 2dcc40d..32197bd 100644
--- a/program/steps/mail/list.inc
+++ b/program/steps/mail/list.inc
@@ -81,6 +81,7 @@
 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'])
     && $_SESSION['search_request'] == $_REQUEST['_search']
 ) {
+    $search_request = $_REQUEST['_search'];
     $_SESSION['search'] = $RCMAIL->storage->get_search_set();
 }
 // remove old search data
@@ -88,13 +89,12 @@
     $RCMAIL->session->remove('search');
 }
 
-// empty result? we'll skip UNSEEN counting in rcmail_send_unread_count()
-if (empty($search_request) && empty($a_headers)) {
-    $unseen = 0;
-}
+rcmail_list_pagetitle();
 
 // update mailboxlist
-rcmail_send_unread_count($mbox_name, !empty($_REQUEST['_refresh']), $unseen);
+if (empty($search_request)) {
+    rcmail_send_unread_count($mbox_name, !empty($_REQUEST['_refresh']), empty($a_headers) ? 0 : null);
+}
 
 // update message count display
 $pages  = ceil($count/$RCMAIL->storage->get_pagesize());
diff --git a/program/steps/mail/search.inc b/program/steps/mail/search.inc
index b505934..d88e575 100644
--- a/program/steps/mail/search.inc
+++ b/program/steps/mail/search.inc
@@ -187,8 +187,6 @@
     }
 }
 
-$OUTPUT->set_pagetitle($RCMAIL->gettext(array('name' => 'searchfor', 'vars' => array('q' => $str))));
-
 // update message count display
 $OUTPUT->set_env('search_request', $search_str ? $search_request : '');
 $OUTPUT->set_env('search_filter', $_SESSION['search_filter']);
@@ -198,6 +196,13 @@
 $OUTPUT->set_env('exists', $mbox === null ? 0 : $RCMAIL->storage->count($mbox, 'EXISTS'));
 $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count, 1), $mbox);
 
+rcmail_list_pagetitle();
+
+// update unseen messages count
+if (empty($search_str)) {
+    rcmail_send_unread_count($mbox, false, empty($result_h) ? 0 : null);
+}
+
 if (!$result->incomplete) {
     $OUTPUT->command('set_quota', $RCMAIL->quota_content(null, $result->multi ? 'INBOX' : $mbox));
 }

--
Gitblit v1.9.1