Rolling back PHPMailer from version 5.2.14 to 5.2.2. The latest version had a problem with smtp authentication set to false it still tried to authenticate.

This commit is contained in:
markjcrane 2016-03-15 02:58:23 -06:00
parent d8aeecad35
commit 0deda1db2e
3 changed files with 3995 additions and 5238 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,251 +1,272 @@
<?php <?php
/*~ class.pop3.php
.---------------------------------------------------------------------------.
| Software: PHPMailer - PHP email class |
| Version: 5.2.2 |
| Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ |
| ------------------------------------------------------------------------- |
| Admin: Jim Jagielski (project admininistrator) |
| Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
| : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
| : Jim Jagielski (jimjag) jimjag@gmail.com |
| Founder: Brent R. Matzelle (original founder) |
| Copyright (c) 2010-2012, Jim Jagielski. All Rights Reserved. |
| Copyright (c) 2004-2009, 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. |
'---------------------------------------------------------------------------'
*/
/** /**
* PHPMailer POP-Before-SMTP Authentication Class. * PHPMailer - PHP POP Before SMTP Authentication Class
* PHP Version 5 * NOTE: Designed for use with PHP version 5 and up
* @package PHPMailer * @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/ * @author Andy Prevost
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk> * @author Marcus Bointon
* @author Jim Jagielski (jimjag) <jimjag@gmail.com> * @author Jim Jagielski
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2014 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski * @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost * @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
* @note 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.
*/ */
/** /**
* PHPMailer POP-Before-SMTP Authentication Class. * PHP POP-Before-SMTP Authentication Class
* Specifically for PHPMailer to use for RFC1939 POP-before-SMTP authentication. *
* Does not support APOP. * Version 5.2.2
*
* @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 Jim Jagielski
* and we can test changes to this script.
*
* This class is based on the structure of the SMTP class originally authored by Chris Ryan
*
* This class is rfc 1939 compliant and implements all the commands
* required for POP3 connection, authentication and disconnection.
*
* @package PHPMailer * @package PHPMailer
* @author Richard Davey (original author) <rich@corephp.co.uk> * @author Richard Davey (orig) <rich@corephp.co.uk>
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk> * @author Andy Prevost
* @author Jim Jagielski (jimjag) <jimjag@gmail.com> * @author Jim Jagielski
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
*/ */
class POP3
{
/**
* The POP3 PHPMailer Version number.
* @var string
* @access public
*/
public $Version = '5.2.14';
class POP3 {
/** /**
* Default POP3 port number. * Default POP3 port
* @var integer * @var int
* @access public
*/ */
public $POP3_PORT = 110; public $POP3_PORT = 110;
/** /**
* Default timeout in seconds. * Default Timeout
* @var integer * @var int
* @access public
*/ */
public $POP3_TIMEOUT = 30; public $POP3_TIMEOUT = 30;
/** /**
* POP3 Carriage Return + Line Feed. * POP3 Carriage Return + Line Feed
* @var string * @var string
* @access public
* @deprecated Use the constant instead
*/ */
public $CRLF = "\r\n"; public $CRLF = "\r\n";
/** /**
* Debug display level. * Displaying Debug warnings? (0 = now, 1+ = yes)
* Options: 0 = no, 1+ = yes * @var int
* @var integer
* @access public
*/ */
public $do_debug = 0; public $do_debug = 2;
/** /**
* POP3 mail server hostname. * POP3 Mail Server
* @var string * @var string
* @access public
*/ */
public $host; public $host;
/** /**
* POP3 port number. * POP3 Port
* @var integer * @var int
* @access public
*/ */
public $port; public $port;
/** /**
* POP3 Timeout Value in seconds. * POP3 Timeout Value
* @var integer * @var int
* @access public
*/ */
public $tval; public $tval;
/** /**
* POP3 username * POP3 Username
* @var string * @var string
* @access public
*/ */
public $username; public $username;
/** /**
* POP3 password. * POP3 Password
* @var string * @var string
* @access public
*/ */
public $password; public $password;
/** /**
* Resource handle for the POP3 connection socket. * Sets the POP3 PHPMailer Version number
* @var resource * @var string
* @access protected
*/ */
protected $pop_conn; public $Version = '5.2.2';
/////////////////////////////////////////////////
// PROPERTIES, PRIVATE AND PROTECTED
/////////////////////////////////////////////////
/** /**
* Are we connected? * @var resource Resource handle for the POP connection socket
* @var boolean
* @access protected
*/ */
protected $connected = false; private $pop_conn;
/**
* @var boolean Are we connected?
*/
private $connected;
/**
* @var array Error container
*/
private $error; // Error log array
/** /**
* Error container. * Constructor, sets the initial values
* @var array * @access public
* @access protected * @return POP3
*/ */
protected $errors = array(); public function __construct() {
$this->pop_conn = 0;
/** $this->connected = false;
* Line break constant $this->error = null;
*/
const CRLF = "\r\n";
/**
* Simple static wrapper for all-in-one POP before SMTP
* @param $host
* @param integer|boolean $port The port number to connect to
* @param integer|boolean $timeout The timeout value
* @param string $username
* @param string $password
* @param integer $debug_level
* @return boolean
*/
public static function popBeforeSmtp(
$host,
$port = false,
$timeout = false,
$username = '',
$password = '',
$debug_level = 0
) {
$pop = new POP3;
return $pop->authorise($host, $port, $timeout, $username, $password, $debug_level);
} }
/** /**
* Authenticate with a POP3 server. * Combination of public events - connect, login, disconnect
* A connect, login, disconnect sequence
* appropriate for POP-before SMTP authorisation.
* @access public * @access public
* @param string $host The hostname to connect to * @param string $host
* @param integer|boolean $port The port number to connect to * @param bool|int $port
* @param integer|boolean $timeout The timeout value * @param bool|int $tval
* @param string $username * @param string $username
* @param string $password * @param string $password
* @param integer $debug_level * @param int $debug_level
* @return boolean * @return bool
*/ */
public function authorise($host, $port = false, $timeout = false, $username = '', $password = '', $debug_level = 0) public function Authorise ($host, $port = false, $tval = false, $username, $password, $debug_level = 0) {
{
$this->host = $host; $this->host = $host;
// If no port value provided, use default
if (false === $port) { // If no port value is passed, retrieve it
if ($port == false) {
$this->port = $this->POP3_PORT; $this->port = $this->POP3_PORT;
} else { } else {
$this->port = (integer)$port; $this->port = $port;
} }
// If no timeout value provided, use default
if (false === $timeout) { // If no port value is passed, retrieve it
if ($tval == false) {
$this->tval = $this->POP3_TIMEOUT; $this->tval = $this->POP3_TIMEOUT;
} else { } else {
$this->tval = (integer)$timeout; $this->tval = $tval;
} }
$this->do_debug = $debug_level; $this->do_debug = $debug_level;
$this->username = $username; $this->username = $username;
$this->password = $password; $this->password = $password;
// Reset the error log
$this->errors = array(); // Refresh the error log
// connect $this->error = null;
$result = $this->connect($this->host, $this->port, $this->tval);
// Connect
$result = $this->Connect($this->host, $this->port, $this->tval);
if ($result) { if ($result) {
$login_result = $this->login($this->username, $this->password); $login_result = $this->Login($this->username, $this->password);
if ($login_result) { if ($login_result) {
$this->disconnect(); $this->Disconnect();
return true; return true;
} }
} }
// We need to disconnect regardless of whether the login succeeded
$this->disconnect(); // We need to disconnect regardless if the login succeeded
$this->Disconnect();
return false; return false;
} }
/** /**
* Connect to a POP3 server. * Connect to the POP3 server
* @access public * @access public
* @param string $host * @param string $host
* @param integer|boolean $port * @param bool|int $port
* @param integer $tval * @param integer $tval
* @return boolean * @return boolean
*/ */
public function connect($host, $port = false, $tval = 30) public function Connect ($host, $port = false, $tval = 30) {
{
// Are we already connected? // Are we already connected?
if ($this->connected) { if ($this->connected) {
return true; return true;
} }
//On Windows this will raise a PHP Warning error if the hostname doesn't exist. /*
//Rather than suppress it with @fsockopen, capture it cleanly instead On Windows this will raise a PHP Warning error if the hostname doesn't exist.
set_error_handler(array($this, 'catchWarning')); Rather than supress it with @fsockopen, let's capture it cleanly instead
*/
if (false === $port) { set_error_handler(array(&$this, 'catchWarning'));
$port = $this->POP3_PORT;
}
// connect to the POP3 server // Connect to the POP3 server
$this->pop_conn = fsockopen( $this->pop_conn = fsockopen($host, // POP3 Host
$host, // POP3 Host
$port, // Port # $port, // Port #
$errno, // Error Number $errno, // Error Number
$errstr, // Error Message $errstr, // Error Message
$tval $tval); // Timeout (seconds)
); // Timeout (seconds)
// Restore the error handler // Restore the error handler
restore_error_handler(); restore_error_handler();
// Does the Error Log now contain anything?
if ($this->error && $this->do_debug >= 1) {
$this->displayErrors();
}
// Did we connect? // Did we connect?
if (false === $this->pop_conn) { if ($this->pop_conn == false) {
// It would appear not... // It would appear not...
$this->setError(array( $this->error = array(
'error' => "Failed to connect to server $host on port $port", 'error' => "Failed to connect to server $host on port $port",
'errno' => $errno, 'errno' => $errno,
'errstr' => $errstr 'errstr' => $errstr
)); );
if ($this->do_debug >= 1) {
$this->displayErrors();
}
return false; return false;
} }
// Increase the stream time-out // Increase the stream time-out
// Check for PHP 4.3.0 or later
if (version_compare(phpversion(), '5.0.0', 'ge')) {
stream_set_timeout($this->pop_conn, $tval, 0); 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 // Get the POP3 server response
$pop3_response = $this->getResponse(); $pop3_response = $this->getResponse();
// Check for the +OK // Check for the +OK
if ($this->checkResponse($pop3_response)) { if ($this->checkResponse($pop3_response)) {
// The connection is established and the POP3 server is talking // The connection is established and the POP3 server is talking
@ -256,32 +277,41 @@ class POP3
} }
/** /**
* Log in to the POP3 server. * Login to the POP3 server (does not support APOP yet)
* Does not support APOP (RFC 2828, 4949).
* @access public * @access public
* @param string $username * @param string $username
* @param string $password * @param string $password
* @return boolean * @return boolean
*/ */
public function login($username = '', $password = '') public function Login ($username = '', $password = '') {
{ if ($this->connected == false) {
if (!$this->connected) { $this->error = 'Not connected to POP3 server';
$this->setError('Not connected to POP3 server');
if ($this->do_debug >= 1) {
$this->displayErrors();
} }
}
if (empty($username)) { if (empty($username)) {
$username = $this->username; $username = $this->username;
} }
if (empty($password)) { if (empty($password)) {
$password = $this->password; $password = $this->password;
} }
$pop_username = "USER $username" . $this->CRLF;
$pop_password = "PASS $password" . $this->CRLF;
// Send the Username // Send the Username
$this->sendString("USER $username" . self::CRLF); $this->sendString($pop_username);
$pop3_response = $this->getResponse(); $pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) { if ($this->checkResponse($pop3_response)) {
// Send the Password // Send the Password
$this->sendString("PASS $password" . self::CRLF); $this->sendString($pop_password);
$pop3_response = $this->getResponse(); $pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) { if ($this->checkResponse($pop3_response)) {
return true; return true;
} }
@ -290,118 +320,99 @@ class POP3
} }
/** /**
* Disconnect from the POP3 server. * Disconnect from the POP3 server
* @access public * @access public
*/ */
public function disconnect() public function Disconnect () {
{
$this->sendString('QUIT'); $this->sendString('QUIT');
//The QUIT command may cause the daemon to exit, which will kill our connection
//So ignore errors here fclose($this->pop_conn);
try {
@fclose($this->pop_conn);
} catch (Exception $e) {
//Do nothing
};
} }
/////////////////////////////////////////////////
// Private Methods
/////////////////////////////////////////////////
/** /**
* Get a response from the POP3 server. * Get the socket response back.
* $size is the maximum number of bytes to retrieve * $size is the maximum number of bytes to retrieve
* @access private
* @param integer $size * @param integer $size
* @return string * @return string
* @access protected
*/ */
protected function getResponse($size = 128) private function getResponse ($size = 128) {
{ $pop3_response = fgets($this->pop_conn, $size);
$response = fgets($this->pop_conn, $size);
if ($this->do_debug >= 1) { return $pop3_response;
echo "Server -> Client: $response";
}
return $response;
} }
/** /**
* Send raw data to the POP3 server. * Send a string down the open socket connection to the POP3 server
* @access private
* @param string $string * @param string $string
* @return integer * @return integer
* @access protected
*/ */
protected function sendString($string) private function sendString ($string) {
{ $bytes_sent = fwrite($this->pop_conn, $string, strlen($string));
if ($this->pop_conn) {
if ($this->do_debug >= 2) { //Show client messages when debug >= 2 return $bytes_sent;
echo "Client -> Server: $string";
}
return fwrite($this->pop_conn, $string, strlen($string));
}
return 0;
} }
/** /**
* Checks the POP3 server response. * Checks the POP3 server response for +OK or -ERR
* Looks for for +OK or -ERR. * @access private
* @param string $string * @param string $string
* @return boolean * @return boolean
* @access protected
*/ */
protected function checkResponse($string) private function checkResponse ($string) {
{
if (substr($string, 0, 3) !== '+OK') { if (substr($string, 0, 3) !== '+OK') {
$this->setError(array( $this->error = array(
'error' => "Server reported an error: $string", 'error' => "Server reported an error: $string",
'errno' => 0, 'errno' => 0,
'errstr' => '' 'errstr' => ''
)); );
if ($this->do_debug >= 1) {
$this->displayErrors();
}
return false; return false;
} else { } else {
return true; return true;
} }
} }
/** /**
* Add an error to the internal error store. * If debug is enabled, display the error message array
* Also display debug output if it's enabled. * @access private
* @param $error
* @access protected
*/ */
protected function setError($error) private function displayErrors () {
{
$this->errors[] = $error;
if ($this->do_debug >= 1) {
echo '<pre>'; echo '<pre>';
foreach ($this->errors as $error) {
print_r($error); foreach ($this->error as $single_error) {
print_r($single_error);
} }
echo '</pre>'; echo '</pre>';
} }
}
/** /**
* Get an array of error messages, if any. * Takes over from PHP for the socket warning handler
* @return array * @access private
*/
public function getErrors()
{
return $this->errors;
}
/**
* POP3 connection error handler.
* @param integer $errno * @param integer $errno
* @param string $errstr * @param string $errstr
* @param string $errfile * @param string $errfile
* @param integer $errline * @param integer $errline
* @access protected
*/ */
protected function catchWarning($errno, $errstr, $errfile, $errline) private function catchWarning ($errno, $errstr, $errfile, $errline) {
{ $this->error[] = array(
$this->setError(array(
'error' => "Connecting to the POP3 server raised a PHP warning: ", 'error' => "Connecting to the POP3 server raised a PHP warning: ",
'errno' => $errno, 'errno' => $errno,
'errstr' => $errstr, 'errstr' => $errstr
'errfile' => $errfile, );
'errline' => $errline
));
} }
// End of class
} }
?>

File diff suppressed because it is too large Load Diff