Source for file imap_search.php

Documentation is available at imap_search.php

  1. <?php
  2.  
  3. /**
  4.  * imap_search.php
  5.  *
  6.  * Copyright (c) 1999-2006 The SquirrelMail Project Team
  7.  * Licensed under the GNU GPL. For full terms see the file COPYING.
  8.  *
  9.  * IMAP search routines
  10.  *
  11.  * @version $Id: imap_search.php,v 1.63.2.7 2006/02/03 22:27:47 jervfors Exp $
  12.  * @package squirrelmail
  13.  * @subpackage imap
  14.  * @deprecated This search interface has been largely replaced by asearch
  15.  */
  16.  
  17. /**
  18.  * Load up a bunch of SM functions */
  19.  
  20. require_once(SM_PATH 'functions/imap.php');
  21. require_once(SM_PATH 'functions/date.php');
  22. require_once(SM_PATH 'functions/mailbox_display.php');
  23. require_once(SM_PATH 'functions/mime.php');
  24.  
  25. function sqimap_search($imapConnection$search_where$search_what$mailbox,
  26.                        $color$search_position ''$search_all$count_all{
  27.  
  28.     global $message_highlight_list$squirrelmail_language$languages,
  29.            $index_order$pos$allow_charset_search$uid_support,
  30.        $imap_server_type;
  31.  
  32.     $pos $search_position;
  33.  
  34.     $urlMailbox urlencode($mailbox);
  35.  
  36.     /* construct the search query, taking multiple search terms into account */
  37.     $multi_search array();
  38.     $search_what  trim($search_what);
  39.     $search_what  ereg_replace('[ ]{2,}'' '$search_what);
  40.     $multi_search explode(' '$search_what);
  41.     $search_string '';
  42.  
  43.     /* it seems macosx and hmailserver do not support the prefered search
  44.        syntax so we fall back to the older style. This IMAP
  45.        server has a problem with multiple search terms. Instead
  46.        of returning the messages that match all the terms it
  47.        returns the messages that match each term. Could be fixed
  48.        on the client side, but should be fixed on the server
  49.        as per the RFC */
  50.  
  51.     if ($imap_server_type == 'macosx' || $imap_server_type == 'hmailserver'{
  52.         foreach ($multi_search as $multi_search_part{
  53.             if (strtoupper($languages[$squirrelmail_language]['CHARSET']== 'ISO-2022-JP'{
  54.                 $multi_search_part mb_convert_encoding($multi_search_part'JIS''auto');
  55.             }
  56.             $search_string .= $search_where ' ' .$multi_search_part ' ';
  57.         }
  58.     }
  59.     else {
  60.         foreach ($multi_search as $multi_search_part{
  61.             if (strtoupper($languages[$squirrelmail_language]['CHARSET']== 'ISO-2022-JP'{
  62.                 $multi_search_part mb_convert_encoding($multi_search_part'JIS''auto');
  63.             }
  64.             $search_string .= $search_where ' {' strlen($multi_search_part)
  65.                 . "}\r\n" $multi_search_part ' ';
  66.         }
  67.     }
  68.  
  69.     $search_string trim($search_string);
  70.  
  71.     /* now use $search_string in the imap search */
  72.     if ($allow_charset_search && isset($languages[$squirrelmail_language]['CHARSET']&&
  73.         $languages[$squirrelmail_language]['CHARSET']{
  74.         $ss "SEARCH CHARSET "
  75.             . strtoupper($languages[$squirrelmail_language]['CHARSET'])
  76.             . " ALL $search_string";
  77.     else {
  78.         $ss "SEARCH ALL $search_string";
  79.     }
  80.  
  81.     /* read data back from IMAP */
  82.     $readin sqimap_run_command($imapConnection$ssfalse$result$message$uid_support);
  83.  
  84.     /* try US-ASCII charset if search fails */
  85.     if (isset($languages[$squirrelmail_language]['CHARSET'])
  86.         && strtolower($result== 'no'{
  87.         $ss "SEARCH CHARSET \"US-ASCII\" ALL $search_string";
  88.         $readin sqimap_run_command ($imapConnection$sstrue,
  89.                                       $result$message$uid_support);
  90.     }
  91.  
  92.     unset($messagelist);
  93.  
  94.     /* Keep going till we find the SEARCH response */
  95.     foreach ($readin as $readin_part{
  96.         /* Check to see if a SEARCH response was received */
  97.         if (substr($readin_part09== '* SEARCH '{
  98.             $messagelist preg_split("/ /"substr($readin_part9));
  99.         else if (isset($errors)) {
  100.             $errors $errors.$readin_part;
  101.         else {
  102.             $errors $readin_part;
  103.         }
  104.     }
  105.  
  106.     /* If nothing is found * SEARCH should be the first error else echo errors */
  107.     if (isset($errors)) {
  108.         if (strstr($errors,'* SEARCH')) {
  109.             return array();
  110.         }
  111.         echo '<!-- '.htmlspecialchars($errors.' -->';
  112.     }
  113.  
  114.  
  115.     global $sent_folder;
  116.  
  117.     $cnt count($messagelist);
  118.     for ($q 0$q $cnt$q++{
  119.         $id[$qtrim($messagelist[$q]);
  120.     }
  121.     $issent ($mailbox == $sent_folder);
  122.  
  123.     $msgs fillMessageArray($imapConnection,$id,$cnt);
  124.  
  125.     return $msgs;
  126. }
  127.  
  128.  
  129.  
  130. ?>

Documentation generated on Sat, 07 Oct 2006 16:31:49 +0300 by phpDocumentor 1.3.0RC6