From 44122bf7df9a2461da809858fa8876292cf15818 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 28 Feb 2022 21:36:22 +0000 Subject: [PATCH] External Libraries: Upgrade PHPMailer to version 6.6.0. This is a minor feature release. > Prior to this version, any OAuth provider needed to extend the provided `OAuth` base class, and this made it difficult to use with libraries other than ones based on the default [https://github.com/thephpleague/oauth2-client league] client packages. The OAuth property now accepts anything that implements the `OAuthProviderInterface`, making it much easier to use things like [https://github.com/googleapis/google-api-php-client Google's own OAuth classes]. Existing implementations that extend the provided `OAuth` base class will still work, as that base class now implements this interface too. > > When TLS errors occurred in PHPMailer, the error messages were often missing important info that might help diagnose/solve the problem. These error messages should now be more informative. A minor change is that a TLS error on SMTP connect will now throw an exception if exceptions are enabled. Release notes: https://github.com/PHPMailer/PHPMailer/releases/tag/v6.6.0 For a full list of changes in this update, see the PHPMailer GitHub: https://github.com/PHPMailer/PHPMailer/compare/v6.5.4...v6.6.0 Follow-up to [50628], [50799], [51169], [51634], [51635], [52252], [52749]. Props jrf, Synchro, miken32. Fixes #55277. git-svn-id: https://develop.svn.wordpress.org/trunk@52811 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/PHPMailer/PHPMailer.php | 41 ++++++++++++++++++++----- src/wp-includes/PHPMailer/SMTP.php | 4 +-- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/wp-includes/PHPMailer/PHPMailer.php b/src/wp-includes/PHPMailer/PHPMailer.php index 25b04e42d0..10f3fe8cda 100644 --- a/src/wp-includes/PHPMailer/PHPMailer.php +++ b/src/wp-includes/PHPMailer/PHPMailer.php @@ -358,9 +358,9 @@ class PHPMailer public $AuthType = ''; /** - * An instance of the PHPMailer OAuth class. + * An implementation of the PHPMailer OAuthTokenProvider interface. * - * @var OAuth + * @var OAuthTokenProvider */ protected $oauth; @@ -750,7 +750,7 @@ class PHPMailer * * @var string */ - const VERSION = '6.5.4'; + const VERSION = '6.6.0'; /** * Error severity: message only, continue processing. @@ -2163,7 +2163,8 @@ class PHPMailer } if ($tls) { if (!$this->smtp->startTLS()) { - throw new Exception($this->lang('connect_host')); + $message = $this->getSmtpErrorMessage('connect_host'); + throw new Exception($message); } //We must resend EHLO after TLS negotiation $this->smtp->hello($hello); @@ -2193,6 +2194,10 @@ class PHPMailer //As we've caught all exceptions, just report whatever the last one was if ($this->exceptions && null !== $lastexception) { throw $lastexception; + } elseif ($this->exceptions) { + // no exception was thrown, likely $this->smtp->connect() failed + $message = $this->getSmtpErrorMessage('connect_host'); + throw new Exception($message); } return false; @@ -4129,6 +4134,26 @@ class PHPMailer return $key; } + /** + * Build an error message starting with a generic one and adding details if possible. + * + * @param string $base_key + * @return string + */ + private function getSmtpErrorMessage($base_key) + { + $message = $this->lang($base_key); + $error = $this->smtp->getError(); + if (!empty($error['error'])) { + $message .= ' ' . $error['error']; + if (!empty($error['detail'])) { + $message .= ' ' . $error['detail']; + } + } + + return $message; + } + /** * Check if an error occurred. * @@ -5029,9 +5054,9 @@ class PHPMailer } /** - * Get the OAuth instance. + * Get the OAuthTokenProvider instance. * - * @return OAuth + * @return OAuthTokenProvider */ public function getOAuth() { @@ -5039,9 +5064,9 @@ class PHPMailer } /** - * Set an OAuth instance. + * Set an OAuthTokenProvider instance. */ - public function setOAuth(OAuth $oauth) + public function setOAuth(OAuthTokenProvider $oauth) { $this->oauth = $oauth; } diff --git a/src/wp-includes/PHPMailer/SMTP.php b/src/wp-includes/PHPMailer/SMTP.php index 138177060e..5ecad21dae 100644 --- a/src/wp-includes/PHPMailer/SMTP.php +++ b/src/wp-includes/PHPMailer/SMTP.php @@ -35,7 +35,7 @@ class SMTP * * @var string */ - const VERSION = '6.5.4'; + const VERSION = '6.6.0'; /** * SMTP line break constant. @@ -483,7 +483,7 @@ class SMTP * @param string $username The user name * @param string $password The password * @param string $authtype The auth type (CRAM-MD5, PLAIN, LOGIN, XOAUTH2) - * @param OAuth $OAuth An optional OAuth instance for XOAUTH2 authentication + * @param OAuthTokenProvider $OAuth An optional OAuthTokenProvider instance for XOAUTH2 authentication * * @return bool True if successfully authenticated */