roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
public function sort($mailbox, $field = 'ARRIVAL', $criteria = '', $return_uid = false, $encoding = 'US-ASCII')
    {
        $old_sel   = $this->selected;
        $supported = array('ARRIVAL', 'CC', 'DATE', 'FROM', 'SIZE', 'SUBJECT', 'TO');
        $field     = strtoupper($field);

        if ($field == 'INTERNALDATE') {
            $field = 'ARRIVAL';
        }

        if (!in_array($field, $supported)) {
            return new rcube_result_index($mailbox);
        }

        if (!$this->select($mailbox)) {
            return new rcube_result_index($mailbox);
        }

        // return empty result when folder is empty and we're just after SELECT
        if ($old_sel != $mailbox && !$this->data['EXISTS']) {
            return new rcube_result_index($mailbox, '* SORT');
        }

        // RFC 5957: SORT=DISPLAY
        if (($field == 'FROM' || $field == 'TO') && $this->getCapability('SORT=DISPLAY')) {
            $field = 'DISPLAY' . $field;
        }

        $encoding = $encoding ? trim($encoding) : 'US-ASCII';
        $criteria = $criteria ? 'ALL ' . trim($criteria) : 'ALL';

        list($code, $response) = $this->execute($return_uid ? 'UID SORT' : 'SORT',
            array("($field)", $encoding, $criteria));

        if ($code != self::ERROR_OK) {
            $response = null;
        }

        return new rcube_result_index($mailbox, $response);
    }
public function sort($mailbox, $field = 'ARRIVAL', $criteria = '', $return_uid = false, $encoding = 'US-ASCII')
    {
        $old_sel   = $this->selected;
        $supported = array('ARRIVAL', 'CC', 'DATE', 'FROM', 'SIZE', 'SUBJECT', 'TO');
        $field     = strtoupper($field);

        if ($field == 'INTERNALDATE') {
            $field = 'ARRIVAL';
        }

        if (!in_array($field, $supported)) {
            return new rcube_result_index($mailbox);
        }

        if (!$this->select($mailbox)) {
            return new rcube_result_index($mailbox);
        }

        // return empty result when folder is empty and we're just after SELECT
        if ($old_sel != $mailbox && !$this->data['EXISTS']) {
            return new rcube_result_index($mailbox, '* SORT');
        }

        // RFC 5957: SORT=DISPLAY
        if (($field == 'FROM' || $field == 'TO') && $this->getCapability('SORT=DISPLAY')) {
            $field = 'DISPLAY' . $field;
        }

        $encoding = $encoding ? trim($encoding) : 'US-ASCII';
        $criteria = $criteria ? 'ALL ' . trim($criteria) : 'ALL';

        list($code, $response) = $this->execute($return_uid ? 'UID SORT' : 'SORT',
            array("($field)", $encoding, $criteria));

        if ($code != self::ERROR_OK) {
            $response = null;
        }

        return new rcube_result_index($mailbox, $response);
    }
public function sort ( $ mailbox , $ field = 'ARRIVAL' , $ criteria = '' , $ return_uid = false , $ encoding = 'US-ASCII' ) { $ old_sel = $ this -> selected ; $ supported = array ( 'ARRIVAL' , 'CC' , 'DATE' , 'FROM' , 'SIZE' , 'SUBJECT' , 'TO' ) ; $ field = strtoupper ( $ field ) ; if ( $ field == 'INTERNALDATE' ) { $ field = 'ARRIVAL' ; } if ( ! in_array ( $ field , $ supported ) ) { return new rcube_result_index ( $ mailbox ) ; } if ( ! $ this -> select ( $ mailbox ) ) { return new rcube_result_index ( $ mailbox ) ; } // return empty result when folder is empty and we're just after SELECT if ( $ old_sel != $ mailbox && ! $ this -> data [ 'EXISTS' ] ) { return new rcube_result_index ( $ mailbox , '* SORT' ) ; } // RFC 5957: SORT=DISPLAY if ( ( $ field == 'FROM' || $ field == 'TO' ) && $ this -> getCapability ( 'SORT=DISPLAY' ) ) { $ field = 'DISPLAY' . $ field ; } $ encoding = $ encoding ? trim ( $ encoding ) : 'US-ASCII' ; $ criteria = $ criteria ? 'ALL ' . trim ( $ criteria ) : 'ALL' ; list ( $ code , $ response ) = $ this -> execute ( $ return_uid ? 'UID SORT' : 'SORT' , array ( "($field)" , $ encoding , $ criteria ) ) ; if ( $ code != self :: ERROR_OK ) { $ response = null ; } return new rcube_result_index ( $ mailbox , $ response ) ; }
Executes SORT command

@param string $mailbox    Mailbox name
@param string $field      Field to sort by (ARRIVAL, CC, DATE, FROM, SIZE, SUBJECT, TO)
@param string $criteria   Searching criteria
@param bool   $return_uid Enables UID SORT usage
@param string $encoding   Character set

@return rcube_result_index Response data
Executes SORT command