From 7b89544d44e28eb0be1af9590810ed2a971c9bf7 Mon Sep 17 00:00:00 2001
From: Michael Lee <lee.5151@osu.edu>
Date: Wed, 31 Jul 2024 13:27:17 -0400
Subject: [PATCH] Upgrading drupal/smtp (1.3.0 => 1.4.0)

---
 composer.json                                 |   2 +-
 composer.lock                                 |  18 +--
 vendor/composer/installed.json                |  18 +--
 vendor/composer/installed.php                 |  10 +-
 web/modules/smtp/.gitlab-ci.yml               |  11 +-
 .../smtp/config/install/smtp.settings.yml     |   2 +-
 .../smtp/config/schema/smtp.schema.yml        |   2 +-
 web/modules/smtp/smtp.info.yml                |   8 +-
 web/modules/smtp/smtp.install                 |   9 ++
 web/modules/smtp/smtp.module                  |   1 -
 web/modules/smtp/smtp.post_update.php         |   2 +-
 .../src/ConnectionTester/ConnectionTester.php |   5 +
 web/modules/smtp/src/Form/SMTPConfigForm.php  |  53 ++-------
 .../smtp/src/Plugin/Mail/SMTPMailSystem.php   | 107 +++++++-----------
 .../ConnectionTester/ConnectionTesterTest.php |  22 ++--
 .../src/Kernel/MigrateD7SettingsTest.php      |  12 +-
 .../Unit/Plugin/Mail/SMTPMailSystemTest.php   |  15 +--
 .../tests/src/Unit/SMTPConfigFormTest.php     |   8 +-
 18 files changed, 137 insertions(+), 168 deletions(-)

diff --git a/composer.json b/composer.json
index 02dbb509ec..b7c51f972a 100644
--- a/composer.json
+++ b/composer.json
@@ -150,7 +150,7 @@
         "drupal/scheduler": "2.0.4",
         "drupal/simple_gmap": "3.1.0",
         "drupal/simple_sitemap": "4.1.9",
-        "drupal/smtp": "1.3",
+        "drupal/smtp": "1.4",
         "drupal/social_media": "2.0.0",
         "drupal/social_media_links": "^2.8",
         "drupal/svg_image": "3.0.2",
diff --git a/composer.lock b/composer.lock
index a45236eddb..45ed859968 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "b5c49b8a9853090473c5e6423ca9c81e",
+    "content-hash": "888b0d6bf68e948ce25df536f3aa055d",
     "packages": [
         {
             "name": "algolia/places",
@@ -5855,20 +5855,20 @@
         },
         {
             "name": "drupal/smtp",
-            "version": "1.3.0",
+            "version": "1.4.0",
             "source": {
                 "type": "git",
                 "url": "https://git.drupalcode.org/project/smtp.git",
-                "reference": "8.x-1.3"
+                "reference": "8.x-1.4"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://ftp.drupal.org/files/projects/smtp-8.x-1.3.zip",
-                "reference": "8.x-1.3",
-                "shasum": "10c766f0a3ce588dc27d6ac2b21255a807be81d8"
+                "url": "https://ftp.drupal.org/files/projects/smtp-8.x-1.4.zip",
+                "reference": "8.x-1.4",
+                "shasum": "963b4670dc609f30a8c003d888d88893d0841b21"
             },
             "require": {
-                "drupal/core": "^10.1 || ^11",
+                "drupal/core": "^9.5 || ^10 || ^11",
                 "phpmailer/phpmailer": "^6.1.7"
             },
             "suggest": {
@@ -5877,8 +5877,8 @@
             "type": "drupal-module",
             "extra": {
                 "drupal": {
-                    "version": "8.x-1.3",
-                    "datestamp": "1719260754",
+                    "version": "8.x-1.4",
+                    "datestamp": "1722032780",
                     "security-coverage": {
                         "status": "covered",
                         "message": "Covered by Drupal's security advisory policy"
diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json
index 26c649efa7..0ed1bb9a4e 100644
--- a/vendor/composer/installed.json
+++ b/vendor/composer/installed.json
@@ -6151,21 +6151,21 @@
         },
         {
             "name": "drupal/smtp",
-            "version": "1.3.0",
-            "version_normalized": "1.3.0.0",
+            "version": "1.4.0",
+            "version_normalized": "1.4.0.0",
             "source": {
                 "type": "git",
                 "url": "https://git.drupalcode.org/project/smtp.git",
-                "reference": "8.x-1.3"
+                "reference": "8.x-1.4"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://ftp.drupal.org/files/projects/smtp-8.x-1.3.zip",
-                "reference": "8.x-1.3",
-                "shasum": "10c766f0a3ce588dc27d6ac2b21255a807be81d8"
+                "url": "https://ftp.drupal.org/files/projects/smtp-8.x-1.4.zip",
+                "reference": "8.x-1.4",
+                "shasum": "963b4670dc609f30a8c003d888d88893d0841b21"
             },
             "require": {
-                "drupal/core": "^10.1 || ^11",
+                "drupal/core": "^9.5 || ^10 || ^11",
                 "phpmailer/phpmailer": "^6.1.7"
             },
             "suggest": {
@@ -6174,8 +6174,8 @@
             "type": "drupal-module",
             "extra": {
                 "drupal": {
-                    "version": "8.x-1.3",
-                    "datestamp": "1719260754",
+                    "version": "8.x-1.4",
+                    "datestamp": "1722032780",
                     "security-coverage": {
                         "status": "covered",
                         "message": "Covered by Drupal's security advisory policy"
diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php
index 1f84133ecb..eb6ef90c0d 100644
--- a/vendor/composer/installed.php
+++ b/vendor/composer/installed.php
@@ -3,7 +3,7 @@
         'name' => 'osu-asc-webservices/d8-upstream',
         'pretty_version' => 'dev-main',
         'version' => 'dev-main',
-        'reference' => 'bec641bc666fdb4858be0249dd6e543751fd123a',
+        'reference' => '90e996e2a8c36c9dde080c24f6b2bed48fb3b271',
         'type' => 'project',
         'install_path' => __DIR__ . '/../../',
         'aliases' => array(),
@@ -1043,9 +1043,9 @@
             'dev_requirement' => false,
         ),
         'drupal/smtp' => array(
-            'pretty_version' => '1.3.0',
-            'version' => '1.3.0.0',
-            'reference' => '8.x-1.3',
+            'pretty_version' => '1.4.0',
+            'version' => '1.4.0.0',
+            'reference' => '8.x-1.4',
             'type' => 'drupal-module',
             'install_path' => __DIR__ . '/../../web/modules/smtp',
             'aliases' => array(),
@@ -1537,7 +1537,7 @@
         'osu-asc-webservices/d8-upstream' => array(
             'pretty_version' => 'dev-main',
             'version' => 'dev-main',
-            'reference' => 'bec641bc666fdb4858be0249dd6e543751fd123a',
+            'reference' => '90e996e2a8c36c9dde080c24f6b2bed48fb3b271',
             'type' => 'project',
             'install_path' => __DIR__ . '/../../',
             'aliases' => array(),
diff --git a/web/modules/smtp/.gitlab-ci.yml b/web/modules/smtp/.gitlab-ci.yml
index 1afaac5b9f..359886f36a 100644
--- a/web/modules/smtp/.gitlab-ci.yml
+++ b/web/modules/smtp/.gitlab-ci.yml
@@ -23,7 +23,10 @@ include:
 # https://git.drupalcode.org/project/gitlab_templates/-/blob/main/includes/include.drupalci.variables.yml
 # Uncomment the lines below if you want to override any of the variables. The following is just an example.
 ################
-# variables:
-#   SKIP_ESLINT: '1'
-#   OPT_IN_TEST_NEXT_MAJOR: '1'
-#   _CURL_TEMPLATES_REF: 'main'
\ No newline at end of file
+variables:
+  SKIP_CSPELL: 1
+  OPT_IN_TEST_PREVIOUS_MAJOR: 1
+  OPT_IN_TEST_PREVIOUS_MINOR: 1
+  OPT_IN_TEST_NEXT_MINOR: 1
+  OPT_IN_TEST_NEXT_MAJOR: 1
+  OPT_IN_TEST_MAX_PHP: 1
diff --git a/web/modules/smtp/config/install/smtp.settings.yml b/web/modules/smtp/config/install/smtp.settings.yml
index 165491b593..bb99963e07 100644
--- a/web/modules/smtp/config/install/smtp.settings.yml
+++ b/web/modules/smtp/config/install/smtp.settings.yml
@@ -11,7 +11,7 @@ smtp_from: ''
 smtp_fromname: ''
 smtp_client_hostname: ''
 smtp_client_helo: ''
-smtp_allowhtml: ''
+smtp_allowhtml: false
 smtp_test_address: ''
 smtp_reroute_address: ''
 smtp_debugging: false
diff --git a/web/modules/smtp/config/schema/smtp.schema.yml b/web/modules/smtp/config/schema/smtp.schema.yml
index 67a4eb8b78..df294648fa 100644
--- a/web/modules/smtp/config/schema/smtp.schema.yml
+++ b/web/modules/smtp/config/schema/smtp.schema.yml
@@ -42,7 +42,7 @@ smtp.settings:
       type: string
       label: 'HELO'
     smtp_allowhtml:
-      type: string
+      type: boolean
       label: 'Allow to send e-mails formated as HTML'
     smtp_test_address:
       type: email
diff --git a/web/modules/smtp/smtp.info.yml b/web/modules/smtp/smtp.info.yml
index 8f1bb2463e..ff941e40d4 100644
--- a/web/modules/smtp/smtp.info.yml
+++ b/web/modules/smtp/smtp.info.yml
@@ -2,10 +2,10 @@ name: SMTP Authentication Support
 description: "Allow for site emails to be sent through an SMTP server of your choice."
 package: Mail
 type: module
-core_version_requirement: ^10.1 || ^11
+core_version_requirement: ^9.5 || ^10 || ^11
 configure: smtp.config
 
-# Information added by Drupal.org packaging script on 2024-06-24
-version: '8.x-1.3'
+# Information added by Drupal.org packaging script on 2024-07-26
+version: '8.x-1.4'
 project: 'smtp'
-datestamp: 1719254620
+datestamp: 1722032782
diff --git a/web/modules/smtp/smtp.install b/web/modules/smtp/smtp.install
index 77231d10cf..0971a4c163 100644
--- a/web/modules/smtp/smtp.install
+++ b/web/modules/smtp/smtp.install
@@ -58,6 +58,15 @@ function smtp_update_8005() {
     ->save(TRUE);
 }
 
+/**
+ * Convert smtp_allowhtml to a boolean.
+ */
+function smtp_update_8006() {
+  $config = \Drupal::configFactory()->getEditable('smtp.settings');
+  $config->set('smtp_allowhtml', (bool) $config->get('smtp_allowhtml'))
+    ->save(TRUE);
+}
+
 /**
  * Implements hook_requirements().
  */
diff --git a/web/modules/smtp/smtp.module b/web/modules/smtp/smtp.module
index 21ca4bd8f1..6712869e1e 100644
--- a/web/modules/smtp/smtp.module
+++ b/web/modules/smtp/smtp.module
@@ -16,7 +16,6 @@
  */
 
 use Drupal\Core\Routing\RouteMatchInterface;
-use Drupal\Core\Url;
 
 /**
  * Implements hook_modules_installed().
diff --git a/web/modules/smtp/smtp.post_update.php b/web/modules/smtp/smtp.post_update.php
index 82ce22097e..6fbbf9f0d0 100644
--- a/web/modules/smtp/smtp.post_update.php
+++ b/web/modules/smtp/smtp.post_update.php
@@ -45,4 +45,4 @@ function smtp_post_update_set_smtp_autotls() {
 function smtp_post_update_connection_typo() {
   // Empty update to cause a cache rebuild so that the service changes are read.
   // Caused by this typo: https://www.drupal.org/project/smtp/issues/3150369
-}
\ No newline at end of file
+}
diff --git a/web/modules/smtp/src/ConnectionTester/ConnectionTester.php b/web/modules/smtp/src/ConnectionTester/ConnectionTester.php
index 8af7d0cd55..554b505221 100644
--- a/web/modules/smtp/src/ConnectionTester/ConnectionTester.php
+++ b/web/modules/smtp/src/ConnectionTester/ConnectionTester.php
@@ -74,6 +74,7 @@ class ConnectionTester {
    * The SMTP ConnectionTester constructor.
    *
    * @param \Drupal\Core\Config\ConfigFactory $config_factory
+   *   The drupal config factory.
    * @param \Psr\Log\LoggerInterface $logger
    *   The logger channel.
    * @param \Drupal\Core\Mail\MailManagerInterface $mail_manager
@@ -92,6 +93,9 @@ public function __construct(ConfigFactory $config_factory, LoggerInterface $logg
     $this->phpMailer = new PHPMailer(TRUE);
   }
 
+  /**
+   * Set the PHPMailer Library class.
+   */
   public function setMailer(PHPMailer $mailer) {
     $this->phpMailer = $mailer;
   }
@@ -108,6 +112,7 @@ public function testConnection() {
 
     $smtp_enabled = $this->smtpConfig->get('smtp_on');
     // Check to see if MailSystem is enabled and is using SMTPMailSystem.
+    // @phpstan-ignore-line
     if (\Drupal::moduleHandler()->moduleExists('mailsystem')) {
       $mailsystem_defaults = (array) $this->configFactory->get('mailsystem.settings')->get('defaults');
       $smtp_enabled = in_array('SMTPMailSystem', $mailsystem_defaults);
diff --git a/web/modules/smtp/src/Form/SMTPConfigForm.php b/web/modules/smtp/src/Form/SMTPConfigForm.php
index 5223eb5eff..476f65d87a 100644
--- a/web/modules/smtp/src/Form/SMTPConfigForm.php
+++ b/web/modules/smtp/src/Form/SMTPConfigForm.php
@@ -2,16 +2,10 @@
 
 namespace Drupal\smtp\Form;
 
-use Drupal\Core\Extension\ModuleHandlerInterface;
-use PHPMailer\PHPMailer\PHPMailer;
-use Drupal\Component\Utility\EmailValidatorInterface;
-use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\Form\ConfigFormBase;
 use Drupal\Core\Form\FormStateInterface;
-use Drupal\Core\Mail\MailManagerInterface;
-use Drupal\Core\Messenger\MessengerInterface;
-use Drupal\Core\Session\AccountProxyInterface;
 use Drupal\Core\Url;
+use PHPMailer\PHPMailer\PHPMailer;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
@@ -54,43 +48,18 @@ class SMTPConfigForm extends ConfigFormBase {
    */
   protected $moduleHandler;
 
-  /**
-   * Constructs $messenger and $config_factory objects.
-   *
-   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
-   *   The factory for configuration objects.
-   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
-   *   The D8 messenger object.
-   * @param \Drupal\Component\Utility\EmailValidatorInterface $email_validator
-   *   The Email Validator Service.
-   * @param \Drupal\Core\Session\AccountProxyInterface $current_user
-   *   The current active user.
-   * @param \Drupal\Core\Mail\MailManagerInterface $mail_manager
-   *   The mail manager service.
-   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
-   *   The module handler service.
-   */
-  public function __construct(ConfigFactoryInterface $config_factory, MessengerInterface $messenger, EmailValidatorInterface $email_validator, AccountProxyInterface $current_user, MailManagerInterface $mail_manager, ModuleHandlerInterface $module_handler) {
-    $this->messenger = $messenger;
-    $this->emailValidator = $email_validator;
-    $this->currentUser = $current_user;
-    $this->mailManager = $mail_manager;
-    $this->moduleHandler = $module_handler;
-    parent::__construct($config_factory);
-  }
-
   /**
    * {@inheritdoc}
    */
   public static function create(ContainerInterface $container) {
-    return new static(
-      $container->get('config.factory'),
-      $container->get('messenger'),
-      $container->get('email.validator'),
-      $container->get('current_user'),
-      $container->get('plugin.manager.mail'),
-      $container->get('module_handler')
-    );
+    $instance = parent::create($container);
+    $instance->messenger = $container->get('messenger');
+    $instance->emailValidator = $container->get('email.validator');
+    $instance->currentUser = $container->get('current_user');
+    $instance->mailManager = $container->get('plugin.manager.mail');
+    $instance->moduleHandler = $container->get('module_handler');
+
+    return $instance;
   }
 
   /**
@@ -121,7 +90,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
     else {
       $this->messenger->addMessage($this->t('SMTP module is INACTIVE.'));
     }
-    // Add Debugging warning
+    // Add Debugging warning.
     if ($config->get('smtp_debugging')) {
       $this->messenger->addWarning($this->t('SMTP debugging is on, ensure it is <a href="#edit-smtp-debugging">disabled</a> before using in production.'));
     }
@@ -289,7 +258,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
       '#title' => $this->t('Hostname'),
       '#default_value' => $config->get('smtp_client_hostname'),
       '#description' => $this->t('The hostname to use in the Message-Id and Received headers, and as the default HELO string. Leave blank for using %server_name.',
-        ['%server_name' => isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain']),
+        ['%server_name' => $_SERVER['SERVER_NAME'] ?? 'localhost.localdomain']),
       '#disabled' => $this->isOverridden('smtp_client_hostname'),
     ];
     $form['client']['smtp_client_helo'] = [
diff --git a/web/modules/smtp/src/Plugin/Mail/SMTPMailSystem.php b/web/modules/smtp/src/Plugin/Mail/SMTPMailSystem.php
index e306a2db02..268ef3e6c0 100644
--- a/web/modules/smtp/src/Plugin/Mail/SMTPMailSystem.php
+++ b/web/modules/smtp/src/Plugin/Mail/SMTPMailSystem.php
@@ -2,24 +2,22 @@
 
 namespace Drupal\smtp\Plugin\Mail;
 
-use Symfony\Component\Mime\Header\UnstructuredHeader;
-use Symfony\Component\Mime\MimeTypeGuesserInterface;
-use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface AS D8MimeTypeGuesserInterface;
 use Drupal\Component\Utility\EmailValidatorInterface;
-use Drupal\Component\Utility\Unicode;
+use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\File\FileSystemInterface;
 use Drupal\Core\Logger\LoggerChannelFactoryInterface;
 use Drupal\Core\Mail\MailFormatHelper;
 use Drupal\Core\Mail\MailInterface;
 use Drupal\Core\Messenger\MessengerInterface;
 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
+use Drupal\Core\Render\RendererInterface;
+use Drupal\Core\Session\AccountProxyInterface;
 use Drupal\Core\StringTranslation\StringTranslationTrait;
 use PHPMailer\PHPMailer\PHPMailer;
 use Symfony\Component\DependencyInjection\ContainerInterface;
-use Drupal\Core\Config\ConfigFactoryInterface;
-use Drupal\Core\Session\AccountProxyInterface;
-use Drupal\Core\Render\RendererInterface;
 use Symfony\Component\HttpFoundation\Session\SessionInterface;
+use Symfony\Component\Mime\Header\UnstructuredHeader;
+use Symfony\Component\Mime\MimeTypeGuesserInterface;
 
 /**
  * Modify the drupal mail system to use smtp when sending emails.
@@ -36,7 +34,19 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
 
   use StringTranslationTrait;
 
+  /**
+   * Flag to allow HTML Formatted email.
+   *
+   * @var bool
+   */
+  // phpcs:ignore
   protected $AllowHtml;
+
+  /**
+   * SMTP Config Object.
+   *
+   * @var \Drupal\Core\Config\ImmutableConfig
+   */
   protected $smtpConfig;
 
   /**
@@ -84,7 +94,7 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
   /**
    * The file mime type guesser service.
    *
-   * @var \Symfony\Component\Mime\MimeTypeGuesserInterface|\Symfony\Component\Mime\MimeTypesInterface
+   * @var \Symfony\Component\Mime\MimeTypeGuesserInterface
    */
   protected $mimeTypeGuesser;
 
@@ -130,25 +140,14 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
    *   The current user service.
    * @param \Drupal\Core\File\FileSystemInterface $file_system
    *   The file system service.
-   * @param \Symfony\Component\Mime\MimeTypeGuesserInterface|\Symfony\Component\Mime\MimeTypesInterface $mime_type_guesser
+   * @param \Symfony\Component\Mime\MimeTypeGuesserInterface $mime_type_guesser
    *   The file mime type guesser service.
    * @param \Drupal\Core\Render\RendererInterface $renderer
    *   The renderer.
    * @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
    *   The session.
    */
-  public function __construct(array $configuration,
-                              $plugin_id,
-                              $plugin_definition,
-                              LoggerChannelFactoryInterface $logger,
-                              MessengerInterface $messenger,
-                              EmailValidatorInterface $emailValidator,
-                              ConfigFactoryInterface $config_factory,
-                              AccountProxyInterface $account,
-                              FileSystemInterface $file_system,
-                              MimeTypeGuesserInterface $mime_type_guesser,
-                              RendererInterface $renderer,
-                              SessionInterface $session) {
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerChannelFactoryInterface $logger, MessengerInterface $messenger, EmailValidatorInterface $emailValidator, ConfigFactoryInterface $config_factory, AccountProxyInterface $account, FileSystemInterface $file_system, MimeTypeGuesserInterface $mime_type_guesser, RendererInterface $renderer, SessionInterface $session) {
     $this->smtpConfig = $config_factory->get('smtp.settings');
     $this->logger = $logger;
     $this->messenger = $messenger;
@@ -207,7 +206,7 @@ public function format(array $message) {
 
     // Join the body array into one string.
     $message['body'] = implode("\n\n", $message['body']);
-    if ($this->AllowHtml == 0) {
+    if (!$this->AllowHtml) {
       // Convert any HTML to plain-text.
       $message['body'] = MailFormatHelper::htmlToText($message['body']);
       // Wrap the mail body for sending.
@@ -297,12 +296,12 @@ public function mail(array $message) {
     }
 
     // If the SMTP module from email has not been provided, use the provided
-    // from email
+    // from email.
     elseif (!empty($message['params']['from_mail'])) {
       $from = $message['params']['from_mail'];
     }
 
-    // Alternative way to set from with email
+    // Alternative way to set from with email.
     elseif (!empty($message['from'])) {
       $from = $message['from'];
     }
@@ -321,15 +320,9 @@ public function mail(array $message) {
 
     // Defines the From value to what we expect.
     $mailer->From = $from;
-    // @todo remove when dropping support for D8 and 9.2.
-    if ($this->mimeTypeGuesser instanceof MimeTypeGuesserInterface) {
-      // phpcs:ignore
-      $mailer->FromName = (new UnstructuredHeader('From', $from_name))->getBodyAsString();
-    }
-    else {
-      // @phpstan-ignore-next-line
-      $mailer->FromName = Unicode::mimeHeaderEncode($from_name);
-    }
+    // phpcs:ignore
+    $mailer->FromName = (new UnstructuredHeader('From', $from_name))->getBodyAsString();
+
     // Sender needs to be set to an email address only to prevent trying to
     // send an email with an invalid sender (where the name is present).
     $mailer->Sender = $from;
@@ -381,11 +374,11 @@ public function mail(array $message) {
 
           // Set the charset based on the provided value,
           // otherwise set it to UTF-8 (which is Drupal's internal default).
-          $mailer->CharSet = isset($vars['charset']) ? $vars['charset'] : 'UTF-8';
+          $mailer->CharSet = $vars['charset'] ?? 'UTF-8';
 
           // If $vars is empty then set an empty value at index 0,
           // to avoid a PHP warning in the next statement.
-          $vars[0] = isset($vars[0]) ? $vars[0] : '';
+          $vars[0] = $vars[0] ?? '';
 
           switch ($vars[0]) {
             case 'text/plain':
@@ -464,7 +457,8 @@ public function mail(array $message) {
           break;
 
         case 'return-path':
-          $mailer->Sender = $value;
+          $sender_comp = $this->getComponents($value);
+          $mailer->Sender = $sender_comp['email'];
           break;
 
         case 'from':
@@ -495,15 +489,8 @@ public function mail(array $message) {
           foreach ($bcc_recipients as $bcc_recipient) {
             $bcc_comp = $this->getComponents($bcc_recipient);
 
-            // @todo remove when dropping support for D8 and 9.2.
-            if ($this->mimeTypeGuesser instanceof MimeTypeGuesserInterface) {
-              // phpcs:ignore
-              $mailer->AddBCC($bcc_comp['email'], (new UnstructuredHeader('BCC', $bcc_comp['name']))->getBodyAsString());
-            }
-            else {
-              // @phpstan-ignore-next-line
-              $mailer->FromName = Unicode::mimeHeaderEncode($from_name);
-            }
+            // phpcs:ignore
+            $mailer->AddBCC($bcc_comp['email'], (new UnstructuredHeader('BCC', $bcc_comp['name']))->getBodyAsString());
           }
           break;
 
@@ -513,19 +500,6 @@ public function mail(array $message) {
       }
     }
 
-    // TODO
-    // Need to figure out the following.
-    //
-    // Add one last header item, but not if it has already been added.
-    // $errors_to = FALSE;
-    // foreach ($mailer->CustomHeader as $custom_header) {
-    //   if ($custom_header[0] = '') {
-    //     $errors_to = TRUE;
-    //   }
-    // }
-    // if ($errors_to) {
-    //   $mailer->AddCustomHeader('Errors-To: '. $from);
-    // }.
     // Add the message's subject.
     $mailer->Subject = $subject;
 
@@ -533,7 +507,7 @@ public function mail(array $message) {
     switch ($content_type) {
       case 'multipart/related':
         $mailer->Body = $body;
-        // TODO: Figure out if there is anything more to handling this type.
+        // @todo Figure out if there is anything more to handling this type.
         break;
 
       case 'multipart/alternative':
@@ -666,14 +640,8 @@ public function mail(array $message) {
               }
 
               $attachment_new_filename = $this->fileSystem->tempnam('temporary://', 'smtp');
-              if (\Drupal::hasService('file.repository')) {
-                // phpcs:ignore
-                $file_path = \Drupal::service('file.repository')->writeData($attachment, $attachment_new_filename, FileSystemInterface::EXISTS_REPLACE);
-              }
-              else {
-                // @phpstan-ignore-next-line
-                $file_path = \Drupal::service('file.repository')->writeData($attachment, $attachment_new_filename, FileSystemInterface::EXISTS_REPLACE);
-              }
+              // phpcs:ignore
+              $file_path = \Drupal::service('file.repository')->writeData($attachment, $attachment_new_filename, FileSystemInterface::EXISTS_REPLACE); // @phpstan-ignore-line
               $real_path = $this->fileSystem->realpath($file_path->uri);
 
               if (!$mailer->addStringAttachment(file_get_contents($real_path), $file_name)) {
@@ -696,8 +664,8 @@ public function mail(array $message) {
         // Support either the attachment being specified as a filepath
         // OR loaded into memory.
         if (isset($attachment['filepath'])) {
-          $filename = isset($attachment['filename']) ? $attachment['filename'] : basename($attachment['filepath']);
-          $filemime = isset($attachment['filemime']) ? $attachment['filemime'] : $this->mimeTypeGuesser->guess($attachment['filepath']);
+          $filename = $attachment['filename'] ?? basename($attachment['filepath']);
+          $filemime = $attachment['filemime'] ?? $this->mimeTypeGuesser->guessMimeType($attachment['filepath']);
           $mailer->addStringAttachment(file_get_contents($attachment['filepath']), $filename, 'base64', $filemime);
         }
         elseif (isset($attachment['filecontent'])) {
@@ -953,6 +921,7 @@ protected function applyRerouting($to, array $headers) {
    * Get (and, if applicable, build) the PHPMailer object.
    *
    * @return \PHPMailer\PHPMailer\PHPMailer
+   *   The PHPMailer Library.
    */
   protected function getMailer() {
     if ($this->smtpConfig->get('smtp_keepalive')) {
diff --git a/web/modules/smtp/tests/src/Kernel/ConnectionTester/ConnectionTesterTest.php b/web/modules/smtp/tests/src/Kernel/ConnectionTester/ConnectionTesterTest.php
index 0f3383cbd3..512d9a9ba7 100644
--- a/web/modules/smtp/tests/src/Kernel/ConnectionTester/ConnectionTesterTest.php
+++ b/web/modules/smtp/tests/src/Kernel/ConnectionTester/ConnectionTesterTest.php
@@ -14,6 +14,9 @@
  */
 class ConnectionTesterTest extends KernelTestBase {
 
+  /**
+   * {@inheritdoc}
+   */
   protected static $modules = [
     'smtp',
   ];
@@ -65,7 +68,7 @@ public static function providerHookRequirements() {
     return [
       [
         'message' => 'SMTP on, working.',
-        '$smtp_on' => TRUE,
+        'smtp_on' => TRUE,
         'result' => TRUE,
         'exception' => '',
         'expected' => [
@@ -78,7 +81,7 @@ public static function providerHookRequirements() {
       ],
       [
         'message' => 'SMTP on, result FALSE.',
-        '$smtp_on' => TRUE,
+        'smtp_on' => TRUE,
         'result' => FALSE,
         'exception' => '',
         'expected' => [
@@ -91,7 +94,7 @@ public static function providerHookRequirements() {
       ],
       [
         'message' => 'SMTP on, PHPMailerException.',
-        '$smtp_on' => TRUE,
+        'smtp_on' => TRUE,
         'result' => FALSE,
         'exception' => PHPMailerException::class,
         'expected' => [
@@ -104,7 +107,7 @@ public static function providerHookRequirements() {
       ],
       [
         'message' => 'SMTP on, Exception.',
-        '$smtp_on' => TRUE,
+        'smtp_on' => TRUE,
         'result' => FALSE,
         'exception' => \Exception::class,
         'expected' => [
@@ -117,7 +120,7 @@ public static function providerHookRequirements() {
       ],
       [
         'message' => 'SMTP off.',
-        '$smtp_on' => FALSE,
+        'smtp_on' => FALSE,
         'result' => FALSE,
         'exception' => '',
         'expected' => [
@@ -134,14 +137,16 @@ public static function providerHookRequirements() {
   /**
    * Create a mock PHPMailer class for testing the exceptions.
    *
-   * @param $result
+   * @param bool $result
    *   Expected Result.
-   * @param $exception
+   * @param string $exception
    *   Exception passed in.
    *
-   * @return \PHPMailer\PHPMailer\PHPMailer|__anonymous@4029
+   * @return \PHPMailer\PHPMailer\PHPMailer
+   *   The PHPMailer library.
    */
   private function getMockMailer($result, $exception) {
+
     $class = new class($result, $exception) extends PHPMailer {
 
       public function __construct($result, $exception) {
@@ -159,6 +164,7 @@ public function smtpConnect($options = NULL) {
         }
         return $this->result;
       }
+
     };
     return $class;
   }
diff --git a/web/modules/smtp/tests/src/Kernel/MigrateD7SettingsTest.php b/web/modules/smtp/tests/src/Kernel/MigrateD7SettingsTest.php
index 6c6426c9b8..ae136f592c 100644
--- a/web/modules/smtp/tests/src/Kernel/MigrateD7SettingsTest.php
+++ b/web/modules/smtp/tests/src/Kernel/MigrateD7SettingsTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\Core\Database\Database;
 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
+use Drupal\Tests\RandomGeneratorTrait;
 
 /**
  * Tests migration of smtp settings.
@@ -12,6 +13,8 @@
  */
 class MigrateD7SettingsTest extends MigrateDrupal7TestBase {
 
+  use RandomGeneratorTrait;
+
   /**
    * The migration this test is testing.
    *
@@ -83,7 +86,8 @@ public function testMigrateSettings() {
 
     // Validate the D7 variable values made it into the destination structure.
     $destConfig = $this->config('smtp.settings');
-    $this->assertSame($allowHtml, $destConfig->get('smtp_allowhtml'));
+    // Validate smtp_allowhtml was transformed into a boolean.
+    $this->assertSame((bool) $allowHtml, $destConfig->get('smtp_allowhtml'));
     $this->assertSame($clientHelo, $destConfig->get('smtp_client_helo'));
     $this->assertSame($clientHostname, $destConfig->get('smtp_client_hostname'));
     $this->assertSame($debugging, $destConfig->get('smtp_debugging'));
@@ -100,10 +104,10 @@ public function testMigrateSettings() {
     $this->assertSame($username, $destConfig->get('smtp_username'));
 
     // Validate default_value migrations.
-    $this->assertSame(TRUE, $destConfig->get('smtp_autotls'));
+    $this->assertTrue($destConfig->get('smtp_autotls'));
     $this->assertSame(10, $destConfig->get('smtp_timeout'));
     $this->assertSame('php_mail', $destConfig->get('prev_mail_system'));
-    $this->assertSame(FALSE, $destConfig->get('smtp_keepalive'));
+    $this->assertFalse($destConfig->get('smtp_keepalive'));
   }
 
   /**
@@ -113,7 +117,7 @@ public function testMigrateSettings() {
    *   A random email address at a random hostname.
    */
   protected function randomEmail() {
-    return sprintf('%s@%s', $this->randomGenerator->word(8), $this->randomHostname());
+    return sprintf('%s@%s', $this->getRandomGenerator()->word(8), $this->randomHostname());
   }
 
   /**
diff --git a/web/modules/smtp/tests/src/Unit/Plugin/Mail/SMTPMailSystemTest.php b/web/modules/smtp/tests/src/Unit/Plugin/Mail/SMTPMailSystemTest.php
index 0da993d1a7..66d875e566 100644
--- a/web/modules/smtp/tests/src/Unit/Plugin/Mail/SMTPMailSystemTest.php
+++ b/web/modules/smtp/tests/src/Unit/Plugin/Mail/SMTPMailSystemTest.php
@@ -2,27 +2,27 @@
 
 namespace Drupal\Tests\smtp\Unit\Plugin\Mail;
 
-use Drupal\Core\File\FileSystemInterface;
-use Drupal\Core\Session\AccountProxyInterface;
-use Prophecy\PhpUnit\ProphecyTrait;
 use Drupal\Component\Utility\EmailValidator;
 use Drupal\Component\Utility\EmailValidatorInterface;
 use Drupal\Core\File\FileSystem;
+use Drupal\Core\File\FileSystemInterface;
 use Drupal\Core\File\MimeType\MimeTypeGuesser;
 use Drupal\Core\Logger\LoggerChannelFactoryInterface;
 use Drupal\Core\Logger\LoggerChannelInterface;
 use Drupal\Core\Messenger\MessengerInterface;
+use Drupal\Core\Render\RendererInterface;
 use Drupal\Core\Session\AccountProxy;
+use Drupal\Core\Session\AccountProxyInterface;
 use Drupal\Core\StringTranslation\TranslationInterface;
 use Drupal\smtp\Plugin\Mail\SMTPMailSystem;
 use Drupal\Tests\UnitTestCase;
-use PHPMailer\PHPMailer\PHPMailer;
 use PHPMailer\PHPMailer\Exception as PHPMailerException;
+use PHPMailer\PHPMailer\PHPMailer;
 use Prophecy\Argument;
+use Prophecy\PhpUnit\ProphecyTrait;
 use Symfony\Component\DependencyInjection\ContainerInterface;
-use Symfony\Component\Mime\MimeTypeGuesserInterface;
-use Drupal\Core\Render\RendererInterface;
 use Symfony\Component\HttpFoundation\Session\SessionInterface;
+use Symfony\Component\Mime\MimeTypeGuesserInterface;
 
 /**
  * Validate requirements for SMTPMailSystem.
@@ -372,7 +372,7 @@ public function testMailHeader() {
   /**
    * Tests #3308653 and duplicated headers.
    */
-  public function testFromHeaders_3308653() {
+  public function testFromHeaders3308653() {
     $mailer = new class (
       [],
       'SMTPMailSystem',
@@ -413,6 +413,7 @@ protected function getMailer() {
            * @return array
            *   The MIMEHeader as an array.
            */
+          //phpcs:ignore
           public function getMIMEHeaders() {
             return array_filter(explode(static::$LE, $this->MIMEHeader));
           }
diff --git a/web/modules/smtp/tests/src/Unit/SMTPConfigFormTest.php b/web/modules/smtp/tests/src/Unit/SMTPConfigFormTest.php
index ed60a08391..9db3ffdbad 100644
--- a/web/modules/smtp/tests/src/Unit/SMTPConfigFormTest.php
+++ b/web/modules/smtp/tests/src/Unit/SMTPConfigFormTest.php
@@ -2,10 +2,10 @@
 
 namespace Drupal\Tests\smtp\Unit;
 
-use Prophecy\PhpUnit\ProphecyTrait;
 use Drupal\Component\Utility\EmailValidatorInterface;
 use Drupal\Core\Config\Config;
 use Drupal\Core\Config\ConfigFactoryInterface;
+use Drupal\Core\Config\TypedConfigManagerInterface;
 use Drupal\Core\Extension\ModuleHandlerInterface;
 use Drupal\Core\Form\FormState;
 use Drupal\Core\Mail\MailManagerInterface;
@@ -15,6 +15,7 @@
 use Drupal\smtp\Form\SMTPConfigForm;
 use Drupal\Tests\UnitTestCase;
 use Prophecy\Argument;
+use Prophecy\PhpUnit\ProphecyTrait;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
@@ -25,6 +26,7 @@
 class SMTPConfigFormTest extends UnitTestCase {
 
   use ProphecyTrait;
+
   /**
    * Test setup.
    */
@@ -39,6 +41,7 @@ public function setup(): void {
     $this->mockConfigSystemSite->get('name')->willReturn('Site name');
     $this->mockConfigFactory->get('system.site')->willReturn($this->mockConfigSystemSite->reveal());
 
+    $this->mockTypedConfigManager = $this->prophesize(TypedConfigManagerInterface::class);
     $this->mockMessenger = $this->prophesize(MessengerInterface::class);
     $this->mockEmailValidator = $this->prophesize(EmailValidatorInterface::class);
     $this->mockCurrentUser = $this->prophesize(AccountProxyInterface::class);
@@ -47,6 +50,7 @@ public function setup(): void {
 
     $mockContainer = $this->mockContainer = $this->prophesize(ContainerInterface::class);
     $mockContainer->get('config.factory')->willReturn($this->mockConfigFactory->reveal());
+    $mockContainer->get('config.typed')->willReturn($this->mockTypedConfigManager->reveal());
     $mockContainer->get('messenger')->willReturn($this->mockMessenger->reveal());
     $mockContainer->get('email.validator')->willReturn($this->mockEmailValidator->reveal());
     $mockContainer->get('current_user')->willReturn($this->mockCurrentUser->reveal());
@@ -77,7 +81,7 @@ public function setDefaultConfig() {
     $this->mockConfig->get('smtp_password')->willReturn('');
     $this->mockConfig->get('smtp_from')->willReturn('');
     $this->mockConfig->get('smtp_fromname')->willReturn('');
-    $this->mockConfig->get('smtp_allowhtml')->willReturn('');
+    $this->mockConfig->get('smtp_allowhtml')->willReturn(FALSE);
     $this->mockConfig->get('smtp_client_hostname')->willReturn('');
     $this->mockConfig->get('smtp_client_helo')->willReturn('');
     $this->mockConfig->get('smtp_debugging')->willReturn('');
-- 
GitLab