fh = $fh; $this->initialized = false; $this->hasMoreMailData = true; $this->messagePositions = $messages; $this->currentMessagePosition = 0; $this->nextMail(); } /** * Returns true if all the data has been fetched from this set. * * @return bool */ public function isFinished() { return feof( $this->fh ) ? true : false; } /** * Returns one line of data from the current mail in the set * including the ending linebreak. * * Null is returned if there is no current mail in the set or * the end of the mail is reached. * * @return string */ public function getNextLine() { if ( $this->hasMoreMailData ) { $data = fgets( $this->fh ); if ( feof( $this->fh ) || substr( $data, 0, 5 ) === "From " ) { $this->hasMoreMailData = false; return null; } return $data; } return null; } /** * Moves the set to the next mail and returns true upon success. * * False is returned if there are no more mail in the set. * * @return bool */ public function nextMail() { // seek to next message if available if ( $this->currentMessagePosition > count( $this->messagePositions ) - 1 ) { $this->hasMoreMailData = false; return false; } fseek( $this->fh, $this->messagePositions[$this->currentMessagePosition] ); $this->currentMessagePosition++; $this->hasMoreMailData = true; return true; } } ?>