public function getUnreadMessages($read = true) {
        $emails = [];
        $result = imap_search($this->imap, 'UNSEEN');
        if(!$result){
            throw new ImapClientException('No read messages were found.');
        };
        $ids = ''; $countId = count($result);
        foreach($result as $key=>$id) {
            $emails[]= $this->getMessage($id);
            if(($countId-1) == $key){
                $ids .= $id;
            }else{
                $ids .= $id.',';
            };
        }
        /* Set flag UNSEEN */
        if(!$read){
            $this->setUnseenMessage($ids);
        }else{
            $this->setSeenMessage($ids);
        };
        return $emails;
    }
public function getUnreadMessages($read = true) {
        $emails = [];
        $result = imap_search($this->imap, 'UNSEEN');
        if(!$result){
            throw new ImapClientException('No read messages were found.');
        };
        $ids = ''; $countId = count($result);
        foreach($result as $key=>$id) {
            $emails[]= $this->getMessage($id);
            if(($countId-1) == $key){
                $ids .= $id;
            }else{
                $ids .= $id.',';
            };
        }
        /* Set flag UNSEEN */
        if(!$read){
            $this->setUnseenMessage($ids);
        }else{
            $this->setSeenMessage($ids);
        };
        return $emails;
    }
public function getUnreadMessages ( $ read = true ) { $ emails = [ ] ; $ result = imap_search ( $ this -> imap , 'UNSEEN' ) ; if ( ! $ result ) { throw new ImapClientException ( 'No read messages were found.' ) ; } ; $ ids = '' ; $ countId = count ( $ result ) ; foreach ( $ result as $ key => $ id ) { $ emails [ ] = $ this -> getMessage ( $ id ) ; if ( ( $ countId - 1 ) == $ key ) { $ ids .= $ id ; } else { $ ids .= $ id . ',' ; } ; } /* Set flag UNSEEN */ if ( ! $ read ) { $ this -> setUnseenMessage ( $ ids ) ; } else { $ this -> setSeenMessage ( $ ids ) ; } ; return $ emails ; }
Returns unseen emails in the current folder

@param bool $read Mark message like SEEN or no.
@return array objects IncomingMessage
@throws ImapClientException
Returns unseen emails in the current folder