Changeset 4014 in subversion


Ignore:
Timestamp:
Sep 29, 2010 9:46:30 AM (3 years ago)
Author:
alec
Message:
  • Use custom sorting when SORT is disabled by IMAP admin (#1486959)
Location:
trunk/roundcubemail
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r4013 r4014  
    88- Add option to "Return receipt" will be always checked (#1486352) 
    99- Fix HTML to plain text conversion doesn't handle citation blocks (#1486921) 
     10- Use custom sorting when SORT is disabled by IMAP admin (#1486959) 
    1011 
    1112RELEASE 0.4.1 
  • trunk/roundcubemail/program/include/rcube_imap.php

    r4009 r4014  
    6363    private $search_sort_field = ''; 
    6464    private $search_threads = false; 
     65    private $search_sorted = false; 
    6566    private $db_header_fields = array('idx', 'uid', 'subject', 'from', 'to', 'cc', 'date', 'size'); 
    6667    private $options = array('auth_method' => 'check'); 
     
    293294     * @param  string  Charset of search string 
    294295     * @param  string  Sorting field 
    295      */ 
    296     function set_search_set($str=null, $msgs=null, $charset=null, $sort_field=null, $threads=false) 
     296     * @param  string  True if set is sorted (SORT was used for searching) 
     297     */ 
     298    function set_search_set($str=null, $msgs=null, $charset=null, $sort_field=null, $threads=false, $sorted=false) 
    297299    { 
    298300        if (is_array($str) && $msgs == null) 
     
    308310        $this->search_sort_field = $sort_field; 
    309311        $this->search_threads    = $threads; 
     312        $this->search_sorted     = $sorted; 
    310313    } 
    311314 
     
    322325                $this->search_sort_field, 
    323326                $this->search_threads, 
     327                $this->search_sorted, 
    324328            ); 
    325329    } 
     
    616620        } 
    617621        // use SORT command 
    618         else if ($this->get_capability('SORT')) { 
    619             if ($msg_index = $this->conn->sort($mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : '')) { 
     622        else if ($this->get_capability('SORT') && 
     623            // Courier-IMAP provides SORT capability but allows to disable it by admin (#1486959) 
     624            ($msg_index = $this->conn->sort($mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : '')) !== false 
     625        ) { 
     626            if (!empty($msg_index)) { 
    620627                list($begin, $end) = $this->_get_message_range(count($msg_index), $page); 
    621628                $max = max($msg_index); 
     
    859866 
    860867        // sorted messages, so we can first slice array and then fetch only wanted headers 
    861         if ($this->get_capability('SORT')) { // SORT searching result 
     868        if ($this->search_sorted) { // SORT searching result 
    862869            // reset search set if sorting field has been changed 
    863870            if ($this->sort_field && $this->search_sort_field != $this->sort_field) 
     
    11691176            } 
    11701177            // sort with SORT command 
    1171             else if ($this->get_capability('SORT')) { 
     1178            else if ($this->search_sorted) { 
    11721179                if ($this->sort_field && $this->search_sort_field != $this->sort_field) 
    11731180                    $this->search('', $this->search_string, $this->search_charset, $this->sort_field); 
     
    12251232        } 
    12261233        // fetch complete message index 
    1227         else if ($this->get_capability('SORT')) { 
    1228             $a_index = $this->conn->sort($mailbox, 
    1229                 $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''); 
    1230  
    1231             if ($a_index !== false && $this->sort_order == 'DESC') 
     1234        else if ($this->get_capability('SORT') && 
     1235            ($a_index = $this->conn->sort($mailbox, 
     1236                $this->sort_field, $this->skip_deleted ? 'UNDELETED' : '')) !== false 
     1237        ) { 
     1238            if ($this->sort_order == 'DESC') 
    12321239                $a_index = array_reverse($a_index); 
    12331240 
     
    14401447        $results = $this->_search_index($mailbox, $str, $charset, $sort_field); 
    14411448 
    1442         $this->set_search_set($str, $results, $charset, $sort_field, (bool)$this->threading); 
     1449        $this->set_search_set($str, $results, $charset, $sort_field, (bool)$this->threading, 
     1450            $this->threading || $this->search_sorted ? true : false); 
    14431451 
    14441452        return $results; 
     
    14771485                ); 
    14781486            } 
    1479         } 
    1480         else if ($sort_field && $this->get_capability('SORT')) { 
     1487 
     1488            return $a_messages; 
     1489        } 
     1490         
     1491        if ($sort_field && $this->get_capability('SORT')) { 
    14811492            $charset = $charset ? $charset : $this->default_charset; 
    14821493            $a_messages = $this->conn->sort($mailbox, $sort_field, $criteria, false, $charset); 
     
    14871498                $a_messages = $this->conn->sort($mailbox, $sort_field, 
    14881499                    $this->convert_criteria($criteria, $charset), false, 'US-ASCII'); 
     1500 
     1501            if ($a_messages !== false) { 
     1502                $this->search_sorted = true; 
     1503                return $a_messages; 
     1504            } 
     1505        } 
     1506 
     1507        if ($orig_criteria == 'ALL') { 
     1508            $max = $this->_messagecount($mailbox); 
     1509            $a_messages = $max ? range(1, $max) : array(); 
    14891510        } 
    14901511        else { 
    1491             if ($orig_criteria == 'ALL') { 
    1492                 $max = $this->_messagecount($mailbox); 
    1493                 $a_messages = $max ? range(1, $max) : array(); 
    1494             } 
    1495             else { 
     1512            $a_messages = $this->conn->search($mailbox, 
     1513                ($charset ? "CHARSET $charset " : '') . $criteria); 
     1514 
     1515            // Error, try with US-ASCII (some servers may support only US-ASCII) 
     1516            if ($a_messages === false && $charset && $charset != 'US-ASCII') 
    14961517                $a_messages = $this->conn->search($mailbox, 
    1497                     ($charset ? "CHARSET $charset " : '') . $criteria); 
    1498  
    1499                 // Error, try with US-ASCII (some servers may support only US-ASCII) 
    1500                 if ($a_messages === false && $charset && $charset != 'US-ASCII') 
    1501                     $a_messages = $this->conn->search($mailbox, 
    1502                         'CHARSET US-ASCII ' . $this->convert_criteria($criteria, $charset)); 
    1503  
    1504                 // I didn't found that SEARCH should return sorted IDs 
    1505                     if (is_array($a_messages) && !$this->sort_field) 
    1506                     sort($a_messages); 
    1507             } 
    1508         } 
    1509  
    1510         // update messagecount cache ? 
    1511 //      $a_mailbox_cache = get_cache('messagecount'); 
    1512 //      $a_mailbox_cache[$mailbox][$criteria] = sizeof($a_messages); 
    1513 //      $this->update_cache('messagecount', $a_mailbox_cache); 
     1518                    'CHARSET US-ASCII ' . $this->convert_criteria($criteria, $charset)); 
     1519 
     1520            // I didn't found that SEARCH should return sorted IDs 
     1521            if (is_array($a_messages) && !$this->sort_field) 
     1522                sort($a_messages); 
     1523        } 
     1524 
     1525        $this->search_sorted = false; 
    15141526 
    15151527        return $a_messages; 
     
    15921604        else { // ($sort_field == 'date' && $this->threading != 'REFS') 
    15931605            // use SORT command 
    1594             if ($this->get_capability('SORT')) { 
    1595                 $a_index = $this->conn->sort($mailbox, $this->sort_field, 
    1596                         !empty($ids) ? $ids : ($this->skip_deleted ? 'UNDELETED' : '')); 
    1597  
     1606            if ($this->get_capability('SORT') &&  
     1607                ($a_index = $this->conn->sort($mailbox, $this->sort_field, 
     1608                        !empty($ids) ? $ids : ($this->skip_deleted ? 'UNDELETED' : ''))) !== false 
     1609            ) { 
    15981610                    // return unsorted tree if we've got no index data 
    15991611                    if (!$a_index) 
     
    16731685        if (!empty($this->search_string)) 
    16741686            $this->search_set = $this->search('', $this->search_string, $this->search_charset, 
    1675                 $this->search_sort_field, $this->search_threads); 
     1687                $this->search_sort_field, $this->search_threads, $this->search_sorted); 
    16761688 
    16771689        return $this->get_search_set(); 
Note: See TracChangeset for help on using the changeset viewer.