Update PHPMailer to version 5.2.28 (#6282)

* Update class.phpmailer.php

* Update class.pop3.php

* Update class.smtp.php
This commit is contained in:
FusionPBX 2022-01-31 12:34:48 -07:00 committed by GitHub
parent 158391c5ec
commit 1cc629efd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5503 additions and 3994 deletions

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff