135 $this->connected =
false;
152 if (
$port ==
false) {
159 if (
$tval ==
false) {
165 $this->do_debug = $debug_level;
173 $result = $this->
Connect($this->host, $this->port, $this->tval);
176 $login_result = $this->
Login($this->username, $this->password);
202 if ($this->connected) {
211 set_error_handler(array(&$this,
'catchWarning'));
214 $this->pop_conn = fsockopen(
$host,
221 restore_error_handler();
224 if ($this->error && $this->do_debug >= 1) {
225 $this->displayErrors();
229 if ($this->pop_conn ==
false) {
231 $this->error = array(
232 'error' =>
"Failed to connect to server $host on port $port",
237 if ($this->do_debug >= 1) {
238 $this->displayErrors();
247 if (version_compare(phpversion(),
'5.0.0',
'ge')) {
248 stream_set_timeout($this->pop_conn,
$tval, 0);
251 if (substr(PHP_OS, 0, 3) !==
'WIN') {
252 socket_set_timeout($this->pop_conn,
$tval, 0);
257 $pop3_response = $this->getResponse();
260 if ($this->checkResponse($pop3_response)) {
262 $this->connected =
true;
276 if ($this->connected ==
false) {
277 $this->error =
'Not connected to POP3 server';
279 if ($this->do_debug >= 1) {
280 $this->displayErrors();
296 $this->sendString($pop_username);
297 $pop3_response = $this->getResponse();
299 if ($this->checkResponse($pop3_response)) {
301 $this->sendString($pop_password);
302 $pop3_response = $this->getResponse();
304 if ($this->checkResponse($pop3_response)) {
319 $this->sendString(
'QUIT');
321 fclose($this->pop_conn);
335 private function getResponse ($size = 128) {
336 $pop3_response = fgets($this->pop_conn, $size);
338 return $pop3_response;
347 private function sendString ($string) {
348 $bytes_sent = fwrite($this->pop_conn, $string, strlen($string));
359 private function checkResponse ($string) {
360 if (substr($string, 0, 3) !==
'+OK') {
361 $this->error = array(
362 'error' =>
"Server reported an error: $string",
367 if ($this->do_debug >= 1) {
368 $this->displayErrors();
382 private function displayErrors () {
385 foreach ($this->error as $single_error) {
386 print_r($single_error);
400 private function catchWarning ($errno, $errstr, $errfile, $errline) {
401 $this->error[] = array(
402 'error' =>
"Connecting to the POP3 server raised a PHP warning: ",