From 8c9b33c3b6e91d22d5d0e2f919b000e783e170db Mon Sep 17 00:00:00 2001 From: Jake Spurlock Date: Mon, 27 Jul 2020 20:17:36 +0000 Subject: [PATCH] Mail: PHPMailer swap to use is_email for the default validator. Prior to the PHPMailer update in 5.5, old version of the PHPMailer was setting the validator to 'auto' resulting in a sophisticated logic for determining what email address validation should be used. But the new version defaults to 'php', possibly leading to rejection of email addresses which were fine prior to the upgrade. Let's use the WordPress core function `is_email()` so that it can be fully pluggable. Fixes #50720. Props david.binda, ayeshrajans, Synchro, SergeyBiryukov, whyisjake. git-svn-id: https://develop.svn.wordpress.org/trunk@48645 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/pluggable.php | 4 ++++ tests/phpunit/includes/mock-mailer.php | 7 ++++++- tests/phpunit/tests/mail.php | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index c614ac0ed6..b2ed4642c5 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -216,6 +216,10 @@ if ( ! function_exists( 'wp_mail' ) ) : require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php'; require_once ABSPATH . WPINC . '/PHPMailer/Exception.php'; $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true ); + + $phpmailer::$validator = static function ( $email ) { + return (bool) is_email( $email ); + }; } // Headers. diff --git a/tests/phpunit/includes/mock-mailer.php b/tests/phpunit/includes/mock-mailer.php index edc36b9ec6..e5e3d98fa2 100644 --- a/tests/phpunit/includes/mock-mailer.php +++ b/tests/phpunit/includes/mock-mailer.php @@ -96,7 +96,12 @@ function tests_retrieve_phpmailer_instance() { function reset_phpmailer_instance() { $mailer = tests_retrieve_phpmailer_instance(); if ( $mailer ) { - $GLOBALS['phpmailer'] = new MockPHPMailer( true ); + $mailer = new MockPHPMailer( true ); + $mailer::$validator = static function ( $email ) { + return (bool) is_email( $email ); + }; + + $GLOBALS['phpmailer'] = $mailer; return true; } diff --git a/tests/phpunit/tests/mail.php b/tests/phpunit/tests/mail.php index d24d5e831a..f520e1e5a0 100644 --- a/tests/phpunit/tests/mail.php +++ b/tests/phpunit/tests/mail.php @@ -407,4 +407,12 @@ class Tests_Mail extends WP_UnitTestCase { $this->assertEquals( 'wp_mail_failed', $call_args[0]->get_error_code() ); $this->assertEquals( $expected_error_data, $call_args[0]->get_error_data() ); } + + /** + * @ticket 50720 + */ + function test_phpmailer_validator() { + $phpmailer = $GLOBALS['phpmailer']; + $this->assertTrue( $phpmailer->validateAddress( 'foo@192.168.1.1' ), 'Assert PHPMailer accepts IP address email addresses' ); + } }