Minor cleanups
[squirrelmail.git] / functions / imap_asearch.php
index 1b129564c100dbae6dc0d4c84718763de5aa19ee..a1238c37db0056222126a89737f88af2107eb13f 100644 (file)
@@ -31,6 +31,7 @@ $imap_asearch_debug_dump = FALSE;
 /** Imap SEARCH keys
 * @global array $imap_asearch_opcodes
 */
+global $imap_asearch_opcodes;
 $imap_asearch_opcodes = array(
 /* <sequence-set> => 'asequence', */   // Special handling, @see sqimap_asearch_build_criteria()
 /*'ALL' is binary operator */
@@ -88,17 +89,6 @@ $imap_asearch_months = array(
     '12' => 'dec'
 );
 
-/** Error message titles according to imap server returned code
-* @global array $imap_error_titles
-*/
-$imap_error_titles = array(
-    'OK' => '',
-    'NO' => _("ERROR : Could not complete request."),
-    'BAD' => _("ERROR : Bad or malformed request."),
-    'BYE' => _("ERROR : Imap server closed the connection."),
-    '' => _("ERROR : Connection dropped by imap-server.")
-);
-
 /**
 * Function to display an error related to an IMAP-query.
 * We need to do our own error management since we may receive NO responses on purpose (even BAD with SORT or THREAD)
@@ -112,7 +102,16 @@ $imap_error_titles = array(
 //@global array color sm colors array
 function sqimap_asearch_error_box($response, $query, $message, $link = '')
 {
-    global $imap_error_titles;
+    global $color;
+    // Error message titles according to imap server returned code
+    $imap_error_titles = array(
+        'OK' => '',
+        'NO' => _("ERROR : Could not complete request."),
+        'BAD' => _("ERROR : Bad or malformed request."),
+        'BYE' => _("ERROR : Imap server closed the connection."),
+        '' => _("ERROR : Connection dropped by imap-server.")
+    );
+
 
     if (!array_key_exists($response, $imap_error_titles))
         $title = _("ERROR : Unknown imap response.");
@@ -127,16 +126,16 @@ function sqimap_asearch_error_box($response, $query, $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";
+    $string = "<font color=\"$color[2]\"><b>\n" . $title . "</b><br />\n";
     if ($query != '')
-        $string .= _("Query:") . ' ' . htmlspecialchars($query) . '<br>';
+        $string .= _("Query:") . ' ' . htmlspecialchars($query) . '<br />';
     if ($message_title != '')
         $string .= $message_title;
     if ($message != '')
         $string .= htmlspecialchars($message);
     if ($link != '')
         $string .= $link;
-    $string .= "</font><br>\n";
+    $string .= "</font><br />\n";
     error_box($string,$color);
     }
 }
@@ -459,7 +458,7 @@ function sqimap_asearch($imapConnection, &$mailbox_array, &$biop_array, &$unop_a
             if ($next_mailbox != $cur_mailbox) {
                 $search_string = trim($search_string); /* Trim out last space */
                 if ($cur_mailbox == 'All Folders')
-                        $search_mboxes = $mboxes_array;
+                    $search_mboxes = $mboxes_array;
                 else if ((!empty($sub_array[$cur_crit - 1])) || (!in_array($cur_mailbox, $mboxes_array)))
                     $search_mboxes = sqimap_asearch_get_sub_mailboxes($cur_mailbox, $mboxes_array);
                 else
@@ -474,7 +473,6 @@ function sqimap_asearch($imapConnection, &$mailbox_array, &$biop_array, &$unop_a
                 }
                 $cur_mailbox = $next_mailbox;
                 $search_string = '';
-
             }
             if (isset($where_array[$cur_crit]) && empty($exclude_array[$cur_crit])) {
                 for ($crit = $cur_crit; $crit < count($where_array); $crit++) {
@@ -499,7 +497,7 @@ function sqimap_asearch($imapConnection, &$mailbox_array, &$biop_array, &$unop_a
                         $aSearch[] = 'OR '.$aCriteria[$i][1];
                     } else if ($cur_biop != 'OR') {
                         $aSearch[] = 'ALL '.$aCriteria[$i][1];
-                    } else { // or only supports 2 search keys so we need to create a parenthized list
+                    } else { // OR only supports 2 search keys so we need to create a parenthesized list
                         $prev_biop = (isset($aCriteria[$i-1][0])) ? $aCriteria[$i-1][0] : false;
                         if ($prev_biop == $cur_biop) {
                             $last = $aSearch[$i-1];
@@ -509,8 +507,8 @@ function sqimap_asearch($imapConnection, &$mailbox_array, &$biop_array, &$unop_a
                             } else {
                                 $sEnd = '';
                                 while ($last && substr($last,-1) == ')') {
-                                $last = substr($last,0,-1);
-                                $sEnd .= ')';
+                                    $last = substr($last,0,-1);
+                                    $sEnd .= ')';
                                 }
                                 $aSearch[$i-1] = "(OR $last";
                                 $aSearch[] = $aCriteria[$i][1].$sEnd.')';
@@ -519,14 +517,12 @@ function sqimap_asearch($imapConnection, &$mailbox_array, &$biop_array, &$unop_a
                             $aSearch[] = $aCriteria[$i][1];
                         }
                     }
-
                 }
                 $search_string .= implode(' ',$aSearch);
             }
-
         }
     }
     return ($mbox_search);
 }
 
-?>
+?>
\ No newline at end of file