Philippe - let's make sure we make this work for BOTH netscape and IE. I will install...
[squirrelmail.git] / functions / imap_search.php
index a92e8970bf65c7c4b52f746ecb381f047edb3247..a546b4e649801647573716a264e8f41ea7abc5e1 100644 (file)
@@ -1,4 +1,4 @@
-<?php 
+<?php
    /******************************************************************
     ** IMAP SEARCH ROUTIES
     ** $Id$
@@ -8,39 +8,43 @@
       return;
    define ('imap_search_php', true);
    
-   include("../functions/imap.php");
-   include("../functions/date.php");
-   include("../functions/array.php");
-   include("../functions/mailbox_display.php");
-   include("../functions/mime.php");
+   require_once('../functions/imap.php');
+   require_once('../functions/date.php');
+   require_once('../functions/array.php');
+   require_once('../functions/mailbox_display.php');
+   require_once('../functions/mime.php');
 
 
 function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$color) {
    global $msgs, $message_highlight_list, $squirrelmail_language, $languages, $index_order;
+
    $urlMailbox = urlencode($mailbox);
-   
-   # Construct the Search QuERY
-   
-   if (isset($languages[$squirrelmail_language]["CHARSET"]) && $languages[$squirrelmail_language]["CHARSET"]) {
-      $ss = "a001 SEARCH CHARSET ".$languages[$squirrelmail_language]["CHARSET"]." ALL $search_where \"$search_what\"\r\n";
+   $isid = sqimap_session_id();
+
+   /* Construct the Search QuERY */
+   $ss = $isid;
+   if (isset($languages[$squirrelmail_language]['CHARSET']) &&
+       $languages[$squirrelmail_language]['CHARSET']) {
+      $ss .= " SEARCH CHARSET ".$languages[$squirrelmail_language]['CHARSET']." ALL $search_where \"$search_what\"\r\n";
    } else {
-      $ss = "a001 SEARCH ALL $search_where \"$search_what\"\r\n";
+      $ss .= " SEARCH ALL $search_where \"$search_what\"\r\n";
    }
    fputs($imapConnection,$ss);
 
    # Read Data Back From IMAP
-   $readin = sqimap_read_data ($imapConnection, "a001", false, $result, $message);
-   if (isset($languages[$squirrelmail_language]["CHARSET"]) && strtolower($result) == "no") { 
-      $ss = "a001 SEARCH CHARSET \"US-ASCII\" ALL $search_where \"$search_what\"\r\n";
+   $readin = sqimap_read_data ($imapConnection, $isid, false, $result, $message);
+   if (isset($languages[$squirrelmail_language]['CHARSET']) && strtolower($result) == 'no') {
+      $ss = $isid . " SEARCH CHARSET \"US-ASCII\" ALL $search_where \"$search_what\"\r\n";
       fputs ($imapConnection, $ss);
-      $readin = sqimap_read_data ($imapConnection, "a001", true, $result, $message);
+      $readin = sqimap_read_data ($imapConnection, $isid, true, $result, $message);
    }
+
    unset($messagelist); $msgs=""; $c = 0;
 
-   #Keep going till we find the SEARCH responce
-   while ($c < count($readin)) {
+   /* Keep going till we find the SEARCH responce */
+   while ($c < count( $readin )) {
 
-      #Check to see if a SEARCH Responce was recived
+      /* Check to see if a SEARCH Responce was recived */
       if (substr($readin[$c],0,9) == "* SEARCH ")
          $messagelist = explode(" ",substr($readin[$c],9));
       else if (isset($errors))
@@ -139,7 +143,7 @@ function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$colo
                 if (!isset ($msg)) { $msg = ""; }
          mail_message_listing_beginning($imapConnection, 
             "move_messages.php?msg=$msg&mailbox=$urlMailbox&where=".urlencode($search_where)."&what=".urlencode($search_what),
-             '', -1, '<b>' . _("Found") . ' ' . count($messagelist) . ' ' . _("messages") . '</b>',
+             $mailbox, -1, '<b>' . _("Found") . ' ' . count($messagelist) . ' ' . _("messages") . '</b>',
              '&nbsp;');
          
  
@@ -147,8 +151,7 @@ function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$colo
             printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, "", 0, $search_where, $search_what);
             $j++;
          }
-         echo "</table>";
-         echo "</tr></td></table>";
+         echo '</table></tr></td></table>';
       }
    }