public function fetchMessages()
    {

        //count the messages
        $this->countMessages();

        //if there are zero emails report this to the user
        if ($this->email_count == 0) {

            $this->log('There are no emails to process!');

            return false;
        }

        $this->log($this->email_count . ' ' . \Strings::pluralize($this->email_count, 'email') . ' to process.');

        for ($i = 1; $i < $this->email_count + 1; $i++) {

            $email = new Email;

            //set the message index in case we want to delete it later
            $email->index = $i;

            //get all the header info
            $this->parseHeaderInfo($email, imap_headerinfo($this->inbox, $i));

            $structure = \imap_fetchstructure($this->inbox, $i);

            //the type of email format
            $email->subtype = \strtolower($structure->subtype);

            $email->structure = $structure;

            //if the email is divided into parts, html, plain, attachments, etc
            if (isset($structure->parts)) {

                $part_id = 1;

                foreach ($structure->parts as $part) {

                    //get type 0 = text, 1 = multipart, 2 = message,
                    //3 = application, 4 = audio, 5= image, 6= video, 7 = other
                    $type = $part->type;

                    //multipart
                    $sub_id = 1;
                    if ($type == 1 && isset($part->parts)) {
                        foreach ($part->parts as $part) {
                            $part->part_id = $part_id . '.' . $sub_id;
                            $this->examinePart($email, $part);

                            $sub_id++;
                        }
                    } else {
                        $part->part_id = $part_id;
                        $this->examinePart($email, $part, $part_id);
                    }

                    $part_id++;
                }
            } else {

                //it is just a plain text email
                $email->body = \imap_fetchbody($this->inbox, $i, 1);
                $email->body_encoding = $structure->encoding;
            }

            //if the body is base64 encoded, decode it
            if ($email->body_encoding == 3) {
                $email->body = \base64_decode($email->body);
            }

            $this->log(print_r($email, 1));

            //store the email
            $this->emails[] = $email;
        }
    }
public function fetchMessages()
    {

        //count the messages
        $this->countMessages();

        //if there are zero emails report this to the user
        if ($this->email_count == 0) {

            $this->log('There are no emails to process!');

            return false;
        }

        $this->log($this->email_count . ' ' . \Strings::pluralize($this->email_count, 'email') . ' to process.');

        for ($i = 1; $i < $this->email_count + 1; $i++) {

            $email = new Email;

            //set the message index in case we want to delete it later
            $email->index = $i;

            //get all the header info
            $this->parseHeaderInfo($email, imap_headerinfo($this->inbox, $i));

            $structure = \imap_fetchstructure($this->inbox, $i);

            //the type of email format
            $email->subtype = \strtolower($structure->subtype);

            $email->structure = $structure;

            //if the email is divided into parts, html, plain, attachments, etc
            if (isset($structure->parts)) {

                $part_id = 1;

                foreach ($structure->parts as $part) {

                    //get type 0 = text, 1 = multipart, 2 = message,
                    //3 = application, 4 = audio, 5= image, 6= video, 7 = other
                    $type = $part->type;

                    //multipart
                    $sub_id = 1;
                    if ($type == 1 && isset($part->parts)) {
                        foreach ($part->parts as $part) {
                            $part->part_id = $part_id . '.' . $sub_id;
                            $this->examinePart($email, $part);

                            $sub_id++;
                        }
                    } else {
                        $part->part_id = $part_id;
                        $this->examinePart($email, $part, $part_id);
                    }

                    $part_id++;
                }
            } else {

                //it is just a plain text email
                $email->body = \imap_fetchbody($this->inbox, $i, 1);
                $email->body_encoding = $structure->encoding;
            }

            //if the body is base64 encoded, decode it
            if ($email->body_encoding == 3) {
                $email->body = \base64_decode($email->body);
            }

            $this->log(print_r($email, 1));

            //store the email
            $this->emails[] = $email;
        }
    }
public function fetchMessages ( ) { //count the messages $ this -> countMessages ( ) ; //if there are zero emails report this to the user if ( $ this -> email_count == 0 ) { $ this -> log ( 'There are no emails to process!' ) ; return false ; } $ this -> log ( $ this -> email_count . ' ' . \ Strings :: pluralize ( $ this -> email_count , 'email' ) . ' to process.' ) ; for ( $ i = 1 ; $ i < $ this -> email_count + 1 ; $ i ++ ) { $ email = new Email ; //set the message index in case we want to delete it later $ email -> index = $ i ; //get all the header info $ this -> parseHeaderInfo ( $ email , imap_headerinfo ( $ this -> inbox , $ i ) ) ; $ structure = \ imap_fetchstructure ( $ this -> inbox , $ i ) ; //the type of email format $ email -> subtype = \ strtolower ( $ structure -> subtype ) ; $ email -> structure = $ structure ; //if the email is divided into parts, html, plain, attachments, etc if ( isset ( $ structure -> parts ) ) { $ part_id = 1 ; foreach ( $ structure -> parts as $ part ) { //get type 0 = text, 1 = multipart, 2 = message, //3 = application, 4 = audio, 5= image, 6= video, 7 = other $ type = $ part -> type ; //multipart $ sub_id = 1 ; if ( $ type == 1 && isset ( $ part -> parts ) ) { foreach ( $ part -> parts as $ part ) { $ part -> part_id = $ part_id . '.' . $ sub_id ; $ this -> examinePart ( $ email , $ part ) ; $ sub_id ++ ; } } else { $ part -> part_id = $ part_id ; $ this -> examinePart ( $ email , $ part , $ part_id ) ; } $ part_id ++ ; } } else { //it is just a plain text email $ email -> body = \ imap_fetchbody ( $ this -> inbox , $ i , 1 ) ; $ email -> body_encoding = $ structure -> encoding ; } //if the body is base64 encoded, decode it if ( $ email -> body_encoding == 3 ) { $ email -> body = \ base64_decode ( $ email -> body ) ; } $ this -> log ( print_r ( $ email , 1 ) ) ; //store the email $ this -> emails [ ] = $ email ; } }
Fetches all the messages in an inbox and put them in the emails array

@return returns the array of all email objects found
Fetches all the messages in an inbox and put them in the emails array