Changeset ffd3e29 in github for program/include/rcube_imap.php
- Timestamp:
- Jun 4, 2010 5:16:30 AM (3 years ago)
- Branches:
- master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
- Children:
- 309f49f
- Parents:
- 2144f9c
- File:
-
- 1 edited
-
program/include/rcube_imap.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
program/include/rcube_imap.php
rf22b543 rffd3e29 298 298 if (is_array($str) && $msgs == null) 299 299 list($str, $msgs, $charset, $sort_field, $threads) = $str; 300 if ($msgs != null && !is_array($msgs)) 300 if ($msgs === false) 301 $msgs = array(); 302 else if ($msgs != null && !is_array($msgs)) 301 303 $msgs = explode(',', $msgs); 302 304 … … 608 610 $msg_index = array(); 609 611 610 if ($slice )612 if ($slice && $msg_index) 611 613 $msg_index = array_slice($msg_index, ($this->sort_order == 'DESC' ? 0 : -$slice), $slice); 612 614 … … 1198 1200 } 1199 1201 1200 if ($ this->sort_order == 'DESC')1202 if ($a_index !== false && $this->sort_order == 'DESC') 1201 1203 $a_index = array_reverse($a_index); 1202 1204 … … 1205 1207 // fetch complete message index 1206 1208 else if ($this->get_capability('SORT')) { 1207 if ($a_index = $this->conn->sort($mailbox,1208 $this->sort_field, $this->skip_deleted ? 'UNDELETED' : '') ) {1209 if ($this->sort_order == 'DESC') 1210 $a_index = array_reverse($a_index);1211 1212 $this->cache[$key] = $a_index; 1213 } 1209 $a_index = $this->conn->sort($mailbox, 1210 $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''); 1211 1212 if ($a_index !== false && $this->sort_order == 'DESC') 1213 $a_index = array_reverse($a_index); 1214 1215 $this->cache[$key] = $a_index; 1214 1216 } 1215 1217 else if ($a_index = $this->conn->fetchHeaderIndex( … … 1223 1225 } 1224 1226 1225 return $this->cache[$key] ;1227 return $this->cache[$key] !== false ? $this->cache[$key] : array(); 1226 1228 } 1227 1229 … … 1380 1382 $results = $this->_search_index($mailbox, $str, $charset, $sort_field); 1381 1383 1382 // try search with US-ASCII charset (should be supported by server)1383 // only if UTF-8 search is not supported1384 if (empty($results) && !is_array($results) && !empty($charset) && $charset != 'US-ASCII')1385 {1386 // convert strings to US_ASCII1387 if(preg_match_all('/\{([0-9]+)\}\r\n/', $str, $matches, PREG_OFFSET_CAPTURE)) {1388 $last = 0; $res = '';1389 foreach($matches[1] as $m)1390 {1391 $string_offset = $m[1] + strlen($m[0]) + 4; // {}\r\n1392 $string = substr($str, $string_offset - 1, $m[0]);1393 $string = rcube_charset_convert($string, $charset, 'US-ASCII');1394 if (!$string)1395 continue;1396 $res .= sprintf("%s{%d}\r\n%s", substr($str, $last, $m[1] - $last - 1), strlen($string), $string);1397 $last = $m[0] + $string_offset - 1;1398 }1399 if ($last < strlen($str))1400 $res .= substr($str, $last, strlen($str)-$last);1401 }1402 else // strings for conversion not found1403 $res = $str;1404 1405 $results = $this->search($mbox_name, $res, NULL, $sort_field);1406 }1407 1408 1384 $this->set_search_set($str, $results, $charset, $sort_field, (bool)$this->threading); 1409 1385 … … 1427 1403 1428 1404 if ($this->threading) { 1429 list ($thread_tree, $msg_depth, $has_children) = $this->conn->thread( 1430 $mailbox, $this->threading, $criteria, $charset); 1431 1432 $a_messages = array( 1433 'tree' => $thread_tree, 1434 'depth' => $msg_depth, 1435 'children' => $has_children 1436 ); 1405 $a_messages = $this->conn->thread($mailbox, $this->threading, $criteria, $charset); 1406 1407 // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8, 1408 // but I've seen that Courier doesn't support UTF-8) 1409 if ($a_messages === false && $charset && $charset != 'US-ASCII') 1410 $a_messages = $this->conn->thread($mailbox, $this->threading, 1411 $this->convert_criteria($criteria, $charset), 'US-ASCII'); 1412 1413 if ($a_messages !== false) { 1414 list ($thread_tree, $msg_depth, $has_children) = $a_messages; 1415 $a_messages = array( 1416 'tree' => $thread_tree, 1417 'depth' => $msg_depth, 1418 'children' => $has_children 1419 ); 1420 } 1437 1421 } 1438 1422 else if ($sort_field && $this->get_capability('SORT')) { … … 1440 1424 $a_messages = $this->conn->sort($mailbox, $sort_field, $criteria, false, $charset); 1441 1425 1442 if (!$a_messages) 1443 return array(); 1426 // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8, 1427 // but I've seen that Courier doesn't support UTF-8) 1428 if ($a_messages === false && $charset && $charset != 'US-ASCII') 1429 $a_messages = $this->conn->sort($mailbox, $sort_field, 1430 $this->convert_criteria($criteria, $charset), false, 'US-ASCII'); 1444 1431 } 1445 1432 else { … … 1450 1437 else { 1451 1438 $a_messages = $this->conn->search($mailbox, 1452 ($charset ? "CHARSET $charset " : '') . $criteria); 1453 1454 if (!$a_messages) 1455 return array(); 1456 1457 // I didn't found that SEARCH always returns sorted IDs 1458 if (!$this->sort_field) 1459 sort($a_messages); 1439 ($charset ? "CHARSET $charset " : '') . $criteria); 1440 1441 // Error, try with US-ASCII (some servers may support only US-ASCII) 1442 if ($a_messages === false && $charset && $charset != 'US-ASCII') 1443 $a_messages = $this->conn->search($mailbox, 1444 'CHARSET US-ASCII ' . $this->convert_criteria($criteria, $charset)); 1445 1446 // I didn't found that SEARCH should return sorted IDs 1447 if (is_array($a_messages) && !$this->sort_field) 1448 sort($a_messages); 1460 1449 } 1461 1450 } … … 1488 1477 1489 1478 return $this->conn->search($mailbox, $str, $ret_uid); 1479 } 1480 1481 1482 /** 1483 * Converts charset of search criteria string 1484 * 1485 * @param string Search string 1486 * @param string Original charset 1487 * @param string Destination charset (default US-ASCII) 1488 * @return string Search string 1489 * @access private 1490 */ 1491 private function convert_criteria($str, $charset, $dest_charset='US-ASCII') 1492 { 1493 // convert strings to US_ASCII 1494 if (preg_match_all('/\{([0-9]+)\}\r\n/', $str, $matches, PREG_OFFSET_CAPTURE)) { 1495 $last = 0; $res = ''; 1496 foreach ($matches[1] as $m) { 1497 $string_offset = $m[1] + strlen($m[0]) + 4; // {}\r\n 1498 $string = substr($str, $string_offset - 1, $m[0]); 1499 $string = rcube_charset_convert($string, $charset, $dest_charset); 1500 if (!$string) 1501 continue; 1502 $res .= sprintf("%s{%d}\r\n%s", substr($str, $last, $m[1] - $last - 1), strlen($string), $string); 1503 $last = $m[0] + $string_offset - 1; 1504 } 1505 if ($last < strlen($str)) 1506 $res .= substr($str, $last, strlen($str)-$last); 1507 } 1508 else // strings for conversion not found 1509 $res = $str; 1510 1511 return $res; 1490 1512 } 1491 1513
Note: See TracChangeset
for help on using the changeset viewer.
