External Libraries: Upgrade PHPMailer to version 6.1.6.

Now that WordPress Core supports PHP >= 5.6, the PHPMailer library can be updated to the latest version.

The PHPMailer files now reside in a new directory, `wp-includes/PHPMailer`. These files are copied verbatim from the library upstream and will make updating in the future easier. For backwards compatibility, the old files will remain and trigger deprecated file warnings.

The PHPMailer class is also now under the `PHPMailer\PHPMailer\PHPMailer` namespace. The `PHPMailer` class in the global namespace has been aliased for a seamless transition.

This upgrade also clears up a handful of PHP compatibility issues detailed in #49922.

For a full list of changes, see the PHPMailer GitHub: https://github.com/PHPMailer/PHPMailer/compare/v5.2.27...v6.1.6.

Props Synchro, SergeyBiryukov, desrosj, donmhico, ayeshrajans.
Fixes #41750.

git-svn-id: https://develop.svn.wordpress.org/trunk@48033 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2020-06-12 15:45:30 +00:00
parent 55f0a18c02
commit 0933882c6e
9 changed files with 6276 additions and 5284 deletions

View File

@ -112,11 +112,12 @@
<exclude-pattern>/src/wp-includes/class-IXR\.php</exclude-pattern> <exclude-pattern>/src/wp-includes/class-IXR\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/class-json\.php</exclude-pattern> <exclude-pattern>/src/wp-includes/class-json\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/class-phpass\.php</exclude-pattern> <exclude-pattern>/src/wp-includes/class-phpass\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/class-phpmailer\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/class-pop3\.php</exclude-pattern> <exclude-pattern>/src/wp-includes/class-pop3\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/class-requests\.php</exclude-pattern> <exclude-pattern>/src/wp-includes/class-requests\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/class-simplepie\.php</exclude-pattern> <exclude-pattern>/src/wp-includes/class-simplepie\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/class-smtp\.php</exclude-pattern> <exclude-pattern>/src/wp-includes/PHPMailer/Exception\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/PHPMailer/PHPMailer\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/PHPMailer/SMTP\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/class-snoopy\.php</exclude-pattern> <exclude-pattern>/src/wp-includes/class-snoopy\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/class-wp-block-parser\.php</exclude-pattern> <exclude-pattern>/src/wp-includes/class-wp-block-parser\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/deprecated\.php</exclude-pattern> <exclude-pattern>/src/wp-includes/deprecated\.php</exclude-pattern>

View File

@ -0,0 +1,39 @@
<?php
/**
* PHPMailer Exception class.
* PHP Version 5.5.
*
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2017 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @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.
*/
namespace PHPMailer\PHPMailer;
/**
* PHPMailer exception handler.
*
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
*/
class Exception extends \Exception
{
/**
* Prettify error message output.
*
* @return string
*/
public function errorMessage()
{
return '<strong>' . htmlspecialchars($this->getMessage()) . "</strong><br />\n";
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -158,7 +158,7 @@ if ( ! function_exists( 'wp_mail' ) ) :
* *
* @since 1.2.1 * @since 1.2.1
* *
* @global PHPMailer $phpmailer * @global PHPMailer\PHPMailer\PHPMailer $phpmailer
* *
* @param string|array $to Array or comma-separated list of email addresses to send message. * @param string|array $to Array or comma-separated list of email addresses to send message.
* @param string $subject Email subject * @param string $subject Email subject
@ -210,10 +210,11 @@ if ( ! function_exists( 'wp_mail' ) ) :
global $phpmailer; global $phpmailer;
// (Re)create it, if it's gone missing. // (Re)create it, if it's gone missing.
if ( ! ( $phpmailer instanceof PHPMailer ) ) { if ( ! ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer ) ) {
require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
require_once ABSPATH . WPINC . '/class-smtp.php'; require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
$phpmailer = new PHPMailer( true ); require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
$phpmailer = new PHPMailer\PHPMailer\PHPMailer( true );
} }
// Headers. // Headers.
@ -356,7 +357,7 @@ if ( ! function_exists( 'wp_mail' ) ) :
try { try {
$phpmailer->setFrom( $from_email, $from_name, false ); $phpmailer->setFrom( $from_email, $from_name, false );
} catch ( phpmailerException $e ) { } catch ( PHPMailer\PHPMailer\Exception $e ) {
$mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' ); $mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
$mail_error_data['phpmailer_exception_code'] = $e->getCode(); $mail_error_data['phpmailer_exception_code'] = $e->getCode();
@ -404,7 +405,7 @@ if ( ! function_exists( 'wp_mail' ) ) :
$phpmailer->addReplyTo( $address, $recipient_name ); $phpmailer->addReplyTo( $address, $recipient_name );
break; break;
} }
} catch ( phpmailerException $e ) { } catch ( PHPMailer\PHPMailer\Exception $e ) {
continue; continue;
} }
} }
@ -455,12 +456,16 @@ if ( ! function_exists( 'wp_mail' ) ) :
foreach ( (array) $headers as $name => $content ) { foreach ( (array) $headers as $name => $content ) {
// Only add custom headers not added automatically by PHPMailer. // Only add custom headers not added automatically by PHPMailer.
if ( ! in_array( $name, array( 'MIME-Version', 'X-Mailer' ), true ) ) { if ( ! in_array( $name, array( 'MIME-Version', 'X-Mailer' ), true ) ) {
$phpmailer->addCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) ); try {
$phpmailer->addCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
} catch ( PHPMailer\PHPMailer\Exception $e ) {
continue;
}
} }
} }
if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) { if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) {
$phpmailer->addCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) ); $phpmailer->addCustomHeader( sprintf( 'Content-Type: %s; boundary="%s"', $content_type, $boundary ) );
} }
} }
@ -468,7 +473,7 @@ if ( ! function_exists( 'wp_mail' ) ) :
foreach ( $attachments as $attachment ) { foreach ( $attachments as $attachment ) {
try { try {
$phpmailer->addAttachment( $attachment ); $phpmailer->addAttachment( $attachment );
} catch ( phpmailerException $e ) { } catch ( PHPMailer\PHPMailer\Exception $e ) {
continue; continue;
} }
} }
@ -486,17 +491,17 @@ if ( ! function_exists( 'wp_mail' ) ) :
// Send! // Send!
try { try {
return $phpmailer->send(); return $phpmailer->send();
} catch ( phpmailerException $e ) { } catch ( PHPMailer\PHPMailer\Exception $e ) {
$mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' ); $mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
$mail_error_data['phpmailer_exception_code'] = $e->getCode(); $mail_error_data['phpmailer_exception_code'] = $e->getCode();
/** /**
* Fires after a phpmailerException is caught. * Fires after a PHPMailer\PHPMailer\Exception is caught.
* *
* @since 4.4.0 * @since 4.4.0
* *
* @param WP_Error $error A WP_Error object with the phpmailerException message, and an array * @param WP_Error $error A WP_Error object with the PHPMailer\PHPMailer\Exception message, and an array
* containing the mail recipient, subject, message, headers, and attachments. * containing the mail recipient, subject, message, headers, and attachments.
*/ */
do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) ); do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );

View File

@ -1,7 +1,8 @@
<?php <?php
require_once ABSPATH . '/wp-includes/class-phpmailer.php'; require_once ABSPATH . '/wp-includes/PHPMailer/PHPMailer.php';
require_once ABSPATH . '/wp-includes/PHPMailer/Exception.php';
class MockPHPMailer extends PHPMailer { class MockPHPMailer extends PHPMailer\PHPMailer\PHPMailer {
var $mock_sent = array(); var $mock_sent = array();
function preSend() { function preSend() {

View File

@ -81,7 +81,7 @@ class Tests_Mail extends WP_UnitTestCase {
// We need some better assertions here but these catch the failure for now. // We need some better assertions here but these catch the failure for now.
$this->assertEquals( $body, $mailer->get_sent()->body ); $this->assertEquals( $body, $mailer->get_sent()->body );
$this->assertTrue( strpos( $mailer->get_sent()->header, 'boundary="----=_Part_4892_25692638.1192452070893"' ) > 0 ); $this->assertTrue( strpos( iconv_mime_decode_headers( ( $mailer->get_sent()->header ) )['Content-Type'][0], 'boundary="----=_Part_4892_25692638.1192452070893"' ) > 0 );
$this->assertTrue( strpos( $mailer->get_sent()->header, 'charset=' ) > 0 ); $this->assertTrue( strpos( $mailer->get_sent()->header, 'charset=' ) > 0 );
} }