src/IMAP/Query/Query.php
public function get() {
        $messages = MessageCollection::make([]);

        try {
            $this->generate_query();

            /**
             * Don't set the charset if it isn't used - prevent strange outlook mail server errors
             * @see https://github.com/Webklex/laravel-imap/issues/100
             */
            if($this->getCharset() === null){
                $available_messages = imap_search($this->getClient()->getConnection(), $this->getRawQuery(), IMAP::SE_UID);
            }else{
                $available_messages = imap_search($this->getClient()->getConnection(), $this->getRawQuery(), IMAP::SE_UID, $this->getCharset());
            }

            if ($available_messages !== false) {

                $available_messages = collect($available_messages);
                $options = config('imap.options');

                if(strtolower($options['fetch_order']) === 'desc'){
                    $available_messages = $available_messages->reverse();
                }

                $query =& $this;

                $available_messages->forPage($this->page, $this->limit)->each(function($msgno, $msglist) use(&$messages, $options, $query) {
                    $oMessage = new Message($msgno, $msglist, $query->getClient(), $query->getFetchOptions(), $query->getFetchBody(), $query->getFetchAttachment(), $query->getFetchFlags());
                    switch ($options['message_key']){
                        case 'number':
                            $message_key = $oMessage->getMessageNo();
                            break;
                        case 'list':
                            $message_key = $msglist;
                            break;
                        default:
                            $message_key = $oMessage->getMessageId();
                            break;

                    }
                    $messages->put($message_key, $oMessage);
                });
            }

            return $messages;
        } catch (\Exception $e) {
            throw new GetMessagesFailedException($e->getMessage());
        }
    }
public function get() {
        $messages = MessageCollection::make([]);

        try {
            $this->generate_query();

            /**
             * Don't set the charset if it isn't used - prevent strange outlook mail server errors
             * @see https://github.com/Webklex/laravel-imap/issues/100
             */
            if($this->getCharset() === null){
                $available_messages = imap_search($this->getClient()->getConnection(), $this->getRawQuery(), IMAP::SE_UID);
            }else{
                $available_messages = imap_search($this->getClient()->getConnection(), $this->getRawQuery(), IMAP::SE_UID, $this->getCharset());
            }

            if ($available_messages !== false) {

                $available_messages = collect($available_messages);
                $options = config('imap.options');

                if(strtolower($options['fetch_order']) === 'desc'){
                    $available_messages = $available_messages->reverse();
                }

                $query =& $this;

                $available_messages->forPage($this->page, $this->limit)->each(function($msgno, $msglist) use(&$messages, $options, $query) {
                    $oMessage = new Message($msgno, $msglist, $query->getClient(), $query->getFetchOptions(), $query->getFetchBody(), $query->getFetchAttachment(), $query->getFetchFlags());
                    switch ($options['message_key']){
                        case 'number':
                            $message_key = $oMessage->getMessageNo();
                            break;
                        case 'list':
                            $message_key = $msglist;
                            break;
                        default:
                            $message_key = $oMessage->getMessageId();
                            break;

                    }
                    $messages->put($message_key, $oMessage);
                });
            }

            return $messages;
        } catch (\Exception $e) {
            throw new GetMessagesFailedException($e->getMessage());
        }
    }
public function get ( ) { $ messages = MessageCollection :: make ( [ ] ) ; try { $ this -> generate_query ( ) ; /**
             * Don't set the charset if it isn't used - prevent strange outlook mail server errors
             * @see https://github.com/Webklex/laravel-imap/issues/100
             */ if ( $ this -> getCharset ( ) === null ) { $ available_messages = imap_search ( $ this -> getClient ( ) -> getConnection ( ) , $ this -> getRawQuery ( ) , IMAP :: SE_UID ) ; } else { $ available_messages = imap_search ( $ this -> getClient ( ) -> getConnection ( ) , $ this -> getRawQuery ( ) , IMAP :: SE_UID , $ this -> getCharset ( ) ) ; } if ( $ available_messages !== false ) { $ available_messages = collect ( $ available_messages ) ; $ options = config ( 'imap.options' ) ; if ( strtolower ( $ options [ 'fetch_order' ] ) === 'desc' ) { $ available_messages = $ available_messages -> reverse ( ) ; } $ query = & $ this ; $ available_messages -> forPage ( $ this -> page , $ this -> limit ) -> each ( function ( $ msgno , $ msglist ) use ( & $ messages , $ options , $ query ) { $ oMessage = new Message ( $ msgno , $ msglist , $ query -> getClient ( ) , $ query -> getFetchOptions ( ) , $ query -> getFetchBody ( ) , $ query -> getFetchAttachment ( ) , $ query -> getFetchFlags ( ) ) ; switch ( $ options [ 'message_key' ] ) { case 'number' : $ message_key = $ oMessage -> getMessageNo ( ) ; break ; case 'list' : $ message_key = $ msglist ; break ; default : $ message_key = $ oMessage -> getMessageId ( ) ; break ; } $ messages -> put ( $ message_key , $ oMessage ) ; } ) ; } return $ messages ; } catch ( \ Exception $ e ) { throw new GetMessagesFailedException ( $ e -> getMessage ( ) ) ; } }
Fetch the current query and return all found messages

@return MessageCollection
@throws GetMessagesFailedException
Fetch the current query and return all found messages