public function getMessagesByCriteria($criteria = '', $number = 0, $start = 0, $order = 'DESC')
    {
        $emails = array();
        $result = imap_search($this->imap, $criteria);
        if(!$result){
            throw new ImapClientException('Messages not found. Or this criteria not supported on your email server.');
        };
        if ($number == 0)
        {
            $number = count($result);
        }
        if ($result)
        {
            $ids = array();
            foreach ($result as $k => $i)
            {
                $ids[] = $i;
            }
            $ids = array_chunk($ids, $number);
            $ids = array_slice($ids[0], $start, $number);

            $emails = array();
            foreach ($ids as $id)
            {
                $emails[] = $this->getMessage($id);
            }
        }
        if ($order == 'DESC')
        {
            $emails = array_reverse($emails);
        }

        return $emails;
    }
public function getMessagesByCriteria($criteria = '', $number = 0, $start = 0, $order = 'DESC')
    {
        $emails = array();
        $result = imap_search($this->imap, $criteria);
        if(!$result){
            throw new ImapClientException('Messages not found. Or this criteria not supported on your email server.');
        };
        if ($number == 0)
        {
            $number = count($result);
        }
        if ($result)
        {
            $ids = array();
            foreach ($result as $k => $i)
            {
                $ids[] = $i;
            }
            $ids = array_chunk($ids, $number);
            $ids = array_slice($ids[0], $start, $number);

            $emails = array();
            foreach ($ids as $id)
            {
                $emails[] = $this->getMessage($id);
            }
        }
        if ($order == 'DESC')
        {
            $emails = array_reverse($emails);
        }

        return $emails;
    }
public function getMessagesByCriteria ( $ criteria = '' , $ number = 0 , $ start = 0 , $ order = 'DESC' ) { $ emails = array ( ) ; $ result = imap_search ( $ this -> imap , $ criteria ) ; if ( ! $ result ) { throw new ImapClientException ( 'Messages not found. Or this criteria not supported on your email server.' ) ; } ; if ( $ number == 0 ) { $ number = count ( $ result ) ; } if ( $ result ) { $ ids = array ( ) ; foreach ( $ result as $ k => $ i ) { $ ids [ ] = $ i ; } $ ids = array_chunk ( $ ids , $ number ) ; $ ids = array_slice ( $ ids [ 0 ] , $ start , $ number ) ; $ emails = array ( ) ; foreach ( $ ids as $ id ) { $ emails [ ] = $ this -> getMessage ( $ id ) ; } } if ( $ order == 'DESC' ) { $ emails = array_reverse ( $ emails ) ; } return $ emails ; }
Get Messages by Criteria

@see http://php.net/manual/en/function.imap-search.php
@param string $criteria ALL, UNSEEN, FLAGGED, UNANSWERED, DELETED, UNDELETED, etc (e.g. FROM "joey smith")
@param int    $number
@param int    $start
@param string $order
@return array
@throws ImapClientException
Get Messages by Criteria