roundcubemail/program/lib/Roundcube/rcube_imap.php
protected function search_index($folder, $criteria='ALL', $charset=NULL, $sort_field=NULL)
    {
        if (!$this->check_connection()) {
            if ($this->threading) {
                return new rcube_result_thread();
            }
            else {
                return new rcube_result_index();
            }
        }

        if ($this->options['skip_deleted'] && !preg_match('/UNDELETED/', $criteria)) {
            $criteria = 'UNDELETED '.$criteria;
        }

        // unset CHARSET if criteria string is ASCII, this way
        // SEARCH won't be re-sent after "unsupported charset" response
        if ($charset && $charset != 'US-ASCII' && is_ascii($criteria)) {
            $charset = 'US-ASCII';
        }

        if ($this->threading) {
            $threads = $this->conn->thread($folder, $this->threading, $criteria, true, $charset);

            // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8,
            // but I've seen that Courier doesn't support UTF-8)
            if ($threads->is_error() && $charset && $charset != 'US-ASCII') {
                $threads = $this->conn->thread($folder, $this->threading,
                    self::convert_criteria($criteria, $charset), true, 'US-ASCII');
            }

            return $threads;
        }

        if ($sort_field && $this->get_capability('SORT')) {
            $charset  = $charset ? $charset : $this->default_charset;
            $messages = $this->conn->sort($folder, $sort_field, $criteria, true, $charset);

            // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8,
            // but I've seen Courier with disabled UTF-8 support)
            if ($messages->is_error() && $charset && $charset != 'US-ASCII') {
                $messages = $this->conn->sort($folder, $sort_field,
                    self::convert_criteria($criteria, $charset), true, 'US-ASCII');
            }

            if (!$messages->is_error()) {
                $this->search_sorted = true;
                return $messages;
            }
        }

        $messages = $this->conn->search($folder,
            ($charset && $charset != 'US-ASCII' ? "CHARSET $charset " : '') . $criteria, true);

        // Error, try with US-ASCII (some servers may support only US-ASCII)
        if ($messages->is_error() && $charset && $charset != 'US-ASCII') {
            $messages = $this->conn->search($folder,
                self::convert_criteria($criteria, $charset), true);
        }

        $this->search_sorted = false;

        return $messages;
    }
protected function search_index($folder, $criteria='ALL', $charset=NULL, $sort_field=NULL)
    {
        if (!$this->check_connection()) {
            if ($this->threading) {
                return new rcube_result_thread();
            }
            else {
                return new rcube_result_index();
            }
        }

        if ($this->options['skip_deleted'] && !preg_match('/UNDELETED/', $criteria)) {
            $criteria = 'UNDELETED '.$criteria;
        }

        // unset CHARSET if criteria string is ASCII, this way
        // SEARCH won't be re-sent after "unsupported charset" response
        if ($charset && $charset != 'US-ASCII' && is_ascii($criteria)) {
            $charset = 'US-ASCII';
        }

        if ($this->threading) {
            $threads = $this->conn->thread($folder, $this->threading, $criteria, true, $charset);

            // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8,
            // but I've seen that Courier doesn't support UTF-8)
            if ($threads->is_error() && $charset && $charset != 'US-ASCII') {
                $threads = $this->conn->thread($folder, $this->threading,
                    self::convert_criteria($criteria, $charset), true, 'US-ASCII');
            }

            return $threads;
        }

        if ($sort_field && $this->get_capability('SORT')) {
            $charset  = $charset ? $charset : $this->default_charset;
            $messages = $this->conn->sort($folder, $sort_field, $criteria, true, $charset);

            // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8,
            // but I've seen Courier with disabled UTF-8 support)
            if ($messages->is_error() && $charset && $charset != 'US-ASCII') {
                $messages = $this->conn->sort($folder, $sort_field,
                    self::convert_criteria($criteria, $charset), true, 'US-ASCII');
            }

            if (!$messages->is_error()) {
                $this->search_sorted = true;
                return $messages;
            }
        }

        $messages = $this->conn->search($folder,
            ($charset && $charset != 'US-ASCII' ? "CHARSET $charset " : '') . $criteria, true);

        // Error, try with US-ASCII (some servers may support only US-ASCII)
        if ($messages->is_error() && $charset && $charset != 'US-ASCII') {
            $messages = $this->conn->search($folder,
                self::convert_criteria($criteria, $charset), true);
        }

        $this->search_sorted = false;

        return $messages;
    }
protected function search_index ( $ folder , $ criteria = 'ALL' , $ charset = NULL , $ sort_field = NULL ) { if ( ! $ this -> check_connection ( ) ) { if ( $ this -> threading ) { return new rcube_result_thread ( ) ; } else { return new rcube_result_index ( ) ; } } if ( $ this -> options [ 'skip_deleted' ] && ! preg_match ( '/UNDELETED/' , $ criteria ) ) { $ criteria = 'UNDELETED ' . $ criteria ; } // unset CHARSET if criteria string is ASCII, this way // SEARCH won't be re-sent after "unsupported charset" response if ( $ charset && $ charset != 'US-ASCII' && is_ascii ( $ criteria ) ) { $ charset = 'US-ASCII' ; } if ( $ this -> threading ) { $ threads = $ this -> conn -> thread ( $ folder , $ this -> threading , $ criteria , true , $ charset ) ; // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8, // but I've seen that Courier doesn't support UTF-8) if ( $ threads -> is_error ( ) && $ charset && $ charset != 'US-ASCII' ) { $ threads = $ this -> conn -> thread ( $ folder , $ this -> threading , self :: convert_criteria ( $ criteria , $ charset ) , true , 'US-ASCII' ) ; } return $ threads ; } if ( $ sort_field && $ this -> get_capability ( 'SORT' ) ) { $ charset = $ charset ? $ charset : $ this -> default_charset ; $ messages = $ this -> conn -> sort ( $ folder , $ sort_field , $ criteria , true , $ charset ) ; // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8, // but I've seen Courier with disabled UTF-8 support) if ( $ messages -> is_error ( ) && $ charset && $ charset != 'US-ASCII' ) { $ messages = $ this -> conn -> sort ( $ folder , $ sort_field , self :: convert_criteria ( $ criteria , $ charset ) , true , 'US-ASCII' ) ; } if ( ! $ messages -> is_error ( ) ) { $ this -> search_sorted = true ; return $ messages ; } } $ messages = $ this -> conn -> search ( $ folder , ( $ charset && $ charset != 'US-ASCII' ? "CHARSET $charset " : '' ) . $ criteria , true ) ; // Error, try with US-ASCII (some servers may support only US-ASCII) if ( $ messages -> is_error ( ) && $ charset && $ charset != 'US-ASCII' ) { $ messages = $ this -> conn -> search ( $ folder , self :: convert_criteria ( $ criteria , $ charset ) , true ) ; } $ this -> search_sorted = false ; return $ messages ; }
protected search method

@param string $folder     Folder name
@param string $criteria   Search criteria
@param string $charset    Charset
@param string $sort_field Sorting field

@return rcube_result_index|rcube_result_thread  Search results (UIDs)
@see rcube_imap::search()
protected search method