From: Marc G. K. <st...@us...> - 2004-06-06 01:43:43
|
Update of /cvsroot/squirrelmail/squirrelmail/functions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18649/functions Modified Files: imap_asearch.php Log Message: Fixed created search strings. Index: imap_asearch.php =================================================================== RCS file: /cvsroot/squirrelmail/squirrelmail/functions/imap_asearch.php,v retrieving revision 1.27 retrieving revision 1.28 diff -u -w -r1.27 -r1.28 --- imap_asearch.php 31 May 2004 20:07:43 -0000 1.27 +++ imap_asearch.php 6 Jun 2004 01:43:35 -0000 1.28 @@ -455,7 +455,7 @@ /* We loop one more time than the real array count, so the last search gets fired */ for ($cur_crit=0,$iCnt=count($where_array); $cur_crit <= $iCnt; ++$cur_crit) { if (empty($exclude_array[$cur_crit])) { - $next_mailbox = $mailbox_array[$cur_crit]; + $next_mailbox = (isset($mailbox_array[$cur_crit])) ? $mailbox_array[$cur_crit] : false; if ($next_mailbox != $cur_mailbox) { $search_string = trim($search_string); /* Trim out last space */ if ($cur_mailbox == 'All Folders') @@ -477,35 +477,51 @@ } if (isset($where_array[$cur_crit]) && empty($exclude_array[$cur_crit])) { - $criteria = sqimap_asearch_build_criteria($where_array[$cur_crit], $what_array[$cur_crit], $search_charset); - if (!empty($criteria)) { - //$criteria = 'ALL '. $criteria; - $unop = $unop_array[$cur_crit]; + 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])) { + if (asearch_nz($mailbox_array[$crit]) == $cur_mailbox) { + $unop = $unop_array[$crit]; if (!empty($unop)) { $criteria = $unop . ' ' . $criteria; - } else { - $criteria = 'ALL ' . $criteria; } - /* We need to infix the next non-excluded criteria's biop if it's the same mailbox */ - $next_biop = ''; - for ($next_crit = $cur_crit+1; $next_crit <= count($where_array); $next_crit++) { - if (empty($exclude_array[$next_crit])) { - if (asearch_nz($mailbox_array[$next_crit]) == $cur_mailbox) { - $next_biop = asearch_nz($biop_array[$next_crit]); - if ($next_biop == 'OR' || $next_biop == 'ALL') { - $next_criterium = sqimap_asearch_build_criteria($where_array[$next_crit], $what_array[$next_crit], $search_charset); + $aCriteria[] = array($biop_array[$crit], $criteria); + } + } // unset something - $exclude_array[$next_crit] = true; - $criteria .= $next_biop . ' '. $next_criterium; + $exclude_array[$crit] = true; } + $aSearch = array(); + for($i=0,$iCnt=count($aCriteria);$i<$iCnt;++$i) { + $cur_biop = $aCriteria[$i][0]; + $next_biop = (isset($aCriteria[$i+1][0])) ? $aCriteria[$i+1][0] : false; + if ($next_biop != $cur_biop && $next_biop == 'OR') { + $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 + $prev_biop = (isset($aCriteria[$i-1][0])) ? $aCriteria[$i-1][0] : false; + if ($prev_biop == $cur_biop) { + $last = $aSearch[$i-1]; + if (!substr($last,-1) == ')') { + $aSearch[$i-1] = "(OR $last"; + $aSearch[] = $aCriteria[$i][1].')'; + } else { + $sEnd = ''; + while ($last && substr($last,-1) == ')') { + $last = substr($last,0,-1); + $sEnd .= ')'; } + $aSearch[$i-1] = "(OR $last"; + $aSearch[] = $aCriteria[$i][1].$sEnd.')'; + } + } else { + $aSearch[] = $aCriteria[$i][1]; } } - //if ($next_biop == 'OR') - // $criteria = $next_biop . ' ' . $criteria; - $search_string .= $criteria; - //$cur_biop = asearch_nz($biop_array[$cur_crit]); + } + $search_string .= implode(' ',$aSearch); } } |