-<?php\r
-/*~ class.pop3.php\r
-.---------------------------------------------------------------------------.\r
-| Software: PHPMailer - PHP email class |\r
-| Version: 2.0.0 rc2 |\r
-| Contact: via sourceforge.net support pages (also www.codeworxtech.com) |\r
-| Info: http://phpmailer.sourceforge.net |\r
-| Support: http://sourceforge.net/projects/phpmailer/ |\r
-| ------------------------------------------------------------------------- |\r
-| Author: Andy Prevost (project admininistrator) |\r
-| Author: Brent R. Matzelle (original founder) |\r
-| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |\r
-| Copyright (c) 2001-2003, Brent R. Matzelle |\r
-| ------------------------------------------------------------------------- |\r
-| License: Distributed under the Lesser General Public License (LGPL) |\r
-| http://www.gnu.org/copyleft/lesser.html |\r
-| This program is distributed in the hope that it will be useful - WITHOUT |\r
-| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |\r
-| FITNESS FOR A PARTICULAR PURPOSE. |\r
-| ------------------------------------------------------------------------- |\r
-| We offer a number of paid services (www.codeworxtech.com): |\r
-| - Web Hosting on highly optimized fast and secure servers |\r
-| - Technology Consulting |\r
-| - Oursourcing (highly qualified programmers and graphic designers) |\r
-'---------------------------------------------------------------------------'\r
-\r
-/**\r
- * POP Before SMTP Authentication Class\r
- * Version 1.0\r
- *\r
- * Author: Richard Davey (rich@corephp.co.uk)\r
- * License: LGPL, see PHPMailer License\r
- *\r
- * Specifically for PHPMailer to allow POP before SMTP authentication.\r
- * Does not yet work with APOP - if you have an APOP account, contact me\r
- * and we can test changes to this script.\r
- *\r
- * This class is based on the structure of the SMTP class by Chris Ryan\r
- *\r
- * This class is rfc 1939 compliant and implements all the commands\r
- * required for POP3 connection, authentication and disconnection.\r
- *\r
- * @package PHPMailer\r
- * @author Richard Davey\r
- */\r
-\r
-class POP3\r
-{\r
- /**\r
- * Default POP3 port\r
- * @var int\r
- */\r
- var $POP3_PORT = 110;\r
-\r
- /**\r
- * Default Timeout\r
- * @var int\r
- */\r
- var $POP3_TIMEOUT = 30;\r
-\r
- /**\r
- * POP3 Carriage Return + Line Feed\r
- * @var string\r
- */\r
- var $CRLF = "\r\n";\r
-\r
- /**\r
- * Displaying Debug warnings? (0 = now, 1+ = yes)\r
- * @var int\r
- */\r
- var $do_debug = 2;\r
-\r
- /**\r
- * POP3 Mail Server\r
- * @var string\r
- */\r
- var $host;\r
-\r
- /**\r
- * POP3 Port\r
- * @var int\r
- */\r
- var $port;\r
-\r
- /**\r
- * POP3 Timeout Value\r
- * @var int\r
- */\r
- var $tval;\r
-\r
- /**\r
- * POP3 Username\r
- * @var string\r
- */\r
- var $username;\r
-\r
- /**\r
- * POP3 Password\r
- * @var string\r
- */\r
- var $password;\r
-\r
- /**#@+\r
- * @access private\r
- */\r
- var $pop_conn;\r
- var $connected;\r
- var $error; // Error log array\r
- /**#@-*/\r
-\r
- /**\r
- * Constructor, sets the initial values\r
- *\r
- * @return POP3\r
- */\r
- function POP3 ()\r
- {\r
- $this->pop_conn = 0;\r
- $this->connected = false;\r
- $this->error = null;\r
- }\r
-\r
- /**\r
- * Combination of public events - connect, login, disconnect\r
- *\r
- * @param string $host\r
- * @param integer $port\r
- * @param integer $tval\r
- * @param string $username\r
- * @param string $password\r
- */\r
- function Authorise ($host, $port = false, $tval = false, $username, $password, $debug_level = 0)\r
- {\r
- $this->host = $host;\r
-\r
- // If no port value is passed, retrieve it\r
- if ($port == false)\r
- {\r
- $this->port = $this->POP3_PORT;\r
- }\r
- else\r
- {\r
- $this->port = $port;\r
- }\r
-\r
- // If no port value is passed, retrieve it\r
- if ($tval == false)\r
- {\r
- $this->tval = $this->POP3_TIMEOUT;\r
- }\r
- else\r
- {\r
- $this->tval = $tval;\r
- }\r
-\r
- $this->do_debug = $debug_level;\r
- $this->username = $username;\r
- $this->password = $password;\r
-\r
- // Refresh the error log\r
- $this->error = null;\r
-\r
- // Connect\r
- $result = $this->Connect($this->host, $this->port, $this->tval);\r
-\r
- if ($result)\r
- {\r
- $login_result = $this->Login($this->username, $this->password);\r
-\r
- if ($login_result)\r
- {\r
- $this->Disconnect();\r
-\r
- return true;\r
- }\r
-\r
- }\r
-\r
- // We need to disconnect regardless if the login succeeded\r
- $this->Disconnect();\r
-\r
- return false;\r
- }\r
-\r
- /**\r
- * Connect to the POP3 server\r
- *\r
- * @param string $host\r
- * @param integer $port\r
- * @param integer $tval\r
- * @return boolean\r
- */\r
- function Connect ($host, $port = false, $tval = 30)\r
- {\r
- // Are we already connected?\r
- if ($this->connected)\r
- {\r
- return true;\r
- }\r
-\r
- /*\r
- On Windows this will raise a PHP Warning error if the hostname doesn't exist.\r
- Rather than supress it with @fsockopen, let's capture it cleanly instead\r
- */\r
-\r
- set_error_handler(array(&$this, 'catchWarning'));\r
-\r
- // Connect to the POP3 server\r
- $this->pop_conn = fsockopen($host, // POP3 Host\r
- $port, // Port #\r
- $errno, // Error Number\r
- $errstr, // Error Message\r
- $tval); // Timeout (seconds)\r
-\r
- // Restore the error handler\r
- restore_error_handler();\r
-\r
- // Does the Error Log now contain anything?\r
- if ($this->error && $this->do_debug >= 1)\r
- {\r
- $this->displayErrors();\r
- }\r
-\r
- // Did we connect?\r
- if ($this->pop_conn == false)\r
- {\r
- // It would appear not...\r
- $this->error = array(\r
- 'error' => "Failed to connect to server $host on port $port",\r
- 'errno' => $errno,\r
- 'errstr' => $errstr\r
- );\r
-\r
- if ($this->do_debug >= 1)\r
- {\r
- $this->displayErrors();\r
- }\r
-\r
- return false;\r
- }\r
-\r
- // Increase the stream time-out\r
-\r
- // Check for PHP 4.3.0 or later\r
- if (version_compare(phpversion(), '4.3.0', 'ge'))\r
- {\r
- stream_set_timeout($this->pop_conn, $tval, 0);\r
- }\r
- else\r
- {\r
- // Does not work on Windows\r
- if (substr(PHP_OS, 0, 3) !== 'WIN')\r
- {\r
- socket_set_timeout($this->pop_conn, $tval, 0);\r
- }\r
- }\r
-\r
- // Get the POP3 server response\r
- $pop3_response = $this->getResponse();\r
-\r
- // Check for the +OK\r
- if ($this->checkResponse($pop3_response))\r
- {\r
- // The connection is established and the POP3 server is talking\r
- $this->connected = true;\r
- return true;\r
- }\r
-\r
- }\r
-\r
- /**\r
- * Login to the POP3 server (does not support APOP yet)\r
- *\r
- * @param string $username\r
- * @param string $password\r
- * @return boolean\r
- */\r
- function Login ($username = '', $password = '')\r
- {\r
- if ($this->connected == false)\r
- {\r
- $this->error = 'Not connected to POP3 server';\r
-\r
- if ($this->do_debug >= 1)\r
- {\r
- $this->displayErrors();\r
- }\r
- }\r
-\r
- if (empty($username))\r
- {\r
- $username = $this->username;\r
- }\r
-\r
- if (empty($password))\r
- {\r
- $password = $this->password;\r
- }\r
-\r
- $pop_username = "USER $username" . $this->CRLF;\r
- $pop_password = "PASS $password" . $this->CRLF;\r
-\r
- // Send the Username\r
- $this->sendString($pop_username);\r
- $pop3_response = $this->getResponse();\r
-\r
- if ($this->checkResponse($pop3_response))\r
- {\r
- // Send the Password\r
- $this->sendString($pop_password);\r
- $pop3_response = $this->getResponse();\r
-\r
- if ($this->checkResponse($pop3_response))\r
- {\r
- return true;\r
- }\r
- else\r
- {\r
- return false;\r
- }\r
- }\r
- else\r
- {\r
- return false;\r
- }\r
- }\r
-\r
- /**\r
- * Disconnect from the POP3 server\r
- */\r
- function Disconnect ()\r
- {\r
- $this->sendString('QUIT');\r
-\r
- fclose($this->pop_conn);\r
- }\r
-\r
- /*\r
- ---------------\r
- Private Methods\r
- ---------------\r
- */\r
-\r
- /**\r
- * Get the socket response back.\r
- * $size is the maximum number of bytes to retrieve\r
- *\r
- * @param integer $size\r
- * @return string\r
- */\r
- function getResponse ($size = 128)\r
- {\r
- $pop3_response = fgets($this->pop_conn, $size);\r
-\r
- return $pop3_response;\r
- }\r
-\r
- /**\r
- * Send a string down the open socket connection to the POP3 server\r
- *\r
- * @param string $string\r
- * @return integer\r
- */\r
- function sendString ($string)\r
- {\r
- $bytes_sent = fwrite($this->pop_conn, $string, strlen($string));\r
-\r
- return $bytes_sent;\r
-\r
- }\r
-\r
- /**\r
- * Checks the POP3 server response for +OK or -ERR\r
- *\r
- * @param string $string\r
- * @return boolean\r
- */\r
- function checkResponse ($string)\r
- {\r
- if (substr($string, 0, 3) !== '+OK')\r
- {\r
- $this->error = array(\r
- 'error' => "Server reported an error: $string",\r
- 'errno' => 0,\r
- 'errstr' => ''\r
- );\r
-\r
- if ($this->do_debug >= 1)\r
- {\r
- $this->displayErrors();\r
- }\r
-\r
- return false;\r
- }\r
- else\r
- {\r
- return true;\r
- }\r
-\r
- }\r
-\r
- /**\r
- * If debug is enabled, display the error message array\r
- *\r
- */\r
- function displayErrors ()\r
- {\r
- echo '<pre>';\r
-\r
- foreach ($this->error as $single_error)\r
- {\r
- print_r($single_error);\r
- }\r
-\r
- echo '</pre>';\r
- }\r
-\r
- /**\r
- * Takes over from PHP for the socket warning handler\r
- *\r
- * @param integer $errno\r
- * @param string $errstr\r
- * @param string $errfile\r
- * @param integer $errline\r
- */\r
- function catchWarning ($errno, $errstr, $errfile, $errline)\r
- {\r
- $this->error[] = array(\r
- 'error' => "Connecting to the POP3 server raised a PHP warning: ",\r
- 'errno' => $errno,\r
- 'errstr' => $errstr\r
- );\r
- }\r
-\r
- // End of class\r
-}\r
-?>\r
+<?php
+/*~ class.pop3.php
+.---------------------------------------------------------------------------.
+| Software: PHPMailer - PHP email class |
+| Version: 2.0.0 rc2 |
+| Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
+| Info: http://phpmailer.sourceforge.net |
+| Support: http://sourceforge.net/projects/phpmailer/ |
+| ------------------------------------------------------------------------- |
+| Author: Andy Prevost (project admininistrator) |
+| Author: Brent R. Matzelle (original founder) |
+| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |
+| Copyright (c) 2001-2003, Brent R. Matzelle |
+| ------------------------------------------------------------------------- |
+| License: Distributed under the Lesser General Public License (LGPL) |
+| http://www.gnu.org/copyleft/lesser.html |
+| This program is distributed in the hope that it will be useful - WITHOUT |
+| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
+| FITNESS FOR A PARTICULAR PURPOSE. |
+| ------------------------------------------------------------------------- |
+| We offer a number of paid services (www.codeworxtech.com): |
+| - Web Hosting on highly optimized fast and secure servers |
+| - Technology Consulting |
+| - Oursourcing (highly qualified programmers and graphic designers) |
+'---------------------------------------------------------------------------'
+
+/**
+ * POP Before SMTP Authentication Class
+ * Version 1.0
+ *
+ * Author: Richard Davey (rich@corephp.co.uk)
+ * License: LGPL, see PHPMailer License
+ *
+ * Specifically for PHPMailer to allow POP before SMTP authentication.
+ * Does not yet work with APOP - if you have an APOP account, contact me
+ * and we can test changes to this script.
+ *
+ * This class is based on the structure of the SMTP class by Chris Ryan
+ *
+ * This class is rfc 1939 compliant and implements all the commands
+ * required for POP3 connection, authentication and disconnection.
+ *
+ * @package PHPMailer
+ * @author Richard Davey
+ */
+
+class POP3
+{
+ /**
+ * Default POP3 port
+ * @var int
+ */
+ var $POP3_PORT = 110;
+
+ /**
+ * Default Timeout
+ * @var int
+ */
+ var $POP3_TIMEOUT = 30;
+
+ /**
+ * POP3 Carriage Return + Line Feed
+ * @var string
+ */
+ var $CRLF = "\r\n";
+
+ /**
+ * Displaying Debug warnings? (0 = now, 1+ = yes)
+ * @var int
+ */
+ var $do_debug = 2;
+
+ /**
+ * POP3 Mail Server
+ * @var string
+ */
+ var $host;
+
+ /**
+ * POP3 Port
+ * @var int
+ */
+ var $port;
+
+ /**
+ * POP3 Timeout Value
+ * @var int
+ */
+ var $tval;
+
+ /**
+ * POP3 Username
+ * @var string
+ */
+ var $username;
+
+ /**
+ * POP3 Password
+ * @var string
+ */
+ var $password;
+
+ /**#@+
+ * @access private
+ */
+ var $pop_conn;
+ var $connected;
+ var $error; // Error log array
+ /**#@-*/
+
+ /**
+ * Constructor, sets the initial values
+ *
+ * @return POP3
+ */
+ function POP3 ()
+ {
+ $this->pop_conn = 0;
+ $this->connected = false;
+ $this->error = null;
+ }
+
+ /**
+ * Combination of public events - connect, login, disconnect
+ *
+ * @param string $host
+ * @param integer $port
+ * @param integer $tval
+ * @param string $username
+ * @param string $password
+ */
+ function Authorise ($host, $port = false, $tval = false, $username, $password, $debug_level = 0)
+ {
+ $this->host = $host;
+
+ // If no port value is passed, retrieve it
+ if ($port == false)
+ {
+ $this->port = $this->POP3_PORT;
+ }
+ else
+ {
+ $this->port = $port;
+ }
+
+ // If no port value is passed, retrieve it
+ if ($tval == false)
+ {
+ $this->tval = $this->POP3_TIMEOUT;
+ }
+ else
+ {
+ $this->tval = $tval;
+ }
+
+ $this->do_debug = $debug_level;
+ $this->username = $username;
+ $this->password = $password;
+
+ // Refresh the error log
+ $this->error = null;
+
+ // Connect
+ $result = $this->Connect($this->host, $this->port, $this->tval);
+
+ if ($result)
+ {
+ $login_result = $this->Login($this->username, $this->password);
+
+ if ($login_result)
+ {
+ $this->Disconnect();
+
+ return true;
+ }
+
+ }
+
+ // We need to disconnect regardless if the login succeeded
+ $this->Disconnect();
+
+ return false;
+ }
+
+ /**
+ * Connect to the POP3 server
+ *
+ * @param string $host
+ * @param integer $port
+ * @param integer $tval
+ * @return boolean
+ */
+ function Connect ($host, $port = false, $tval = 30)
+ {
+ // Are we already connected?
+ if ($this->connected)
+ {
+ return true;
+ }
+
+ /*
+ On Windows this will raise a PHP Warning error if the hostname doesn't exist.
+ Rather than supress it with @fsockopen, let's capture it cleanly instead
+ */
+
+ set_error_handler(array(&$this, 'catchWarning'));
+
+ // Connect to the POP3 server
+ $this->pop_conn = fsockopen($host, // POP3 Host
+ $port, // Port #
+ $errno, // Error Number
+ $errstr, // Error Message
+ $tval); // Timeout (seconds)
+
+ // Restore the error handler
+ restore_error_handler();
+
+ // Does the Error Log now contain anything?
+ if ($this->error && $this->do_debug >= 1)
+ {
+ $this->displayErrors();
+ }
+
+ // Did we connect?
+ if ($this->pop_conn == false)
+ {
+ // It would appear not...
+ $this->error = array(
+ 'error' => "Failed to connect to server $host on port $port",
+ 'errno' => $errno,
+ 'errstr' => $errstr
+ );
+
+ if ($this->do_debug >= 1)
+ {
+ $this->displayErrors();
+ }
+
+ return false;
+ }
+
+ // Increase the stream time-out
+
+ // Check for PHP 4.3.0 or later
+ if (version_compare(phpversion(), '4.3.0', 'ge'))
+ {
+ stream_set_timeout($this->pop_conn, $tval, 0);
+ }
+ else
+ {
+ // Does not work on Windows
+ if (substr(PHP_OS, 0, 3) !== 'WIN')
+ {
+ socket_set_timeout($this->pop_conn, $tval, 0);
+ }
+ }
+
+ // Get the POP3 server response
+ $pop3_response = $this->getResponse();
+
+ // Check for the +OK
+ if ($this->checkResponse($pop3_response))
+ {
+ // The connection is established and the POP3 server is talking
+ $this->connected = true;
+ return true;
+ }
+
+ }
+
+ /**
+ * Login to the POP3 server (does not support APOP yet)
+ *
+ * @param string $username
+ * @param string $password
+ * @return boolean
+ */
+ function Login ($username = '', $password = '')
+ {
+ if ($this->connected == false)
+ {
+ $this->error = 'Not connected to POP3 server';
+
+ if ($this->do_debug >= 1)
+ {
+ $this->displayErrors();
+ }
+ }
+
+ if (empty($username))
+ {
+ $username = $this->username;
+ }
+
+ if (empty($password))
+ {
+ $password = $this->password;
+ }
+
+ $pop_username = "USER $username" . $this->CRLF;
+ $pop_password = "PASS $password" . $this->CRLF;
+
+ // Send the Username
+ $this->sendString($pop_username);
+ $pop3_response = $this->getResponse();
+
+ if ($this->checkResponse($pop3_response))
+ {
+ // Send the Password
+ $this->sendString($pop_password);
+ $pop3_response = $this->getResponse();
+
+ if ($this->checkResponse($pop3_response))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Disconnect from the POP3 server
+ */
+ function Disconnect ()
+ {
+ $this->sendString('QUIT');
+
+ fclose($this->pop_conn);
+ }
+
+ /*
+ ---------------
+ Private Methods
+ ---------------
+ */
+
+ /**
+ * Get the socket response back.
+ * $size is the maximum number of bytes to retrieve
+ *
+ * @param integer $size
+ * @return string
+ */
+ function getResponse ($size = 128)
+ {
+ $pop3_response = fgets($this->pop_conn, $size);
+
+ return $pop3_response;
+ }
+
+ /**
+ * Send a string down the open socket connection to the POP3 server
+ *
+ * @param string $string
+ * @return integer
+ */
+ function sendString ($string)
+ {
+ $bytes_sent = fwrite($this->pop_conn, $string, strlen($string));
+
+ return $bytes_sent;
+
+ }
+
+ /**
+ * Checks the POP3 server response for +OK or -ERR
+ *
+ * @param string $string
+ * @return boolean
+ */
+ function checkResponse ($string)
+ {
+ if (substr($string, 0, 3) !== '+OK')
+ {
+ $this->error = array(
+ 'error' => "Server reported an error: $string",
+ 'errno' => 0,
+ 'errstr' => ''
+ );
+
+ if ($this->do_debug >= 1)
+ {
+ $this->displayErrors();
+ }
+
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+
+ }
+
+ /**
+ * If debug is enabled, display the error message array
+ *
+ */
+ function displayErrors ()
+ {
+ echo '<pre>';
+
+ foreach ($this->error as $single_error)
+ {
+ print_r($single_error);
+ }
+
+ echo '</pre>';
+ }
+
+ /**
+ * Takes over from PHP for the socket warning handler
+ *
+ * @param integer $errno
+ * @param string $errstr
+ * @param string $errfile
+ * @param integer $errline
+ */
+ function catchWarning ($errno, $errstr, $errfile, $errline)
+ {
+ $this->error[] = array(
+ 'error' => "Connecting to the POP3 server raised a PHP warning: ",
+ 'errno' => $errno,
+ 'errstr' => $errstr
+ );
+ }
+
+ // End of class
+}
+?>