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

Update phpmailer to PHP5 version, start of class-based mail handling object. Probably break a few things along the way.

This commit is contained in:
e107steved
2009-09-01 19:53:08 +00:00
parent 30e6ad4225
commit bbbde843f6
6 changed files with 2001 additions and 1535 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -2,14 +2,16 @@
/*~ class.pop3.php /*~ class.pop3.php
.---------------------------------------------------------------------------. .---------------------------------------------------------------------------.
| Software: PHPMailer - PHP email class | | Software: PHPMailer - PHP email class |
| Version: 2.0.4 | | Version: 5.0.0 |
| Contact: via sourceforge.net support pages (also www.codeworxtech.com) | | Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
| Info: http://phpmailer.sourceforge.net | | Info: http://phpmailer.sourceforge.net |
| Support: http://sourceforge.net/projects/phpmailer/ | | Support: http://sourceforge.net/projects/phpmailer/ |
| ------------------------------------------------------------------------- | | ------------------------------------------------------------------------- |
| Author: Andy Prevost (project admininistrator) | | Admin: Andy Prevost (project admininistrator) |
| Author: Brent R. Matzelle (original founder) | | Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. | | : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
| Founder: Brent R. Matzelle (original founder) |
| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
| Copyright (c) 2001-2003, Brent R. Matzelle | | Copyright (c) 2001-2003, Brent R. Matzelle |
| ------------------------------------------------------------------------- | | ------------------------------------------------------------------------- |
| License: Distributed under the Lesser General Public License (LGPL) | | License: Distributed under the Lesser General Public License (LGPL) |
@@ -23,18 +25,32 @@
| - Technology Consulting | | - Technology Consulting |
| - Oursourcing (highly qualified programmers and graphic designers) | | - Oursourcing (highly qualified programmers and graphic designers) |
'---------------------------------------------------------------------------' '---------------------------------------------------------------------------'
*/
/**
* PHPMailer - PHP POP Before SMTP Authentication Class
* NOTE: Designed for use with PHP version 5 and up
* @package PHPMailer
* @author Andy Prevost
* @author Marcus Bointon
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
* @version $Id: class.pop3.php,v 1.5 2009-09-01 19:53:08 e107steved Exp $
*/
/** /**
* POP Before SMTP Authentication Class * POP Before SMTP Authentication Class
* Version 5.0.0
* *
* Author: Richard Davey (rich@corephp.co.uk) * Author: Richard Davey (rich@corephp.co.uk)
* Modifications: Andy Prevost
* License: LGPL, see PHPMailer License * License: LGPL, see PHPMailer License
* *
* Specifically for PHPMailer to allow POP before SMTP authentication. * Specifically for PHPMailer to allow POP before SMTP authentication.
* Does not yet work with APOP - if you have an APOP account, contact me * Does not yet work with APOP - if you have an APOP account, contact Richard Davey
* and we can test changes to this script. * 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 based on the structure of the SMTP class originally authored by Chris Ryan
* *
* This class is rfc 1939 compliant and implements all the commands * This class is rfc 1939 compliant and implements all the commands
* required for POP3 connection, authentication and disconnection. * required for POP3 connection, authentication and disconnection.
@@ -43,112 +59,103 @@
* @author Richard Davey * @author Richard Davey
*/ */
class POP3 class POP3 {
{
/** /**
* Default POP3 port * Default POP3 port
* @var int * @var int
*/ */
var $POP3_PORT = 110; public $POP3_PORT = 110;
/** /**
* Default Timeout * Default Timeout
* @var int * @var int
*/ */
var $POP3_TIMEOUT = 30; public $POP3_TIMEOUT = 30;
/** /**
* POP3 Carriage Return + Line Feed * POP3 Carriage Return + Line Feed
* @var string * @var string
*/ */
var $CRLF = "\r\n"; public $CRLF = "\r\n";
/** /**
* Displaying Debug warnings? (0 = now, 1+ = yes) * Displaying Debug warnings? (0 = now, 1+ = yes)
* @var int * @var int
*/ */
var $do_debug = 2; public $do_debug = 2;
/** /**
* POP3 Mail Server * POP3 Mail Server
* @var string * @var string
*/ */
var $host; public $host;
/** /**
* POP3 Port * POP3 Port
* @var int * @var int
*/ */
var $port; public $port;
/** /**
* POP3 Timeout Value * POP3 Timeout Value
* @var int * @var int
*/ */
var $tval; public $tval;
/** /**
* POP3 Username * POP3 Username
* @var string * @var string
*/ */
var $username; public $username;
/** /**
* POP3 Password * POP3 Password
* @var string * @var string
*/ */
var $password; public $password;
/**#@+ /////////////////////////////////////////////////
* @access private // PROPERTIES, PRIVATE AND PROTECTED
*/ /////////////////////////////////////////////////
var $pop_conn;
var $connected; private $pop_conn;
var $error; // Error log array private $connected;
/**#@-*/ private $error; // Error log array
/** /**
* Constructor, sets the initial values * Constructor, sets the initial values
* * @access public
* @return POP3 * @return POP3
*/ */
function POP3 () public function __construct() {
{ $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 * Combination of public events - connect, login, disconnect
* * @access public
* @param string $host * @param string $host
* @param integer $port * @param integer $port
* @param integer $tval * @param integer $tval
* @param string $username * @param string $username
* @param string $password * @param string $password
*/ */
function Authorise ($host, $port = false, $tval = 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 is passed, retrieve it // If no port value is passed, retrieve it
if ($port == false) if ($port == false) {
{
$this->port = $this->POP3_PORT; $this->port = $this->POP3_PORT;
} } else {
else
{
$this->port = $port; $this->port = $port;
} }
// If no port value is passed, retrieve it // If no port value is passed, retrieve it
if ($tval == false) if ($tval == false) {
{
$this->tval = $this->POP3_TIMEOUT; $this->tval = $this->POP3_TIMEOUT;
} } else {
else
{
$this->tval = $tval; $this->tval = $tval;
} }
@@ -157,17 +164,15 @@ class POP3
$this->password = $password; $this->password = $password;
// Refresh the error log // Refresh the error log
$this->error = null; $this->error = null;
// Connect // Connect
$result = $this->Connect($this->host, $this->port, $this->tval); $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;
@@ -183,23 +188,21 @@ class POP3
/** /**
* Connect to the POP3 server * Connect to the POP3 server
* * @access public
* @param string $host * @param string $host
* @param integer $port * @param integer $port
* @param integer $tval * @param integer $tval
* @return boolean * @return boolean
*/ */
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. 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 Rather than supress it with @fsockopen, let's capture it cleanly instead
*/ */
set_error_handler(array(&$this, 'catchWarning')); set_error_handler(array(&$this, 'catchWarning'));
@@ -215,215 +218,183 @@ class POP3
restore_error_handler(); restore_error_handler();
// Does the Error Log now contain anything? // Does the Error Log now contain anything?
if ($this->error && $this->do_debug >= 1) if ($this->error && $this->do_debug >= 1) {
{ $this->displayErrors();
$this->displayErrors();
} }
// Did we connect? // Did we connect?
if ($this->pop_conn == false) if ($this->pop_conn == false) {
{ // It would appear not...
// It would appear not... $this->error = 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) if ($this->do_debug >= 1) {
{ $this->displayErrors();
$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;
} }
return false;
} }
/** // Increase the stream time-out
* 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) // Check for PHP 4.3.0 or later
{ if (version_compare(phpversion(), '5.0.0', 'ge')) {
$this->displayErrors(); 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);
} }
}
if (empty($username)) // Get the POP3 server response
{ $pop3_response = $this->getResponse();
$username = $this->username;
}
if (empty($password)) // Check for the +OK
{ if ($this->checkResponse($pop3_response)) {
$password = $this->password; // 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)
* @access public
* @param string $username
* @param string $password
* @return boolean
*/
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;
}
if (empty($password)) {
$password = $this->password;
}
$pop_username = "USER $username" . $this->CRLF; $pop_username = "USER $username" . $this->CRLF;
$pop_password = "PASS $password" . $this->CRLF; $pop_password = "PASS $password" . $this->CRLF;
// Send the Username // Send the Username
$this->sendString($pop_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(); $pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) 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; return true;
} else {
return false;
}
} else {
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
*
*/
function displayErrors ()
{
echo '<pre>';
foreach ($this->error as $single_error) /**
{ * If debug is enabled, display the error message array
print_r($single_error); * @access private
*/
private function displayErrors () {
echo '<pre>';
foreach ($this->error as $single_error) {
print_r($single_error);
} }
echo '</pre>'; echo '</pre>';
} }
/** /**
* Takes over from PHP for the socket warning handler * Takes over from PHP for the socket warning handler
* * @access private
* @param integer $errno * @param integer $errno
* @param string $errstr * @param string $errstr
* @param string $errfile * @param string $errfile
* @param integer $errline * @param integer $errline
*/ */
function catchWarning ($errno, $errstr, $errfile, $errline) private function catchWarning ($errno, $errstr, $errfile, $errline) {
{
$this->error[] = array( $this->error[] = 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,
@@ -433,4 +404,4 @@ class POP3
// End of class // End of class
} }
?> ?>

File diff suppressed because it is too large Load Diff

View File

@@ -1,23 +0,0 @@
<?php
/**
* PHPMailer language file.
* English Version
*/
$PHPMAILER_LANG = array();
$PHPMAILER_LANG['provide_address'] = 'You must provide at least one recipient email address.';
$PHPMAILER_LANG['mailer_not_supported'] = ' mailer is not supported.';
$PHPMAILER_LANG['execute'] = 'Could not execute: ';
$PHPMAILER_LANG['instantiate'] = 'Could not instantiate mail function.';
$PHPMAILER_LANG['authenticate'] = 'SMTP Error: Could not authenticate.';
$PHPMAILER_LANG['from_failed'] = 'The following From address failed: ';
$PHPMAILER_LANG['recipients_failed'] = 'SMTP Error: The following recipients failed: ';
$PHPMAILER_LANG['data_not_accepted'] = 'SMTP Error: Data not accepted.';
$PHPMAILER_LANG['connect_host'] = 'SMTP Error: Could not connect to SMTP host.';
$PHPMAILER_LANG['file_access'] = 'Could not access file: ';
$PHPMAILER_LANG['file_open'] = 'File Error: Could not open file: ';
$PHPMAILER_LANG['encoding'] = 'Unknown encoding: ';
$PHPMAILER_LANG['signing'] = 'Signing Error: ';
$PHPMAILER_LANG['smtp_error'] = 'SMTP server error: ';
?>

View File

@@ -4,8 +4,8 @@
| e107 website system - Language File. | e107 website system - Language File.
| |
| $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_mailout.php,v $ | $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_mailout.php,v $
| $Revision: 1.5 $ | $Revision: 1.6 $
| $Date: 2008-07-28 21:33:36 $ | $Date: 2009-09-01 19:53:08 $
| $Author: e107steved $ | $Author: e107steved $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -122,7 +122,7 @@ define('LAN_MAILOUT_110','Send test email');
//define('LAN_MAILOUT_111','Clicking button will send test email to main admin email address'); //define('LAN_MAILOUT_111','Clicking button will send test email to main admin email address');
define('LAN_MAILOUT_112','Click to send email to'); define('LAN_MAILOUT_112','Click to send email to');
define('LAN_MAILOUT_113','Test email from'); define('LAN_MAILOUT_113','Test email from');
define('LAN_MAILOUT_114','This is a test email, it appears that your email settings are working ok!\n\nRegards\nfrom the e107 website system.'); define('LAN_MAILOUT_114',"This is a test email, it appears that your email settings are working ok!\n\nRegards\nfrom the e107 website system.");
define('LAN_MAILOUT_115','Emailing method'); define('LAN_MAILOUT_115','Emailing method');
define('LAN_MAILOUT_116','If unsure, leave as php'); define('LAN_MAILOUT_116','If unsure, leave as php');
define('LAN_MAILOUT_117','complete'); define('LAN_MAILOUT_117','complete');