Changeset 1845fb6 in github
- Timestamp:
- Mar 18, 2010 6:56:46 AM (3 years ago)
- Branches:
- master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
- Children:
- 15e00bd
- Parents:
- b575fa9
- Location:
- program
- Files:
-
- 2 edited
-
include/rcube_imap.php (modified) (9 diffs)
-
lib/imap.inc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
program/include/rcube_imap.php
rf52c936f r1845fb6 683 683 } 684 684 // use SORT command 685 else if ($this->get_capability('sort') && ($msg_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''))) 686 { 687 list($begin, $end) = $this->_get_message_range(count($msg_index), $page); 688 $max = max($msg_index); 689 $msg_index = array_slice($msg_index, $begin, $end-$begin); 690 691 if ($slice) 692 $msg_index = array_slice($msg_index, ($this->sort_order == 'DESC' ? 0 : -$slice), $slice); 693 694 // fetch reqested headers from server 695 $this->_fetch_headers($mailbox, join(',', $msg_index), $a_msg_headers, $cache_key); 685 else if ($this->get_capability('sort')) 686 { 687 if ($msg_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : '')) { 688 list($begin, $end) = $this->_get_message_range(count($msg_index), $page); 689 $max = max($msg_index); 690 $msg_index = array_slice($msg_index, $begin, $end-$begin); 691 692 if ($slice) 693 $msg_index = array_slice($msg_index, ($this->sort_order == 'DESC' ? 0 : -$slice), $slice); 694 695 // fetch reqested headers from server 696 $this->_fetch_headers($mailbox, join(',', $msg_index), $a_msg_headers, $cache_key); 697 } 696 698 } 697 699 // fetch specified header for all messages and sort … … 774 776 list ($thread_tree, $msg_depth, $has_children) = iil_C_Thread($this->conn, 775 777 $mailbox, $this->threading, $this->skip_deleted ? 'UNDELETED' : ''); 776 778 777 779 // add to internal (fast) cache 778 780 $this->icache['threads'] = array(); … … 1083 1085 $a_header_index = iil_C_FetchHeaders($this->conn, $mailbox, $msgs, false, false, $this->fetch_add_headers); 1084 1086 1085 if (!empty($a_header_index)) 1086 { 1087 // cache is incomplete 1088 $cache_index = $this->get_message_cache_index($cache_key); 1089 1090 foreach ($a_header_index as $i => $headers) { 1091 if ($this->caching_enabled && $cache_index[$headers->id] != $headers->uid) { 1092 // prevent index duplicates 1093 if ($cache_index[$headers->id]) { 1094 $this->remove_message_cache($cache_key, $headers->id, true); 1095 unset($cache_index[$headers->id]); 1087 if (empty($a_header_index)) 1088 return 0; 1089 1090 // cache is incomplete 1091 $cache_index = $this->get_message_cache_index($cache_key); 1092 1093 foreach ($a_header_index as $i => $headers) { 1094 if ($this->caching_enabled && $cache_index[$headers->id] != $headers->uid) { 1095 // prevent index duplicates 1096 if ($cache_index[$headers->id]) { 1097 $this->remove_message_cache($cache_key, $headers->id, true); 1098 unset($cache_index[$headers->id]); 1096 1099 } 1097 // add message to cache1098 $this->add_message_cache($cache_key, $headers->id, $headers, NULL,1099 !in_array($headers->uid, $cache_index));1100 // add message to cache 1101 $this->add_message_cache($cache_key, $headers->id, $headers, NULL, 1102 !in_array($headers->uid, $cache_index)); 1100 1103 } 1101 1104 1102 $a_msg_headers[$headers->uid] = $headers; 1103 } 1105 $a_msg_headers[$headers->uid] = $headers; 1104 1106 } 1105 1107 … … 1224 1226 } 1225 1227 // fetch complete message index 1226 else if ($this->get_capability('sort') && ($a_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''))) 1227 { 1228 if ($this->sort_order == 'DESC') 1229 $a_index = array_reverse($a_index); 1230 1231 $this->cache[$key] = $a_index; 1232 } 1233 else 1234 { 1235 $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, "1:*", $this->sort_field, $this->skip_deleted); 1236 1228 else if ($this->get_capability('sort')) 1229 { 1230 if ($a_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : '')) { 1231 if ($this->sort_order == 'DESC') 1232 $a_index = array_reverse($a_index); 1233 1234 $this->cache[$key] = $a_index; 1235 } 1236 } 1237 else if ($a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, "1:*", $this->sort_field, $this->skip_deleted)) { 1237 1238 if ($this->sort_order=="ASC") 1238 1239 asort($a_index); … … 1462 1463 $charset = $charset ? $charset : $this->default_charset; 1463 1464 $a_messages = iil_C_Sort($this->conn, $mailbox, $sort_field, $criteria, FALSE, $charset); 1465 1466 if (!$a_messages) 1467 return array(); 1464 1468 } 1465 1469 else { … … 1470 1474 else { 1471 1475 $a_messages = iil_C_Search($this->conn, $mailbox, ($charset ? "CHARSET $charset " : '') . $criteria); 1472 1476 1477 if (!$a_messages) 1478 return array(); 1479 1473 1480 // I didn't found that SEARCH always returns sorted IDs 1474 1481 if (!$this->sort_field) … … 1501 1508 // default sorting 1502 1509 if (!$this->sort_field || ($this->sort_field == 'date' && $this->threading == 'REFS')) { 1503 return array_keys( $thread_tree);1510 return array_keys((array)$thread_tree); 1504 1511 } 1505 1512 // here we'll implement REFS sorting, for performance reason … … 1509 1516 $a_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, 1510 1517 !empty($ids) ? $ids : ($this->skip_deleted ? 'UNDELETED' : '')); 1518 1519 // return unsorted tree if we've got no index data 1520 if (!$a_index) 1521 return array_keys((array)$thread_tree); 1511 1522 } 1512 1523 else { … … 1514 1525 $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, !empty($ids) ? $ids : "1:*", 1515 1526 $this->sort_field, $this->skip_deleted); 1527 1528 // return unsorted tree if we've got no index data 1529 if (!$a_index) 1530 return array_keys((array)$thread_tree); 1531 1516 1532 asort($a_index); // ASC 1517 1533 $a_index = array_values($a_index); -
program/lib/imap.inc
rf52c936f r1845fb6 742 742 } 743 743 744 function iil_CheckForRecent($host, $user, $password, $mailbox) {745 if (empty($mailbox)) {746 $mailbox = 'INBOX';747 }748 749 $conn = iil_Connect($host, $user, $password, 'plain');750 $fp = $conn->fp;751 if ($fp) {752 iil_PutLine($fp, "a002 EXAMINE \"".iil_Escape($mailbox)."\"");753 do {754 $line=chop(iil_ReadLine($fp, 300));755 $a=explode(' ', $line);756 if (($a[0] == '*') && (strcasecmp($a[2], 'RECENT') == 0)) {757 $result = (int) $a[1];758 }759 } while (!iil_StartsWith($a[0], 'a002', true));760 761 iil_PutLine($fp, "a003 LOGOUT");762 fclose($fp);763 } else {764 $result = -2;765 }766 767 return $result;768 }769 770 744 function iil_C_Select(&$conn, $mailbox) { 771 745 … … 1620 1594 $encoding='US-ASCII') { 1621 1595 1622 if (iil_C_Select($conn, $folder)) { 1623 1624 $encoding = $encoding ? trim($encoding) : 'US-ASCII'; 1625 $algorithm = $algorithm ? trim($algorithm) : 'REFERENCES'; 1626 $criteria = $criteria ? 'ALL '.trim($criteria) : 'ALL'; 1596 if (!iil_C_Select($conn, $folder)) { 1597 $conn->error = "Couldn't select $folder"; 1598 return false; 1599 } 1600 1601 $encoding = $encoding ? trim($encoding) : 'US-ASCII'; 1602 $algorithm = $algorithm ? trim($algorithm) : 'REFERENCES'; 1603 $criteria = $criteria ? 'ALL '.trim($criteria) : 'ALL'; 1627 1604 1628 iil_PutLineC($conn->fp, "thrd1 THREAD $algorithm $encoding $criteria");1629 do {1630 $line = trim(iil_ReadLine($conn->fp, 10000));1631 if (preg_match('/^\* THREAD/', $line)){1632 $str = trim(substr($line, 8));1633 $depthmap = array();1634 $haschildren = array();1635 $tree = iil_ParseThread($str, 0, strlen($str), null, null, 0, $depthmap, $haschildren);1636 }1637 } while (!iil_StartsWith($line, 'thrd1', true));1638 1639 $result_code = iil_ParseResult($line);1640 if ($result_code == 0) { 1641 return array($tree, $depthmap, $haschildren);1642 }1643 $conn->error = 'iil_C_Thread: ' . $line . "\n";1644 return false;1645 } 1646 $conn->error = "iil_C_Thread: Couldn't select \"$folder\"\n";1647 return false; 1605 if (!iil_PutLineC($conn->fp, "thrd1 THREAD $algorithm $encoding $criteria")) { 1606 return false; 1607 } 1608 do { 1609 $line = trim(iil_ReadLine($conn->fp, 10000)); 1610 if (preg_match('/^\* THREAD/', $line)) { 1611 $str = trim(substr($line, 8)); 1612 $depthmap = array(); 1613 $haschildren = array(); 1614 $tree = iil_ParseThread($str, 0, strlen($str), null, null, 0, $depthmap, $haschildren); 1615 } 1616 } while (!iil_StartsWith($line, 'thrd1', true)); 1617 1618 $result_code = iil_ParseResult($line); 1619 if ($result_code == 0) { 1620 return array($tree, $depthmap, $haschildren); 1621 } 1622 1623 $conn->error = 'iil_C_Thread: ' . $line . "\n"; 1624 return false; 1648 1625 } 1649 1626 1650 1627 function iil_C_Search(&$conn, $folder, $criteria) { 1651 1628 1652 if (iil_C_Select($conn, $folder)) { 1653 $data = ''; 1654 1655 $query = 'srch1 SEARCH ' . chop($criteria); 1656 if (!iil_PutLineC($conn->fp, $query)) { 1657 return false; 1658 } 1659 do { 1660 $line = trim(iil_ReadLine($conn->fp)); 1661 if (iil_StartsWith($line, '* SEARCH')) { 1662 $data .= substr($line, 8); 1663 } else if (preg_match('/^[0-9 ]+$/', $line)) { 1664 $data .= $line; 1665 } 1666 } while (!iil_StartsWith($line, 'srch1', true)); 1667 1668 $result_code = iil_ParseResult($line); 1669 if ($result_code == 0) { 1670 return preg_split('/\s+/', $data, -1, PREG_SPLIT_NO_EMPTY); 1671 } 1672 $conn->error = 'iil_C_Search: ' . $line . "\n"; 1673 return false; 1674 } 1675 $conn->error = "iil_C_Search: Couldn't select \"$folder\"\n"; 1676 return false; 1629 if (!iil_C_Select($conn, $folder)) { 1630 $conn->error = "Couldn't select $folder"; 1631 return false; 1632 } 1633 1634 $data = ''; 1635 $query = 'srch1 SEARCH ' . chop($criteria); 1636 1637 if (!iil_PutLineC($conn->fp, $query)) { 1638 return false; 1639 } 1640 do { 1641 $line = trim(iil_ReadLine($conn->fp)); 1642 if (iil_StartsWith($line, '* SEARCH')) { 1643 $data .= substr($line, 8); 1644 } else if (preg_match('/^[0-9 ]+$/', $line)) { 1645 $data .= $line; 1646 } 1647 } while (!iil_StartsWith($line, 'srch1', true)); 1648 1649 $result_code = iil_ParseResult($line); 1650 if ($result_code == 0) { 1651 return preg_split('/\s+/', $data, -1, PREG_SPLIT_NO_EMPTY); 1652 } 1653 1654 $conn->error = 'iil_C_Search: ' . $line . "\n"; 1655 return false; 1677 1656 } 1678 1657
Note: See TracChangeset
for help on using the changeset viewer.
