132 $this->connected =
false;
149 if (
$port ==
false) {
156 if (
$tval ==
false) {
162 $this->do_debug = $debug_level;
173 $login_result = $this->
Login($this->username, $this->password);
199 if ($this->connected) {
208 set_error_handler(array(&$this,
'catchWarning'));
211 $this->pop_conn = fsockopen(
$host,
218 restore_error_handler();
221 if ($this->error && $this->do_debug >= 1) {
222 $this->displayErrors();
226 if ($this->pop_conn ==
false) {
228 $this->error = array(
229 'error' =>
"Failed to connect to server $host on port $port",
234 if ($this->do_debug >= 1) {
235 $this->displayErrors();
244 if (version_compare(phpversion(),
'5.0.0',
'ge')) {
245 stream_set_timeout($this->pop_conn,
$tval, 0);
248 if (substr(PHP_OS, 0, 3) !==
'WIN') {
249 socket_set_timeout($this->pop_conn,
$tval, 0);
254 $pop3_response = $this->getResponse();
257 if ($this->checkResponse($pop3_response)) {
259 $this->connected =
true;
273 if ($this->connected ==
false) {
274 $this->error =
'Not connected to POP3 server';
276 if ($this->do_debug >= 1) {
277 $this->displayErrors();
293 $this->sendString($pop_username);
294 $pop3_response = $this->getResponse();
296 if ($this->checkResponse($pop3_response)) {
298 $this->sendString($pop_password);
299 $pop3_response = $this->getResponse();
301 if ($this->checkResponse($pop3_response)) {
316 $this->sendString(
'QUIT');
318 fclose($this->pop_conn);
332 private function getResponse ($size = 128) {
333 $pop3_response = fgets($this->pop_conn, $size);
335 return $pop3_response;
344 private function sendString ($string) {
345 $bytes_sent = fwrite($this->pop_conn, $string, strlen($string));
356 private function checkResponse ($string) {
357 if (substr($string, 0, 3) !==
'+OK') {
358 $this->error = array(
359 'error' =>
"Server reported an error: $string",
364 if ($this->do_debug >= 1) {
365 $this->displayErrors();
379 private function displayErrors () {
382 foreach ($this->error as $single_error) {
383 print_r($single_error);
397 private function catchWarning ($errno, $errstr, $errfile, $errline) {
398 $this->error[] = array(
399 'error' =>
"Connecting to the POP3 server raised a PHP warning: ",