Changeset 1845fb6 in github


Ignore:
Timestamp:
Mar 18, 2010 6:56:46 AM (3 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
15e00bd
Parents:
b575fa9
Message:
  • Handle 'false' result from iil_C_* functions (#1486511)
Location:
program
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • program/include/rcube_imap.php

    rf52c936f r1845fb6  
    683683      } 
    684684    // 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        } 
    696698      } 
    697699    // fetch specified header for all messages and sort 
     
    774776      list ($thread_tree, $msg_depth, $has_children) = iil_C_Thread($this->conn, 
    775777        $mailbox, $this->threading, $this->skip_deleted ? 'UNDELETED' : ''); 
    776      
     778    
    777779      // add to internal (fast) cache 
    778780      $this->icache['threads'] = array(); 
     
    10831085    $a_header_index = iil_C_FetchHeaders($this->conn, $mailbox, $msgs, false, false, $this->fetch_add_headers); 
    10841086 
    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]); 
    10961099          } 
    1097           // add message to cache 
    1098           $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)); 
    11001103        } 
    11011104 
    1102         $a_msg_headers[$headers->uid] = $headers; 
    1103         } 
     1105      $a_msg_headers[$headers->uid] = $headers; 
    11041106      } 
    11051107 
     
    12241226      } 
    12251227    // 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)) { 
    12371238      if ($this->sort_order=="ASC") 
    12381239        asort($a_index); 
     
    14621463      $charset = $charset ? $charset : $this->default_charset; 
    14631464      $a_messages = iil_C_Sort($this->conn, $mailbox, $sort_field, $criteria, FALSE, $charset); 
     1465 
     1466      if (!$a_messages) 
     1467        return array(); 
    14641468      } 
    14651469    else { 
     
    14701474      else { 
    14711475        $a_messages = iil_C_Search($this->conn, $mailbox, ($charset ? "CHARSET $charset " : '') . $criteria); 
    1472      
     1476 
     1477        if (!$a_messages) 
     1478          return array(); 
     1479 
    14731480        // I didn't found that SEARCH always returns sorted IDs 
    14741481        if (!$this->sort_field) 
     
    15011508    // default sorting 
    15021509    if (!$this->sort_field || ($this->sort_field == 'date' && $this->threading == 'REFS')) { 
    1503         return array_keys($thread_tree); 
     1510        return array_keys((array)$thread_tree); 
    15041511      } 
    15051512    // here we'll implement REFS sorting, for performance reason 
     
    15091516        $a_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, 
    15101517            !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); 
    15111522        } 
    15121523      else { 
     
    15141525        $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, !empty($ids) ? $ids : "1:*", 
    15151526            $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 
    15161532        asort($a_index); // ASC 
    15171533        $a_index = array_values($a_index); 
  • program/lib/imap.inc

    rf52c936f r1845fb6  
    742742} 
    743743 
    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  
    770744function iil_C_Select(&$conn, $mailbox) { 
    771745 
     
    16201594    $encoding='US-ASCII') { 
    16211595 
    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'; 
    16271604                 
    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;    
    16481625} 
    16491626 
    16501627function iil_C_Search(&$conn, $folder, $criteria) { 
    16511628 
    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;    
    16771656} 
    16781657 
Note: See TracChangeset for help on using the changeset viewer.