Source for file imap_search.php

Documentation is available at imap_search.php

  1. <?php
  2.  
  3. /**
  4.  * imap_search.php
  5.  *
  6.  * IMAP search routines
  7.  *
  8.  * @copyright 1999-2014 The SquirrelMail Project Team
  9.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.  * @version $Id: imap_search.php 14422 2014-01-01 20:59:43Z pdontthink $
  11.  * @package squirrelmail
  12.  * @subpackage imap
  13.  * @deprecated This search interface has been largely replaced by asearch
  14.  */
  15.  
  16. /**
  17.  * Load up a bunch of SM functions */
  18.  
  19. require_once(SM_PATH 'functions/imap.php');
  20. require_once(SM_PATH 'functions/date.php');
  21. require_once(SM_PATH 'functions/mailbox_display.php');
  22. require_once(SM_PATH 'functions/mime.php');
  23.  
  24. function sqimap_search($imapConnection$search_where$search_what$mailbox,
  25.                        $color$search_position ''$search_all$count_all{
  26.  
  27.     global $message_highlight_list$squirrelmail_language$languages,
  28.            $index_order$pos$allow_charset_search$uid_support,
  29.        $imap_server_type;
  30.  
  31.     $pos $search_position;
  32.  
  33.     $urlMailbox urlencode($mailbox);
  34.  
  35.     /* construct the search query, taking multiple search terms into account */
  36.     $multi_search array();
  37.     $search_what  trim($search_what);
  38.     $search_what  preg_replace('/[ ]{2,}/'' '$search_what);
  39.     $multi_search explode(' '$search_what);
  40.     $search_string '';
  41.  
  42.     if (strtoupper($languages[$squirrelmail_language]['CHARSET']== 'ISO-2022-JP'{
  43.         foreach($multi_search as $idx=>$search_part{
  44.             $multi_search[$idxmb_convert_encoding($search_part'JIS''auto');
  45.         }
  46.     }
  47.  
  48.     $search_literal array('commands'=>array()'literal_args'=>array());
  49.     $use_search_literal FALSE;
  50.     foreach ($multi_search as $string{
  51.         //FIXME: why JIS?  shouldn't input be in EUC-JP?  this is copied from DEVEL
  52.         if (isset($languages[$squirrelmail_language]['CHARSET']&&
  53.             strtoupper($languages[$squirrelmail_language]['CHARSET']== 'ISO-2022-JP')
  54.             $string mb_convert_encoding($string'JIS''auto');
  55.         if (preg_match('/["\\\\\r\n\x80-\xff]/'$string))
  56.             $use_search_literal TRUE;
  57.         $search_literal['commands'][$search_where;
  58.         $search_literal['literal_args'][$string;
  59.         $search_string .= $search_where
  60.                        . ' "'
  61.                        . str_replace(array('\\''"')array('\\\\''\\"')$string)
  62.                        . '" ';
  63.     }
  64.  
  65.     $search_string trim($search_string);
  66.     $original_search_literal $search_literal;
  67.  
  68.     /* now use $search_string in the imap search */
  69.     if ($allow_charset_search && isset($languages[$squirrelmail_language]['CHARSET']&&
  70.         $languages[$squirrelmail_language]['CHARSET']{
  71.         if ($use_search_literal{
  72.             $search_literal['commands'][0'SEARCH CHARSET '
  73.                 . strtoupper($languages[$squirrelmail_language]['CHARSET'])
  74.                 . ' ALL ' $search_literal['commands'][0];
  75.         else {
  76.             $ss "SEARCH CHARSET "
  77.                 . strtoupper($languages[$squirrelmail_language]['CHARSET'])
  78.                 . " ALL $search_string";
  79.         }
  80.     else {
  81.         if ($use_search_literal{
  82.             $search_literal['commands'][0'SEARCH ALL ' $search_literal['commands'][0];
  83.         else {
  84.             $ss "SEARCH ALL $search_string";
  85.         }
  86.     }
  87.  
  88.     /* read data back from IMAP */
  89.     if ($use_search_literal{
  90.         $readin sqimap_run_literal_command($imapConnection$search_literalfalse$result$message$uid_support);
  91.     else {
  92.         $readin sqimap_run_command($imapConnection$ssfalse$result$message$uid_support);
  93.     }
  94.  
  95.     /* try US-ASCII charset if search fails */
  96.     if (isset($languages[$squirrelmail_language]['CHARSET'])
  97.         && strtolower($result== 'no'{
  98.         if ($use_search_literal{
  99.             $original_search_literal['commands'][0'SEARCH CHARSET "US-ASCII" ALL '
  100.                                                     . $original_search_literal['commands'][0];
  101.         else {
  102.             $ss "SEARCH CHARSET \"US-ASCII\" ALL $search_string";
  103.         }
  104.         if ($use_search_literal{
  105.             $readin sqimap_run_literal_command($imapConnection$search_literalfalse$result$message$uid_support);
  106.         else {
  107.             $readin sqimap_run_command($imapConnection$ssfalse$result$message$uid_support);
  108.         }
  109.     }
  110.  
  111.     unset($messagelist);
  112.  
  113.     /* Keep going till we find the SEARCH response */
  114.     foreach ($readin as $readin_part{
  115.         /* Check to see if a SEARCH response was received */
  116.         if (substr($readin_part09== '* SEARCH '{
  117.             $messagelist preg_split("/ /"substr($readin_part9));
  118.         else if (isset($errors)) {
  119.             $errors $errors.$readin_part;
  120.         else {
  121.             $errors $readin_part;
  122.         }
  123.     }
  124.  
  125.     /* If nothing is found * SEARCH should be the first error else echo errors */
  126.     if (isset($errors)) {
  127.         if (strstr($errors,'* SEARCH')) {
  128.             return array();
  129.         }
  130.         echo '<!-- '.sm_encode_html_special_chars($errors.' -->';
  131.     }
  132.  
  133.  
  134.     global $sent_folder;
  135.  
  136.     $cnt count($messagelist);
  137.     for ($q 0$q $cnt$q++{
  138.         $id[$qtrim($messagelist[$q]);
  139.     }
  140.     $issent ($mailbox == $sent_folder);
  141.  
  142.     $msgs fillMessageArray($imapConnection,$id,$cnt);
  143.  
  144.     return $msgs;
  145. }

Documentation generated on Thu, 24 Jul 2014 04:21:08 +0200 by phpDocumentor 1.4.3