Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Udating PHPMailer to version 5.2.3. #1830

Merged
merged 1 commit into from

2 participants

@piotr-cz

There is a bug in 5.2.2 occurring on some systems (including mine).

see Issue 134: Warning: preg_match()

Note: This PHPMailer version is faulty marked as 5.2.2

@eddieajau eddieajau merged commit 98a39bd into joomla:staging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 15, 2013
  1. @piotr-cz

    Udating PHPMailer to version 5.2.3.

    piotr-cz authored
    There was a bug in 5.2.2 occuring on some systems (including mine)
    
    see Issue 134: https://code.google.com/a/apache-extras.org/p/phpmailer/issues/detail?id=140&can=1&start=100
    
    Note: This version is faulty marked as 5.2.2 (see https://code.google.com/a/apache-extras.org/p/phpmailer/source/browse/tags/5.2.3/class.phpmailer.php)
This page is out of date. Refresh to see the latest.
View
2  libraries/phpmailer/LICENSE
@@ -146,7 +146,7 @@ such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
-
+
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
View
39 libraries/phpmailer/phpmailer.php
@@ -171,7 +171,7 @@ class PHPMailer {
* @var boolean
*/
public $UseSendmailOptions = true;
-
+
/**
* Path to PHPMailer plugins. Useful if the SMTP class
* is in a different directory than the PHP include path.
@@ -264,7 +264,7 @@ class PHPMailer {
* @var string
*/
public $AuthType = '';
-
+
/**
* Sets SMTP realm.
* @var string
@@ -491,7 +491,7 @@ class PHPMailer {
const STOP_CONTINUE = 1; // message?, likely ok to continue processing
const STOP_CRITICAL = 2; // message, plus full stop, critical error reached
const CRLF = "\r\n"; // SMTP RFC specified EOL
-
+
/////////////////////////////////////////////////
// METHODS, VARIABLES
/////////////////////////////////////////////////
@@ -727,6 +727,8 @@ public function SetFrom($address, $name = '', $auto = 1) {
* Conforms to RFC5322: Uses *correct* regex on which FILTER_VALIDATE_EMAIL is
* based; So why not use FILTER_VALIDATE_EMAIL? Because it was broken to
* not allow a@b type valid addresses :(
+ * Some Versions of PHP break on the regex though, likely due to PCRE, so use
+ * the older validation method for those users. (http://php.net/manual/en/pcre.installation.php)
* @link http://squiloople.com/2009/12/20/email-address-validation/
* @copyright regex Copyright Michael Rushton 2009-10 | http://squiloople.com/ | Feel free to use and redistribute this code. But please keep this copyright notice.
* @param string $address The email address to check
@@ -735,7 +737,17 @@ public function SetFrom($address, $name = '', $auto = 1) {
* @access public
*/
public static function ValidateAddress($address) {
- return preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[ ])+|(?>[ ]*\x0D\x0A)?[ ]+)?)(\((?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}|(?!(?:.*[a-f0-9][:\]]){7,})((?6)(?>:(?6)){0,5})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){5,})(?8)?::(?>((?6)(?>:(?6)){0,3}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address);
+ if ((defined('PCRE_VERSION')) && (version_compare(PCRE_VERSION, '8.0') >= 0)) {
+ return preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[ ])+|(?>[ ]*\x0D\x0A)?[ ]+)?)(\((?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}|(?!(?:.*[a-f0-9][:\]]){7,})((?6)(?>:(?6)){0,5})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){5,})(?8)?::(?>((?6)(?>:(?6)){0,3}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address);
+ } elseif (function_exists('filter_var')) { //Introduced in PHP 5.2
+ if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
+ return false;
+ } else {
+ return true;
+ }
+ } else {
+ return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);
+ }
}
/////////////////////////////////////////////////
@@ -957,7 +969,7 @@ protected function MailSend($header, $body) {
* @return bool
*/
protected function SmtpSend($header, $body) {
- require_once $this->PluginDir . 'class.smtp.php';
+ require_once $this->PluginDir . 'smtp.php';
$bad_rcpt = array();
if(!$this->SmtpConnect()) {
@@ -965,7 +977,8 @@ protected function SmtpSend($header, $body) {
}
$smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
if(!$this->smtp->Mail($smtp_from)) {
- throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL);
+ $this->SetError($this->Lang('from_failed') . $smtp_from . " : " . implode(",",$this->smtp->getError())) ;
+ throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
}
// Attempt to send attach all recipients
@@ -1064,7 +1077,7 @@ public function SmtpConnect() {
if ($tls) {
if (!$this->smtp->StartTLS()) {
- throw new phpmailerException($this->Lang('tls'));
+ throw new phpmailerException($this->Lang('connect_host'));
}
//We must resend HELO after tls negotiation
@@ -1849,7 +1862,7 @@ protected function EncodeFile($path, $encoding = 'base64') {
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
set_magic_quotes_runtime(0);
} else {
- ini_set('magic_quotes_runtime', 0);
+ ini_set('magic_quotes_runtime', 0);
}
}
$file_buffer = file_get_contents($path);
@@ -1858,7 +1871,7 @@ protected function EncodeFile($path, $encoding = 'base64') {
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
set_magic_quotes_runtime($magic_quotes);
} else {
- ini_set('magic_quotes_runtime', $magic_quotes);
+ ini_set('magic_quotes_runtime', $magic_quotes);
}
}
return $file_buffer;
@@ -2135,13 +2148,13 @@ public function EncodeQ($str, $position = 'text') {
$pattern = '\075\000-\011\013\014\016-\037\077\137\177-\377' . $pattern;
break;
}
-
+
if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
foreach (array_unique($matches[0]) as $char) {
$encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
}
}
-
+
//Replace every spaces to _ (more readable than =20)
return str_replace(' ', '_', $encoded);
}
@@ -2479,12 +2492,12 @@ public function MsgHTML($message, $basedir = '') {
if ($directory == '.') {
$directory = '';
}
- $cid = 'cid:' . md5($filename);
+ $cid = 'cid:' . md5($url);
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$mimeType = self::_mime_types($ext);
if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; }
if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
- if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType) ) {
+ if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($url), $filename, 'base64', $mimeType) ) {
$message = preg_replace("/".$images[1][$i]."=[\"']".preg_quote($url, '/')."[\"']/Ui", $images[1][$i]."=\"".$cid."\"", $message);
}
}
View
28 libraries/phpmailer/smtp.php
@@ -272,10 +272,10 @@ public function Authenticate($username, $password, $authtype='LOGIN', $realm='',
case 'PLAIN':
// Start authentication
fputs($this->smtp_conn,"AUTH PLAIN" . $this->CRLF);
-
+
$rply = $this->get_lines();
$code = substr($rply,0,3);
-
+
if($code != 334) {
$this->error =
array("error" => "AUTH not accepted from server",
@@ -291,7 +291,7 @@ public function Authenticate($username, $password, $authtype='LOGIN', $realm='',
$rply = $this->get_lines();
$code = substr($rply,0,3);
-
+
if($code != 235) {
$this->error =
array("error" => "Authentication not accepted from server",
@@ -306,10 +306,10 @@ public function Authenticate($username, $password, $authtype='LOGIN', $realm='',
case 'LOGIN':
// Start authentication
fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
-
+
$rply = $this->get_lines();
$code = substr($rply,0,3);
-
+
if($code != 334) {
$this->error =
array("error" => "AUTH not accepted from server",
@@ -320,13 +320,13 @@ public function Authenticate($username, $password, $authtype='LOGIN', $realm='',
}
return false;
}
-
+
// Send encoded username
fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
-
+
$rply = $this->get_lines();
$code = substr($rply,0,3);
-
+
if($code != 334) {
$this->error =
array("error" => "Username not accepted from server",
@@ -337,13 +337,13 @@ public function Authenticate($username, $password, $authtype='LOGIN', $realm='',
}
return false;
}
-
+
// Send encoded password
fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
-
+
$rply = $this->get_lines();
$code = substr($rply,0,3);
-
+
if($code != 235) {
$this->error =
array("error" => "Password not accepted from server",
@@ -374,12 +374,12 @@ public function Authenticate($username, $password, $authtype='LOGIN', $realm='',
return false;
}
$msg1 = $ntlm_client->TypeMsg1($realm, $workstation);//msg1
-
+
fputs($this->smtp_conn,"AUTH NTLM " . base64_encode($msg1) . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
-
+
if($code != 334) {
$this->error =
@@ -391,7 +391,7 @@ public function Authenticate($username, $password, $authtype='LOGIN', $realm='',
}
return false;
}
-
+
$challange = substr($rply,3);//though 0 based, there is a white space after the 3 digit number....//msg2
$challange = base64_decode($challange);
$ntlm_res = $ntlm_client->NTLMResponse(substr($challange,24,8),$password);
Something went wrong with that request. Please try again.