fsf changes, meant to be rebased on upstream
[squirrelmail.git] / functions / imap_asearch.php
index 7867335d1f5d4b8d824c2f07f418d59a1422163d..4002793b3a1dda5198bfc975836c5f8c704a5491 100644 (file)
@@ -3,25 +3,24 @@
 /**
  * imap_search.php
  *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
  * IMAP asearch routines
  *
  * Subfolder search idea from Patch #806075 by Thomas Pohl xraven at users.sourceforge.net. Thanks Thomas!
  *
+ * @author Alex Lemaresquier - Brainstorm <alex at brainstorm.fr>
+ * @copyright 1999-2021 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
  * @subpackage imap
  * @see search.php
  * @link http://www.ietf.org/rfc/rfc3501.txt
- * @author Alex Lemaresquier - Brainstorm - alex at brainstorm.fr
  */
 
 /** This functionality requires the IMAP and date functions
  */
-require_once(SM_PATH . 'functions/imap_general.php');
-require_once(SM_PATH . 'functions/date.php');
+//require_once(SM_PATH . 'functions/imap_general.php');
+//require_once(SM_PATH . 'functions/date.php');
 
 /** Set to TRUE to dump the IMAP dialogue
  * @global bool $imap_asearch_debug_dump
@@ -122,23 +121,7 @@ function sqimap_asearch_error_box($response, $query, $message, $link = '')
     else
         $message_title = _("Possible reason:");
     $message_title .= ' ';
-    if (function_exists('sqimap_error_box'))
-        sqimap_error_box($title, $query, $message_title, $message, $link);
-    else {    //Straight copy of 1.5 imap_general.php:sqimap_error_box(). Can be removed at a later time
-        global $color;
-    require_once(SM_PATH . 'functions/display_messages.php');
-    $string = "<font color=\"$color[2]\"><b>\n" . $title . "</b><br />\n";
-    if ($query != '')
-        $string .= _("Query:") . ' ' . htmlspecialchars($query) . '<br />';
-    if ($message_title != '')
-        $string .= $message_title;
-    if ($message != '')
-        $string .= htmlspecialchars($message);
-    if ($link != '')
-        $string .= $link;
-    $string .= "</font><br />\n";
-    error_box($string,$color);
-    }
+    sqimap_error_box($title, $query, $message_title, $message, $link);
 }
 
 /**
@@ -171,27 +154,6 @@ function asearch_unhtmlentities($string) {
  */
 }
 
-/**
- * Provide an easy way to dump the IMAP dialogue if $imap_asearch_debug_dump is TRUE
- * @global bool imap_asearch_debug_dump
- * @param string $var_name
- * @param string $var_var
- */
-function s_debug_dump($var_name, $var_var)
-{
-    global $imap_asearch_debug_dump;
-    if ($imap_asearch_debug_dump) {
-        if (function_exists('sm_print_r'))      //Only exists since 1.4.2
-            sm_print_r($var_name, $var_var);    //Better be the 'varargs' version ;)
-        else {
-            echo '<pre>';
-            echo htmlentities($var_name);
-            print_r($var_var);
-            echo '</pre>';
-        }
-    }
-}
-
 /** Encode a string to quoted or literal as defined in rfc 3501
  *
  * -  4.3 String:
@@ -228,7 +190,7 @@ function sqimap_asearch_parse_date($what)
     global $imap_asearch_months;
 
     $what = trim($what);
-    $what = ereg_replace('[ /\\.,]+', '-', $what);
+    $what = preg_replace('/[ \/\\.,]+/', '-', $what);
     if ($what) {
         preg_match('/^([0-9]+)-+([^\-]+)-+([0-9]+)$/', $what, $what_parts);
         if (count($what_parts) == 4) {
@@ -270,7 +232,7 @@ function sqimap_asearch_build_criteria($opcode, $what, $charset)
         default:
         case 'anum':
             $what = str_replace(' ', '', $what);
-            $what = ereg_replace('[^0-9]+[^KMG]$', '', strtoupper($what));
+            $what = preg_replace('/[^0-9]+[^KMG]$/', '', strtoupper($what));
             if ($what != '') {
                 switch (substr($what, -1)) {
                     case 'G':
@@ -306,7 +268,7 @@ function sqimap_asearch_build_criteria($opcode, $what, $charset)
             $criteria = $opcode . ' ' . sqimap_asearch_encode_string($what, $charset) . ' ';
         break;
         case 'asequence':
-            $what = ereg_replace('[^0-9:\(\)]+', '', $what);
+            $what = preg_replace('/[^0-9:()]+/', '', $what);
             if ($what != '')
                 $criteria = $opcode . ' ' . $what . ' ';
         break;
@@ -351,14 +313,12 @@ function sqimap_run_search($imapConnection, $search_string, $search_charset)
         $query = 'SEARCH CHARSET "' . strtoupper($search_charset) . '" ' . $search_string;
     else
         $query = 'SEARCH ' . $search_string;
-    s_debug_dump('C:', $query);
-    $readin = sqimap_run_command($imapConnection, $query, false, $response, $message, TRUE);
+    $readin = sqimap_run_command_list($imapConnection, $query, false, $response, $message, TRUE);
 
     /* 6.4.4 try US-ASCII charset if we tried an OPTIONAL [CHARSET] and received a tagged NO response (SHOULD be [BADCHARSET]) */
     if (($search_charset != '')  && (strtoupper($response) == 'NO')) {
         $query = 'SEARCH CHARSET US-ASCII ' . $search_string;
-        s_debug_dump('C:', $query);
-        $readin = sqimap_run_command($imapConnection, $query, false, $response, $message, TRUE);
+        $readin = sqimap_run_command_list($imapConnection, $query, false, $response, $message, TRUE);
     }
     if (strtoupper($response) != 'OK') {
         sqimap_asearch_error_box($response, $query, $message);
@@ -408,6 +368,7 @@ function sqimap_asearch_get_sort_criteria($mailbox, $sort_by)
     $sort_opcodes = array ('DATE', 'FROM', 'SUBJECT', 'SIZE');
     if ($internal_date_sort == true)
         $sort_opcodes[0] = 'ARRIVAL';
+// FIXME: Why are these commented out?  I have no idea what this code does, but both of these functions sound more robust than the simple string check that's being used now.  Someone who understands this code should either fix this or remove these lines completely or document why they are here commented out
 //        if (handleAsSent($mailbox))
 //        if (isSentFolder($mailbox))
     if ($mailbox == $sent_folder)
@@ -476,6 +437,7 @@ function sqimap_asearch($imapConnection, &$mailbox_array, &$biop_array, &$unop_a
                 $search_string = '';
             }
             if (isset($where_array[$cur_crit]) && empty($exclude_array[$cur_crit])) {
+                $aCriteria = array();
                 for ($crit = $cur_crit; $crit < count($where_array); $crit++) {
                     $criteria = trim(sqimap_asearch_build_criteria($where_array[$crit], $what_array[$crit], $search_charset));
                     if (!empty($criteria) && empty($exclude_array[$crit])) {
@@ -525,5 +487,3 @@ function sqimap_asearch($imapConnection, &$mailbox_array, &$biop_array, &$unop_a
     }
     return ($mbox_search);
 }
-
-?>
\ No newline at end of file