1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-03 21:27:25 +02:00

Bugtracker #4082 - upgrade PHPMailer to V2.0.0

This commit is contained in:
e107steved
2007-12-07 19:59:24 +00:00
parent 0b6ed873b9
commit 5d0fdfe3c8
3 changed files with 3005 additions and 2720 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,224 +1,273 @@
<?php <?php
/* /*~ class.pop3.php
POP Before SMTP Authentication Class .---------------------------------------------------------------------------.
Version 1.0 | 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) |
'---------------------------------------------------------------------------'
Author: Richard Davey (rich@corephp.co.uk) /**
License: LGPL, see PHPMailer License * POP Before SMTP Authentication Class
* Version 1.0
Specifically for PHPMailer to allow POP before SMTP authentication. *
Does not yet work with APOP - if you have an APOP account, contact me * Author: Richard Davey (rich@corephp.co.uk)
and we can test changes to this script. * License: LGPL, see PHPMailer License
*
This class is based on the structure of the SMTP class by Chris Ryan * Specifically for PHPMailer to allow POP before SMTP authentication.
* Does not yet work with APOP - if you have an APOP account, contact me
This class is rfc 1939 compliant and implements all the commands * and we can test changes to this script.
required for POP3 connection, authentication and disconnection. *
* This class is based on the structure of the SMTP class by Chris Ryan
@package PHPMailer *
@author Richard Davey * 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 class POP3
{ {
// Default POP3 port /**
var $POP3_PORT = 110; * Default POP3 port
* @var int
*/
var $POP3_PORT = 110;
// Default Timeout /**
var $POP3_TIMEOUT = 30; * Default Timeout
* @var int
*/
var $POP3_TIMEOUT = 30;
// Carriage Return + Line Feed /**
var $CRLF = "\r\n"; * POP3 Carriage Return + Line Feed
* @var string
*/
var $CRLF = "\r\n";
// Displaying Debug warnings? (0 = now, 1+ = yes) /**
var $do_debug = 2; * Displaying Debug warnings? (0 = now, 1+ = yes)
* @var int
*/
var $do_debug = 2;
// Socket connection resource handle /**
var $pop_conn; * POP3 Mail Server
* @var string
// Boolean state of connection */
var $connected; var $host;
// Error log array
var $error;
// POP3 Server Connection Required values
// Mail Server /**
var $host; * POP3 Port
* @var int
*/
var $port;
// Port /**
var $port; * POP3 Timeout Value
* @var int
// Timeout Value */
var $tval; var $tval;
// POP3 Username /**
var $username; * POP3 Username
* @var string
// POP3 Password */
var $password; var $username;
/** /**
* Our constructor, sets the initial values * POP3 Password
* * @var string
* @return POP3 */
*/ var $password;
function POP3 ()
/**#@+
* @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->pop_conn = 0;
$this->connected = false; $this->connected = false;
$this->error = null; $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) * Combination of public events - connect, login, disconnect
{ *
$this->port = $this->POP3_PORT; * @param string $host
} * @param integer $port
else * @param integer $tval
{ * @param string $username
$this->port = $port; * @param string $password
} */
function Authorise ($host, $port = false, $tval = false, $username, $password, $debug_level = 0)
// If no port value is passed, retrieve it {
if ($tval == false) $this->host = $host;
{
$this->tval = $this->POP3_TIMEOUT;
}
else
{
$this->tval = $tval;
}
$this->do_debug = $debug_level; // If no port value is passed, retrieve it
$this->username = $username; if ($port == false)
$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? $this->port = $this->POP3_PORT;
if ($this->connected) }
{ else
return true; {
} $this->port = $port;
}
/*
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 no port value is passed, retrieve it
if (version_compare(phpversion(), '4.3.0', 'ge')) if ($tval == false)
{ {
stream_set_timeout($this->pop_conn, $tval, 0); $this->tval = $this->POP3_TIMEOUT;
} }
else else
{ {
// Does not work on Windows $this->tval = $tval;
if (substr(PHP_OS, 0, 3) !== 'WIN') }
{
socket_set_timeout($this->pop_conn, $tval, 0); $this->do_debug = $debug_level;
} $this->username = $username;
} $this->password = $password;
// Get the POP3 server response // Refresh the error log
$pop3_response = $this->getResponse(); $this->error = null;
// Check for the +OK // Connect
if ($this->checkResponse($pop3_response)) $result = $this->Connect($this->host, $this->port, $this->tval);
{
// The connection is established and the POP3 server is talking if ($result)
$this->connected = true; {
return true; $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) * Login to the POP3 server (does not support APOP yet)
* *
@@ -228,71 +277,70 @@ class POP3
*/ */
function Login ($username = '', $password = '') function Login ($username = '', $password = '')
{ {
if ($this->connected == false) if ($this->connected == false)
{ {
$this->error = 'Not connected to POP3 server'; $this->error = 'Not connected to POP3 server';
if ($this->do_debug >= 1) if ($this->do_debug >= 1)
{ {
$this->displayErrors(); $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)) if (empty($username))
{ {
return true; $username = $this->username;
} }
else
{ if (empty($password))
return false; {
} $password = $this->password;
} }
else
{ $pop_username = "USER $username" . $this->CRLF;
return false; $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 * Disconnect from the POP3 server
*
*/ */
function Disconnect () function Disconnect ()
{ {
$this->sendString('QUIT'); $this->sendString('QUIT');
fclose($this->pop_conn); fclose($this->pop_conn);
} }
/* /*
--------------- ---------------
Private Methods Private Methods
--------------- ---------------
*/ */
/** /**
* Get the socket response back. * Get the socket response back.
* $size is the maximum number of bytes to retrieve * $size is the maximum number of bytes to retrieve
@@ -302,9 +350,9 @@ class POP3
*/ */
function getResponse ($size = 128) function getResponse ($size = 128)
{ {
$pop3_response = fgets($this->pop_conn, $size); $pop3_response = fgets($this->pop_conn, $size);
return $pop3_response; return $pop3_response;
} }
/** /**
@@ -315,12 +363,12 @@ class POP3
*/ */
function sendString ($string) function sendString ($string)
{ {
$bytes_sent = fwrite($this->pop_conn, $string, strlen($string)); $bytes_sent = fwrite($this->pop_conn, $string, strlen($string));
return $bytes_sent; return $bytes_sent;
} }
/** /**
* Checks the POP3 server response for +OK or -ERR * Checks the POP3 server response for +OK or -ERR
* *
@@ -329,61 +377,61 @@ class POP3
*/ */
function checkResponse ($string) function checkResponse ($string)
{ {
if (substr($string, 0, 3) !== '+OK') if (substr($string, 0, 3) !== '+OK')
{ {
$this->error = 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;
}
else
{
return true;
}
if ($this->do_debug >= 1)
{
$this->displayErrors();
}
return false;
}
else
{
return true;
}
} }
/** /**
* If debug is enabled, display the error message array * If debug is enabled, display the error message array
* *
*/ */
function displayErrors () function displayErrors ()
{ {
echo '<pre>'; echo '<pre>';
foreach ($this->error as $single_error) foreach ($this->error as $single_error)
{ {
print_r($single_error); print_r($single_error);
}
echo '</pre>';
} }
/** 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 /**
* 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
} }
?> ?>

File diff suppressed because it is too large Load Diff