e0df0e86c183dc812e149b5ab7bc132828947c09
[squirrelmail.git] / functions / imap_asearch.php
1 <?php
2
3 /**
4 * imap_search.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * IMAP asearch routines
10 * @author Alex Lemaresquier - Brainstorm - alex at brainstorm.fr
11 * @package squirrelmail
12 * @see search.php
13 *
14 */
15
16 /** This functionality requires the IMAP and date functions */
17 require_once(SM_PATH . 'functions/imap_general.php');
18 require_once(SM_PATH . 'functions/date.php');
19
20 /** Set to TRUE to dump the imap dialogue
21 * @global bool $imap_asearch_debug_dump
22 */
23 $imap_asearch_debug_dump = FALSE;
24
25 /** Array of imap SEARCH opcodes
26 * @global array $imap_asearch_opcodes
27 */
28 $imap_asearch_opcodes = array(
29 /* <message set> => 'asequence', */
30 /*'ALL' is binary operator */
31 'ANSWERED' => '',
32 'BCC' => 'astring',
33 'BEFORE' => 'adate',
34 'BODY' => 'astring',
35 'CC' => 'astring',
36 'DELETED' => '',
37 'DRAFT' => '',
38 'FLAGGED' => '',
39 'FROM' => 'astring',
40 'HEADER' => 'afield', /* Special syntax for this one, see below */
41 'KEYWORD' => 'akeyword',
42 'LARGER' => 'anum',
43 'NEW' => '',
44 /*'NOT' is unary operator */
45 'OLD' => '',
46 'ON' => 'adate',
47 /*'OR' is binary operator */
48 'RECENT' => '',
49 'SEEN' => '',
50 'SENTBEFORE' => 'adate',
51 'SENTON' => 'adate',
52 'SENTSINCE' => 'adate',
53 'SINCE' => 'adate',
54 'SMALLER' => 'anum',
55 'SUBJECT' => 'astring',
56 'TEXT' => 'astring',
57 'TO' => 'astring',
58 'UID' => 'asequence',
59 'UNANSWERED' => '',
60 'UNDELETED' => '',
61 'UNDRAFT' => '',
62 'UNFLAGGED' => '',
63 'UNKEYWORD' => 'akeyword',
64 'UNSEEN' => ''
65 );
66
67 /** Imap SEARCH month names encoding
68 * @global array $imap_asearch_months
69 */
70 $imap_asearch_months = array(
71 '01' => 'jan',
72 '02' => 'feb',
73 '03' => 'mar',
74 '04' => 'apr',
75 '05' => 'may',
76 '06' => 'jun',
77 '07' => 'jul',
78 '08' => 'aug',
79 '09' => 'sep',
80 '10' => 'oct',
81 '11' => 'nov',
82 '12' => 'dec'
83 );
84
85 /** Error message titles according to imap server returned code
86 * @global array $imap_error_titles
87 */
88 $imap_error_titles = array(
89 'OK' => '',
90 'NO' => _("ERROR : Could not complete request."),
91 'BAD' => _("ERROR : Bad or malformed request."),
92 'BYE' => _("ERROR : Imap server closed the connection.")
93 );
94
95 /**
96 * Function to display an error related to an IMAP-query.
97 * We need to do our own error management since we may receive NO responses on purpose (even BAD with SORT or THREAD)
98 * so we call sqimap_error_box() if the function exists (sm >= 1.5) or use our own embedded code
99 * @global array imap_error_titles
100 * @param string $response the imap server response code
101 * @param string $query the failed query
102 * @param string $message the error message
103 */
104 //@global array color sm colors array
105 function sqimap_asearch_error_box($response, $query, $message)
106 {
107 global $imap_error_titles;
108
109 //if (!array_key_exists($response, $imap_error_titles)) //php 4.0.6 compatibility
110 if (!in_array($response, array_keys($imap_error_titles)))
111 $title = _("ERROR : Unknown imap response.");
112 else
113 $title = $imap_error_titles[$response];
114 $message_title = _("Reason Given: ");
115 if (function_exists('sqimap_error_box'))
116 sqimap_error_box($title, $query, $message_title, $message);
117 else { //Straight copy of 1.5 imap_general.php:sqimap_error_box(). Can be removed at a later time
118 global $color;
119 require_once(SM_PATH . 'functions/display_messages.php');
120 $string = "<font color=$color[2]><b>\n" . $title . "</b><br>\n";
121 if ($query != '')
122 $string .= _("Query:") . ' ' . htmlspecialchars($query) . '<br>';
123 if ($message_title != '')
124 $string .= $message_title;
125 if ($message != '')
126 $string .= htmlspecialchars($message);
127 $string .= "</font><br>\n";
128 error_box($string,$color);
129 }
130 }
131
132 /**
133 * This is to avoid the E_NOTICE warnings signaled by marc AT squirrelmail.org. Thanks Marc!
134 * @param mixed $var any variable (reference)
135 * @return mixed zls ('') if $var is not defined, otherwise $var
136 */
137 function asearch_nz(&$var)
138 {
139 if (isset($var))
140 return $var;
141 return '';
142 }
143
144 /**
145 * This should give the same results as PHP 4 >= 4.3.0's html_entity_decode(),
146 * except it doesn't handle hex constructs
147 * @param string $string string to unhtmlentity()
148 * @return string decoded string
149 */
150 function asearch_unhtmlentities($string) {
151 $trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES));
152 for ($i=127; $i<255; $i++) /* Add &#<dec>; entities */
153 $trans_tbl['&#' . $i . ';'] = chr($i);
154 return strtr($string, $trans_tbl);
155 /* I think the one above is quicker, though it should be benchmarked
156 $string = strtr($string, array_flip(get_html_translation_table(HTML_ENTITIES)));
157 return preg_replace("/&#([0-9]+);/E", "chr('\\1')", $string);
158 */
159 }
160
161 /**
162 * Provide an easy way to dump the imap dialogue if $imap_asearch_debug_dump is TRUE
163 * @global imap_asearch_debug_dump
164 * @param string $var_name
165 * @param string $var_var
166 */
167 function s_debug_dump($var_name, $var_var)
168 {
169 global $imap_asearch_debug_dump;
170 if ($imap_asearch_debug_dump) {
171 if (function_exists('sm_print_r')) //Only exists since 1.4.2
172 sm_print_r($var_name, $var_var); //Better be the 'varargs' version ;)
173 else {
174 echo '<pre>';
175 echo htmlentities($var_name);
176 print_r($var_var);
177 echo '</pre>';
178 }
179 }
180 }
181
182 /** Encode a string to quoted or literal as defined in rfc 3501
183 *
184 * - ยง 4.3 String:
185 * A quoted string is a sequence of zero or more 7-bit characters,
186 * excluding CR and LF, with double quote (<">) characters at each end.
187 * - ยง 9. Formal Syntax:
188 * quoted-specials = DQUOTE / "\"
189 * @param string $what string to encode
190 * @param string $charset search charset used
191 * @return string encoded string
192 */
193 function sqimap_asearch_encode_string($what, $charset)
194 {
195 if (strtoupper($charset) == 'ISO-2022-JP') // This should be now handled in imap_utf7_local?
196 $what = mb_convert_encoding($what, 'JIS', 'auto');
197 //if (ereg("[\"\\\r\n\x80-\xff]", $what))
198 if (preg_match('/["\\\\\r\n\x80-\xff]/', $what))
199 return '{' . strlen($what) . "}\r\n" . $what; // 4.3 literal form
200 return '"' . $what . '"'; // 4.3 quoted string form
201 }
202
203 /**
204 * Parses a user date string into an rfc 3501 date string
205 * Handles space, slash, backslash, dot and comma as separators (and dash of course ;=)
206 * @global imap_asearch_months
207 * @param string user date
208 * @return array a preg_match-style array:
209 * - [0] = fully formatted rfc 3501 date string (<day number>-<US month TLA>-<4 digit year>)
210 * - [1] = day
211 * - [2] = month
212 * - [3] = year
213 */
214 function sqimap_asearch_parse_date($what)
215 {
216 global $imap_asearch_months;
217
218 $what = trim($what);
219 $what = ereg_replace('[ /\\.,]+', '-', $what);
220 if ($what) {
221 preg_match('/^([0-9]+)-+([^\-]+)-+([0-9]+)$/', $what, $what_parts);
222 if (count($what_parts) == 4) {
223 $what_month = strtolower(asearch_unhtmlentities($what_parts[2]));
224 /* if (!in_array($what_month, $imap_asearch_months)) {*/
225 foreach ($imap_asearch_months as $month_number => $month_code) {
226 if (($what_month == $month_number)
227 || ($what_month == $month_code)
228 || ($what_month == strtolower(asearch_unhtmlentities(getMonthName($month_number))))
229 || ($what_month == strtolower(asearch_unhtmlentities(getMonthAbrv($month_number))))
230 ) {
231 $what_parts[2] = $month_number;
232 $what_parts[0] = $what_parts[1] . '-' . $month_code . '-' . $what_parts[3];
233 break;
234 }
235 }
236 /* }*/
237 }
238 }
239 else
240 $what_parts = array();
241 return $what_parts;
242 }
243
244 /**
245 * Build one criteria sequence
246 * @global array imap_asearch_opcodes
247 * @param string $opcode search opcode
248 * @param string $what opcode argument
249 * @param string $charset search charset
250 * @return string one full criteria sequence
251 */
252 function sqimap_asearch_build_criteria($opcode, $what, $charset)
253 {
254 global $imap_asearch_opcodes;
255
256 $criteria = '';
257 switch ($imap_asearch_opcodes[$opcode]) {
258 default:
259 case 'anum':
260 // $what = str_replace(' ', '', $what);
261 $what = ereg_replace('[^0-9]+', '', $what);
262 if ($what != '')
263 $criteria = $opcode . ' ' . $what . ' ';
264 break;
265 case '': //aflag
266 $criteria = $opcode . ' ';
267 break;
268 case 'afield': /* HEADER field-name: field-body */
269 preg_match('/^([^:]+):(.*)$/', $what, $what_parts);
270 if (count($what_parts) == 3)
271 $criteria = $opcode . ' ' .
272 sqimap_asearch_encode_string($what_parts[1], $charset) . ' ' .
273 sqimap_asearch_encode_string($what_parts[2], $charset) . ' ';
274 break;
275 case 'adate':
276 $what_parts = sqimap_asearch_parse_date($what);
277 if (isset($what_parts[0]))
278 $criteria = $opcode . ' ' . $what_parts[0] . ' ';
279 break;
280 case 'akeyword':
281 case 'astring':
282 $criteria = $opcode . ' ' . sqimap_asearch_encode_string($what, $charset) . ' ';
283 break;
284 case 'asequence':
285 $what = ereg_replace('[^0-9:\(\)]+', '', $what);
286 if ($what != '')
287 $criteria = $opcode . ' ' . $what . ' ';
288 break;
289 }
290 return $criteria;
291 }
292
293 /**
294 * Another way to do array_values(array_unique(array_merge($to, $from)));
295 * @param array $to to array (reference)
296 * @param array $from from array
297 * @return array uniquely merged array
298 */
299 function sqimap_array_merge_unique(&$to, $from)
300 {
301 if (empty($to))
302 return $from;
303 $count = count($from);
304 for ($i = 0; $i < $count; $i++) {
305 if (!in_array($from[$i], $to))
306 $to[] = $from[$i];
307 }
308 return $to;
309 }
310
311 /**
312 * Run the imap SEARCH command as defined in rfc 3501
313 * @link ftp://ftp.rfc-editor.org/in-notes/rfc3501.txt
314 * @param resource $imapConnection the current imap stream
315 * @param string $search_string the full search expression eg "ALL RECENT"
316 * @param string $search_charset charset to use or zls ('')
317 * @return array an IDs or UIDs array of matching messages or an empty array
318 */
319 function sqimap_run_search($imapConnection, $search_string, $search_charset)
320 {
321 global $uid_support;
322
323 /* 6.4.4 try OPTIONAL [CHARSET] specification first */
324 if ($search_charset != '')
325 $query = 'SEARCH CHARSET "' . strtoupper($search_charset) . '" ALL ' . $search_string;
326 else
327 $query = 'SEARCH ALL ' . $search_string;
328 s_debug_dump('C:', $query);
329 $readin = sqimap_run_command($imapConnection, $query, false, $response, $message, $uid_support);
330
331 /* 6.4.4 try US-ASCII charset if we tried an OPTIONAL [CHARSET] and received a tagged NO response (SHOULD be [BADCHARSET]) */
332 if (($search_charset != '') && (strtoupper($response) == 'NO')) {
333 $query = 'SEARCH CHARSET US-ASCII ALL ' . $search_string;
334 s_debug_dump('C:', $query);
335 $readin = sqimap_run_command($imapConnection, $query, false, $response, $message, $uid_support);
336 }
337 if (strtoupper($response) != 'OK') {
338 sqimap_asearch_error_box($response, $query, $message);
339 return array();
340 }
341
342 // Keep going till we find the * SEARCH response
343 foreach ($readin as $readin_part) {
344 s_debug_dump('S:', $readin_part);
345 if (substr($readin_part, 0, 9) == '* SEARCH ') {
346 //EIMS returns multiple SEARCH responses, and this allowed according to Mark Crispin
347 $messagelist = sqimap_array_merge_unique($messagelist, preg_split("/ /", substr($readin_part, 9)));
348 }
349 }
350
351 if (empty($messagelist)) //Empty search response, ie '* SEARCH'
352 return array();
353
354 $cnt = count($messagelist);
355 for ($q = 0; $q < $cnt; $q++)
356 $id[$q] = trim($messagelist[$q]);
357 return $id;
358 }
359
360 /**
361 * Run the imap SORT command as defined in
362 * @link http://www.ietf.org/internet-drafts/draft-ietf-imapext-sort-13.txt
363 * @param resource $imapConnection the current imap stream
364 * @param string $search_string the full search expression as defined in rfc 3501
365 * @param string $search_charset mandatory charset
366 * @param string $sort_criteria the full sort criteria expression eg "SUBJECT REVERSE DATE"
367 * @return array an IDs or UIDs array of matching messages or an empty array
368 */
369 function sqimap_run_sort($imapConnection, $search_string, $search_charset, $sort_criteria)
370 {
371 global $uid_support;
372
373 if ($search_charset == '')
374 $search_charset = 'US-ASCII';
375 $query = 'SORT (' . $sort_criteria . ') ' . strtoupper($search_charset) . ' ALL ' . $search_string;
376 s_debug_dump('C:', $query);
377 $readin = sqimap_run_command($imapConnection, $query, false, $response, $message, $uid_support);
378
379 /* 6.4 try US-ASCII charset if we received a tagged NO response (SHOULD be [BADCHARSET]) */
380 if (($search_charset != 'US-ASCII') && (strtoupper($response) == 'NO')) {
381 $query = 'SORT (' . $sort_criteria . ') US-ASCII ALL ' . $search_string;
382 s_debug_dump('C:', $query);
383 $readin = sqimap_run_command($imapConnection, $query, false, $response, $message, $uid_support);
384 }
385
386 if (strtoupper($response) != 'OK') {
387 // sqimap_asearch_error_box($response, $query, $message);
388 // return array();
389 return sqimap_run_search($imapConnection, $search_string, $search_charset); // Fell back to standard search
390 }
391
392 /* Keep going till we find the * SORT response */
393 foreach ($readin as $readin_part) {
394 s_debug_dump('S:', $readin_part);
395 if (substr($readin_part, 0, 7) == '* SORT ') {
396 //SORT returns untagged responses
397 $messagelist = sqimap_array_merge_unique($messagelist, preg_split("/ /", substr($readin_part, 7)));
398 }
399 }
400
401 if (empty($messagelist)) //Empty search response, ie '* SORT'
402 return array();
403
404 $cnt = count($messagelist);
405 for ($q = 0; $q < $cnt; $q++)
406 $id[$q] = trim($messagelist[$q]);
407 return $id;
408 }
409
410 /**
411 * Run the imap THREAD command as defined in
412 * @link http://www.ietf.org/internet-drafts/draft-ietf-imapext-sort-13.txt
413 * @param resource $imapConnection the current imap stream
414 * @param string $search_string the full search expression as defined in rfc 3501
415 * @param string $search_charset mandatory charset
416 * @param string $thread_algorithm the threading algorithm "ORDEREDSUBJECT" or "REFERENCES"
417 * @return array an IDs or UIDs array of matching messages or an empty array
418 * @global array $thread_new will be used by thread view in mailbox_display
419 * @global array $server_sort_array will be used by thread view in mailbox_display
420 */
421 function sqimap_run_thread($imapConnection, $search_string, $search_charset, $thread_algorithm)
422 {
423 global $thread_new, $server_sort_array;
424
425 if (sqsession_is_registered('thread_new'))
426 sqsession_unregister('thread_new');
427 if (sqsession_is_registered('server_sort_array'))
428 sqsession_unregister('server_sort_array');
429
430 $thread_new = array();
431 $thread_new[0] = "";
432
433 $server_sort_array = array();
434
435 global $uid_support;
436
437 if ($search_charset == '')
438 $search_charset = 'US-ASCII';
439 $query = 'THREAD ' . $thread_algorithm . ' ' . strtoupper($search_charset) . ' ALL ' . $search_string;
440 s_debug_dump('C:', $query);
441 $readin = sqimap_run_command($imapConnection, $query, false, $response, $message, $uid_support);
442
443 /* 6.4 try US-ASCII charset if we received a tagged NO response (SHOULD be [BADCHARSET]) */
444 if (($search_charset != 'US-ASCII') && (strtoupper($response) == 'NO')) {
445 $query = 'THREAD ' . $thread_algorithm . ' US-ASCII ALL ' . $search_string;
446 s_debug_dump('C:', $query);
447 $readin = sqimap_run_command($imapConnection, $query, false, $response, $message, $uid_support);
448 }
449
450 if (strtoupper($response) != 'OK') {
451 /* we should at this point:
452 - warn the user that the THREAD call has failed
453 - (offer him a way to) disconnect it permanently in the prefs
454 - perform the regular search instead or provide a way to do it in one click
455 */
456 // sqimap_asearch_error_box($response, $query, $message);
457 // return array();
458 return sqimap_run_search($imapConnection, $search_string, $search_charset); // Fell back to standard search
459 }
460
461 /* Keep going till we find the * THREAD response */
462 foreach ($readin as $readin_part) {
463 s_debug_dump('S:', $readin_part);
464 if (substr($readin_part, 0, 9) == '* THREAD ') {
465 $thread_temp = preg_split("//", substr($readin_part, 9), -1, PREG_SPLIT_NO_EMPTY);
466 break; // Should be the last anyway
467 }
468 }
469
470 if (empty($thread_temp)) //Empty search response, ie '* THREAD'
471 return array();
472
473 $char_count = count($thread_temp);
474 $counter = 0;
475 $k = 0;
476 for ($i=0;$i<$char_count;$i++) {
477 if ($thread_temp[$i] != ')' && $thread_temp[$i] != '(') {
478 $thread_new[$k] = $thread_new[$k] . $thread_temp[$i];
479 }
480 elseif ($thread_temp[$i] == '(') {
481 $thread_new[$k] .= $thread_temp[$i];
482 $counter++;
483 }
484 elseif ($thread_temp[$i] == ')') {
485 if ($counter > 1) {
486 $thread_new[$k] .= $thread_temp[$i];
487 $counter = $counter - 1;
488 }
489 else {
490 $thread_new[$k] .= $thread_temp[$i];
491 $k++;
492 $thread_new[$k] = "";
493 $counter = $counter - 1;
494 }
495 }
496 }
497 sqsession_register($thread_new, 'thread_new');
498 $thread_new = array_reverse($thread_new);
499 $thread_list = implode(" ", $thread_new);
500 $thread_list = str_replace("(", " ", $thread_list);
501 $thread_list = str_replace(")", " ", $thread_list);
502 $thread_list = preg_split("/\s/", $thread_list, -1, PREG_SPLIT_NO_EMPTY);
503 $server_sort_array = $thread_list;
504 sqsession_register($server_sort_array, 'server_sort_array');
505 return $thread_list;
506 }
507
508 /**
509 * @global bool allow_charset_search user setting
510 * @global array languages sm languages array
511 * @global string squirrelmail_language user language setting
512 * @return string the user defined charset if $allow_charset_search is TRUE else zls ('')
513 */
514 function sqimap_asearch_get_charset()
515 {
516 global $allow_charset_search, $languages, $squirrelmail_language;
517
518 if ($allow_charset_search)
519 return $languages[$squirrelmail_language]['CHARSET'];
520 return '';
521 }
522
523 /**
524 * Convert sm internal sort to imap sort taking care of:
525 * - user defined date sorting (ARRIVAL vs DATE)
526 * - if the searched mailbox is the sent folder then TO is being used instead of FROM
527 * - reverse order by using REVERSE
528 * @param string $mailbox mailbox name to sort
529 * @param integer $sort_by sm sort criteria
530 * @return string imap sort criteria
531 */
532 function sqimap_asearch_get_sort_criteria($mailbox, $sort_by)
533 {
534 global $internal_date_sort, $sent_folder;
535
536 $sort_opcodes = array ('DATE', 'FROM', 'SUBJECT', 'SIZE');
537 if ($internal_date_sort == true)
538 $sort_opcodes[0] = 'ARRIVAL';
539 // if (handleAsSent($mailbox))
540 // if (isSentFolder($mailbox))
541 if ($mailbox == $sent_folder)
542 $sort_opcodes[1] = 'TO';
543 return (($sort_by % 2) ? '' : 'REVERSE ') . $sort_opcodes[($sort_by >> 1) & 3];
544 }
545
546 /**
547 * Performs the search, given all the criteria, merging results for every mailbox
548 * @return array array(mailbox => array(UIDs))
549 */
550 function sqimap_asearch($imapConnection, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $mboxes_array)
551 {
552 global $allow_server_sort, $sort, $allow_thread_sort, $thread_sort_messages;
553 global $data_dir, $username;
554
555 $search_charset = sqimap_asearch_get_charset();
556 $mbox_msgs = array();
557 $search_string = '';
558 $cur_mailbox = $mailbox_array[0];
559 $cur_biop = ''; /* Start with ALL */
560 /* We loop one more time than the real array count, so the last search gets fired */
561 for ($cur_crit = 0; $cur_crit <= count($where_array); $cur_crit++) {
562 if (empty($exclude_array[$cur_crit])) {
563 $next_mailbox = $mailbox_array[$cur_crit];
564 if ($next_mailbox != $cur_mailbox) {
565 $search_string = trim($search_string); /* Trim out last space */
566 if (($cur_mailbox == 'All Folders') && (!empty($mboxes_array)))
567 $search_mboxes = $mboxes_array;
568 else
569 $search_mboxes = array($cur_mailbox);
570 foreach ($search_mboxes as $cur_mailbox) {
571 s_debug_dump('C:SELECT:', $cur_mailbox);
572 sqimap_mailbox_select($imapConnection, $cur_mailbox);
573 $thread_sort_messages = $allow_thread_sort && getPref($data_dir, $username, 'thread_' . $cur_mailbox);
574 if ($thread_sort_messages) {
575 $thread_algorithm = 'REFERENCES';
576 $found_msgs = sqimap_run_thread($imapConnection, $search_string, $search_charset, $thread_algorithm);
577 }
578 else
579 if (($allow_server_sort) && ($sort < 6)) {
580 $sort_criteria = sqimap_asearch_get_sort_criteria($cur_mailbox, $sort);
581 $found_msgs = sqimap_run_sort($imapConnection, $search_string, $search_charset, $sort_criteria);
582 }
583 else
584 $found_msgs = sqimap_run_search($imapConnection, $search_string, $search_charset);
585 if (isset($mbox_msgs[$cur_mailbox])) {
586 if ($cur_biop == 'OR') /* Merge with previous results */
587 $mbox_msgs[$cur_mailbox] = sqimap_array_merge_unique($mbox_msgs[$cur_mailbox], $found_msgs);
588 else /* Intersect previous results */
589 $mbox_msgs[$cur_mailbox] = array_values(array_intersect($found_msgs, $mbox_msgs[$cur_mailbox]));
590 }
591 else /* No previous results */
592 $mbox_msgs[$cur_mailbox] = $found_msgs;
593 if (empty($mbox_msgs[$cur_mailbox])) /* Can happen with intersect, and we need at the end a contiguous array */
594 unset($mbox_msgs[$cur_mailbox]);
595 }
596 $cur_mailbox = $next_mailbox;
597 $search_string = '';
598 }
599 if (isset($where_array[$cur_crit])) {
600 $criteria = sqimap_asearch_build_criteria($where_array[$cur_crit], $what_array[$cur_crit], $search_charset);
601 if (!empty($criteria)) {
602 $unop = $unop_array[$cur_crit];
603 if (!empty($unop))
604 $criteria = $unop . ' ' . $criteria;
605 /* We need to infix the next non-excluded criteria's biop if it's the same mailbox */
606 $next_biop = '';
607 for ($next_crit = $cur_crit+1; $next_crit <= count($where_array); $next_crit++) {
608 if (empty($exclude_array[$next_crit])) {
609 if (asearch_nz($mailbox_array[$next_crit]) == $cur_mailbox)
610 $next_biop = asearch_nz($biop_array[$next_crit]);
611 break;
612 }
613 }
614 if ($next_biop == 'OR')
615 $criteria = $next_biop . ' ' . $criteria;
616 $search_string .= $criteria;
617 $cur_biop = asearch_nz($biop_array[$cur_crit]);
618 }
619 }
620 }
621 }
622 return $mbox_msgs;
623 }
624
625 ?>