connection = $connection; $this->messages = $messages; $this->deleteFromServer = $deleteFromServer; $this->nextMail(); } /** * Returns true if all the data has been fetched from this set. * * @return bool */ public function isFinished() { return $this->currentMessage === false ? true : false; } /** * Returns one line of data from the current mail in the set. * * 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 = $this->connection->getLine(); if ( rtrim( $data ) === "." ) { $this->hasMoreMailData = false; // remove the mail if required by the user. if ( $this->deleteFromServer == true ) { $this->connection->sendData( "DELE {$this->currentMessage}" ); $response = $this->connection->getLine(); // ignore response } 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. * * @throws ezcMailTransportException if the server sent a negative reply when requesting a mail. * @return bool */ public function nextMail() { if ( $this->currentMessage === null ) { $this->currentMessage = reset( $this->messages ); } else { $this->currentMessage = next( $this->messages ); } if ( is_integer( $this->currentMessage ) ) { $this->connection->sendData( "RETR {$this->currentMessage}" ); $response = $this->connection->getLine(); if ( strpos( $response, "+OK" ) === 0 ) { $this->hasMoreMailData = true; return true; } else { throw new ezcMailTransportException( "The POP3 server sent a negative reply when requesting mail." ); } } return false; } } ?>