src/Imap.php
private function getEmailResponse($command, $parameters = array(), $first = false)
    {
        //send out the command
        if (!$this->send($command, $parameters)) {
            return false;
        }

        $messageId  = $uniqueId = $count = 0;
        $emails     = $email = array();
        $start      = time();

        //while there is no hang
        while (time() < ($start + self::TIMEOUT)) {
            //get a response line
            $line = str_replace("\n", '', $this->getLine());

            //if the line starts with a fetch
            //it means it's the end of getting an email
            if (strpos($line, 'FETCH') !== false && strpos($line, 'TAG'.$this->tag) === false) {
                //if there is email data
                if (!empty($email)) {
                    //create the email format and add it to emails
                    $emails[$uniqueId] = $this->getEmailFormat($email, $uniqueId, $flags);

                    //if all we want is the first one
                    if ($first) {
                        //just return this
                        return $emails[$uniqueId];
                    }

                    //make email data empty again
                    $email = array();
                }

                //if just okay
                if (strpos($line, 'OK') !== false) {
                    //then skip the rest
                    continue;
                }

                //if it's not just ok
                //it will contain the message id and the unique id and flags
                $flags = array();
                if (strpos($line, '\Answered') !== false) {
                    $flags[] = 'answered';
                }

                if (strpos($line, '\Flagged') !== false) {
                    $flags[] = 'flagged';
                }

                if (strpos($line, '\Deleted') !== false) {
                    $flags[] = 'deleted';
                }

                if (strpos($line, '\Seen') !== false) {
                    $flags[] = 'seen';
                }

                if (strpos($line, '\Draft') !== false) {
                    $flags[] = 'draft';
                }

                $findUid = explode(' ', $line);
                foreach ($findUid as $i => $uid) {
                    if (is_numeric($uid)) {
                        $uniqueId = $uid;
                    }
                    if (strpos(strtolower($uid), 'uid') !== false) {
                        $uniqueId = $findUid[$i+1];
                        break;
                    }
                }

                //skip the rest
                continue;
            }

            //if there is a tag it means we are at the end
            if (strpos($line, 'TAG'.$this->tag) !== false) {
                //if email details are not empty and the last line is just a )
                if (!empty($email) && strpos(trim($email[count($email) -1]), ')') === 0) {
                    //take it out because that is not part of the details
                    array_pop($email);
                }

                //if there is email data
                if (!empty($email)) {
                    //create the email format and add it to emails
                    $emails[$uniqueId] = $this->getEmailFormat($email, $uniqueId, $flags);

                    //if all we want is the first one
                    if ($first) {
                        //just return this
                        return $emails[$uniqueId];
                    }
                }

                //break out of this loop
                break;
            }

            //so at this point we are getting raw data
            //capture this data in email details
            $email[] = $line;
        }

        return $emails;
    }
private function getEmailResponse($command, $parameters = array(), $first = false)
    {
        //send out the command
        if (!$this->send($command, $parameters)) {
            return false;
        }

        $messageId  = $uniqueId = $count = 0;
        $emails     = $email = array();
        $start      = time();

        //while there is no hang
        while (time() < ($start + self::TIMEOUT)) {
            //get a response line
            $line = str_replace("\n", '', $this->getLine());

            //if the line starts with a fetch
            //it means it's the end of getting an email
            if (strpos($line, 'FETCH') !== false && strpos($line, 'TAG'.$this->tag) === false) {
                //if there is email data
                if (!empty($email)) {
                    //create the email format and add it to emails
                    $emails[$uniqueId] = $this->getEmailFormat($email, $uniqueId, $flags);

                    //if all we want is the first one
                    if ($first) {
                        //just return this
                        return $emails[$uniqueId];
                    }

                    //make email data empty again
                    $email = array();
                }

                //if just okay
                if (strpos($line, 'OK') !== false) {
                    //then skip the rest
                    continue;
                }

                //if it's not just ok
                //it will contain the message id and the unique id and flags
                $flags = array();
                if (strpos($line, '\Answered') !== false) {
                    $flags[] = 'answered';
                }

                if (strpos($line, '\Flagged') !== false) {
                    $flags[] = 'flagged';
                }

                if (strpos($line, '\Deleted') !== false) {
                    $flags[] = 'deleted';
                }

                if (strpos($line, '\Seen') !== false) {
                    $flags[] = 'seen';
                }

                if (strpos($line, '\Draft') !== false) {
                    $flags[] = 'draft';
                }

                $findUid = explode(' ', $line);
                foreach ($findUid as $i => $uid) {
                    if (is_numeric($uid)) {
                        $uniqueId = $uid;
                    }
                    if (strpos(strtolower($uid), 'uid') !== false) {
                        $uniqueId = $findUid[$i+1];
                        break;
                    }
                }

                //skip the rest
                continue;
            }

            //if there is a tag it means we are at the end
            if (strpos($line, 'TAG'.$this->tag) !== false) {
                //if email details are not empty and the last line is just a )
                if (!empty($email) && strpos(trim($email[count($email) -1]), ')') === 0) {
                    //take it out because that is not part of the details
                    array_pop($email);
                }

                //if there is email data
                if (!empty($email)) {
                    //create the email format and add it to emails
                    $emails[$uniqueId] = $this->getEmailFormat($email, $uniqueId, $flags);

                    //if all we want is the first one
                    if ($first) {
                        //just return this
                        return $emails[$uniqueId];
                    }
                }

                //break out of this loop
                break;
            }

            //so at this point we are getting raw data
            //capture this data in email details
            $email[] = $line;
        }

        return $emails;
    }
private function getEmailResponse ( $ command , $ parameters = array ( ) , $ first = false ) { //send out the command if ( ! $ this -> send ( $ command , $ parameters ) ) { return false ; } $ messageId = $ uniqueId = $ count = 0 ; $ emails = $ email = array ( ) ; $ start = time ( ) ; //while there is no hang while ( time ( ) < ( $ start + self :: TIMEOUT ) ) { //get a response line $ line = str_replace ( "\n" , '' , $ this -> getLine ( ) ) ; //if the line starts with a fetch //it means it's the end of getting an email if ( strpos ( $ line , 'FETCH' ) !== false && strpos ( $ line , 'TAG' . $ this -> tag ) === false ) { //if there is email data if ( ! empty ( $ email ) ) { //create the email format and add it to emails $ emails [ $ uniqueId ] = $ this -> getEmailFormat ( $ email , $ uniqueId , $ flags ) ; //if all we want is the first one if ( $ first ) { //just return this return $ emails [ $ uniqueId ] ; } //make email data empty again $ email = array ( ) ; } //if just okay if ( strpos ( $ line , 'OK' ) !== false ) { //then skip the rest continue ; } //if it's not just ok //it will contain the message id and the unique id and flags $ flags = array ( ) ; if ( strpos ( $ line , '\Answered' ) !== false ) { $ flags [ ] = 'answered' ; } if ( strpos ( $ line , '\Flagged' ) !== false ) { $ flags [ ] = 'flagged' ; } if ( strpos ( $ line , '\Deleted' ) !== false ) { $ flags [ ] = 'deleted' ; } if ( strpos ( $ line , '\Seen' ) !== false ) { $ flags [ ] = 'seen' ; } if ( strpos ( $ line , '\Draft' ) !== false ) { $ flags [ ] = 'draft' ; } $ findUid = explode ( ' ' , $ line ) ; foreach ( $ findUid as $ i => $ uid ) { if ( is_numeric ( $ uid ) ) { $ uniqueId = $ uid ; } if ( strpos ( strtolower ( $ uid ) , 'uid' ) !== false ) { $ uniqueId = $ findUid [ $ i + 1 ] ; break ; } } //skip the rest continue ; } //if there is a tag it means we are at the end if ( strpos ( $ line , 'TAG' . $ this -> tag ) !== false ) { //if email details are not empty and the last line is just a ) if ( ! empty ( $ email ) && strpos ( trim ( $ email [ count ( $ email ) - 1 ] ) , ')' ) === 0 ) { //take it out because that is not part of the details array_pop ( $ email ) ; } //if there is email data if ( ! empty ( $ email ) ) { //create the email format and add it to emails $ emails [ $ uniqueId ] = $ this -> getEmailFormat ( $ email , $ uniqueId , $ flags ) ; //if all we want is the first one if ( $ first ) { //just return this return $ emails [ $ uniqueId ] ; } } //break out of this loop break ; } //so at this point we are getting raw data //capture this data in email details $ email [ ] = $ line ; } return $ emails ; }
Splits emails into arrays

@param *string $command    The IMAP command
@param array   $parameters Any extra parameters
@param bool    $first      Whether the return should just be the first

@return array
Splits emails into arrays