Fix IMAP parsing to properly match Non-FETCH reponses.
[squirrelmail.git] / functions / imap_search.php
index 37205c861efc4491b96a974bcea63522e14f73f4..858e3beebe980a82510ccadfa47a1b58b13f144a 100644 (file)
@@ -19,8 +19,8 @@ require_once('../functions/mime.php');
 
 function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$color, $search_position = '', $search_all, $count_all) {
 
-    global $msgs, $message_highlight_list, $squirrelmail_language, $languages, $index_order;
-    global $pos;
+    global $msgs, $message_highlight_list, $squirrelmail_language, $languages, $index_order,
+           $pos;
 
     $pos = $search_position;
 
@@ -42,20 +42,20 @@ function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$colo
             $search_string = '';
     $count = count($multi_search);
             for ($x=0;$x<$count;$x++) {
-                $search_string = $search_string . ' ' . $search_where . ' "' . $multi_search[$x] . '" ';
+                trim($multi_search[$x]);
+                $search_string = $search_string . ' ' . $search_where . ' "' . $multi_search[$x] . '"';
             }
     }
     $search_string = trim($search_string);
 
-    /* now use $search_string in the imap search */
+/* now use $search_string in the imap search */
 
     if (isset($languages[$squirrelmail_language]['CHARSET']) &&
         $languages[$squirrelmail_language]['CHARSET']) {
         $ss = "SEARCH CHARSET ".$languages[$squirrelmail_language]['CHARSET']." ALL $search_string";
     } else {
-        $ss .= "SEARCH ALL $search_string\"";
+        $ss .= "SEARCH ALL $search_string";
     }
-
     /* Read Data Back From IMAP */
     $readin = sqimap_run_command ($imapConnection, $ss, true, $result, $message);
     if (isset($languages[$squirrelmail_language]['CHARSET']) && strtolower($result) == 'no') {
@@ -195,7 +195,12 @@ function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$colo
                 -1,
                 '<b>' . _("Found") . ' ' . count($messagelist) . ' ' . _("messages") . '</b></tr><tr>');
         }
-        echo '<b><big>' . _("Folder:") . " $mailbox</big></b>";
+        if ( $mailbox == 'INBOX' ) {
+            $showbox = _("INBOX");
+        } else {
+            $showbox = $mailbox;
+        }
+        echo '<b><big>' . _("Folder:") . " $showbox</big></b>";
         while ($j < count($msgs)) {
             printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, '', 0, $search_where, $search_what);
             $j++;