Loading reroute_email.info.yml +1 −0 Original line number Diff line number Diff line Loading @@ -2,5 +2,6 @@ name: 'Reroute emails' description: 'Reroutes emails send from the site to a predefined email. Useful for test sites.' package: Development core: 8.x core_version_requirement: ^8 || ^9 configure: reroute_email.settings type: module reroute_email.module +2 −3 Original line number Diff line number Diff line Loading @@ -8,7 +8,6 @@ use Drupal\Core\StringTranslation\TranslatableMarkup; use Egulias\EmailValidator\EmailParser; use Egulias\EmailValidator\EmailLexer; use Drupal\Component\Utility\Unicode; define('REROUTE_EMAIL_ENABLE', 'enable'); define('REROUTE_EMAIL_ADDRESS', 'address'); Loading Loading @@ -231,7 +230,7 @@ function reroute_email_check(array &$message) { // The part after the @ sign is the domain and according to RFC 1035, // section 3.1: "Name servers and resolvers must compare [domains] in a // case-insensitive manner". $domain = Unicode::strtolower($matches[1]); $domain = mb_strtolower($matches[1]); $whitelisted_domains[$domain] = $domain; unset($whitelisted_addresses[$key]); Loading @@ -249,7 +248,7 @@ function reroute_email_check(array &$message) { } // Check whitelisted emails and domains. $domain = Unicode::strtolower((new EmailParser(new EmailLexer()))->parse($email)['domain']); $domain = mb_strtolower((new EmailParser(new EmailLexer()))->parse($email)['domain']); if (in_array($email, $whitelisted_addresses, TRUE) || in_array($domain, $whitelisted_domains, TRUE)) { continue; Loading tests/modules/reroute_email_test/reroute_email_test.info.yml +1 −0 Original line number Diff line number Diff line name: 'Reroute Email Test' description: 'Helper module for the reroute email tests.' core: 8.x core_version_requirement: ^8 || ^9 package: Testing hidden: true type: module tests/src/Functional/RerouteEmailTestBase.php +6 −1 Original line number Diff line number Diff line Loading @@ -36,6 +36,11 @@ abstract class RerouteEmailTestBase extends BrowserTestBase { */ public static $modules = ['reroute_email']; /** * {@inheritdoc} */ protected $defaultTheme = 'stark'; /** * User object to perform site browsing. * Loading Loading @@ -157,7 +162,7 @@ abstract class RerouteEmailTestBase extends BrowserTestBase { // Search in $mailbody for "Originally to: $original_destination". $mail_body = end($mails)['body']; $search_for = t('Originally to: @to', ['@to' => $original_destination]); $has_info = preg_match("/{$search_for}/", $mail_body); $has_info = (bool) preg_match("/{$search_for}/", $mail_body); // Asserts whether searched text was found. $this->assertTrue($has_info, 'Found the correct "Originally to" line in the body.'); Loading tests/src/Functional/TestEmailFormTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ class TestEmailFormTest extends RerouteEmailTestBase { 'bcc' => t('Originally bcc: @bcc', ['@bcc' => $mail['headers']['X-Rerouted-Original-Bcc']]), ]; foreach ($copy_headers as $header => $message_line) { $has_header = preg_match("/{$message_line}/", $mail['body']); $has_header = (bool) preg_match("/{$message_line}/", $mail['body']); $this->assertTrue($has_header, new FormattableMarkup('Found the correct "@header" line in the body.', ['@header' => $header])); } Loading Loading
reroute_email.info.yml +1 −0 Original line number Diff line number Diff line Loading @@ -2,5 +2,6 @@ name: 'Reroute emails' description: 'Reroutes emails send from the site to a predefined email. Useful for test sites.' package: Development core: 8.x core_version_requirement: ^8 || ^9 configure: reroute_email.settings type: module
reroute_email.module +2 −3 Original line number Diff line number Diff line Loading @@ -8,7 +8,6 @@ use Drupal\Core\StringTranslation\TranslatableMarkup; use Egulias\EmailValidator\EmailParser; use Egulias\EmailValidator\EmailLexer; use Drupal\Component\Utility\Unicode; define('REROUTE_EMAIL_ENABLE', 'enable'); define('REROUTE_EMAIL_ADDRESS', 'address'); Loading Loading @@ -231,7 +230,7 @@ function reroute_email_check(array &$message) { // The part after the @ sign is the domain and according to RFC 1035, // section 3.1: "Name servers and resolvers must compare [domains] in a // case-insensitive manner". $domain = Unicode::strtolower($matches[1]); $domain = mb_strtolower($matches[1]); $whitelisted_domains[$domain] = $domain; unset($whitelisted_addresses[$key]); Loading @@ -249,7 +248,7 @@ function reroute_email_check(array &$message) { } // Check whitelisted emails and domains. $domain = Unicode::strtolower((new EmailParser(new EmailLexer()))->parse($email)['domain']); $domain = mb_strtolower((new EmailParser(new EmailLexer()))->parse($email)['domain']); if (in_array($email, $whitelisted_addresses, TRUE) || in_array($domain, $whitelisted_domains, TRUE)) { continue; Loading
tests/modules/reroute_email_test/reroute_email_test.info.yml +1 −0 Original line number Diff line number Diff line name: 'Reroute Email Test' description: 'Helper module for the reroute email tests.' core: 8.x core_version_requirement: ^8 || ^9 package: Testing hidden: true type: module
tests/src/Functional/RerouteEmailTestBase.php +6 −1 Original line number Diff line number Diff line Loading @@ -36,6 +36,11 @@ abstract class RerouteEmailTestBase extends BrowserTestBase { */ public static $modules = ['reroute_email']; /** * {@inheritdoc} */ protected $defaultTheme = 'stark'; /** * User object to perform site browsing. * Loading Loading @@ -157,7 +162,7 @@ abstract class RerouteEmailTestBase extends BrowserTestBase { // Search in $mailbody for "Originally to: $original_destination". $mail_body = end($mails)['body']; $search_for = t('Originally to: @to', ['@to' => $original_destination]); $has_info = preg_match("/{$search_for}/", $mail_body); $has_info = (bool) preg_match("/{$search_for}/", $mail_body); // Asserts whether searched text was found. $this->assertTrue($has_info, 'Found the correct "Originally to" line in the body.'); Loading
tests/src/Functional/TestEmailFormTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ class TestEmailFormTest extends RerouteEmailTestBase { 'bcc' => t('Originally bcc: @bcc', ['@bcc' => $mail['headers']['X-Rerouted-Original-Bcc']]), ]; foreach ($copy_headers as $header => $message_line) { $has_header = preg_match("/{$message_line}/", $mail['body']); $has_header = (bool) preg_match("/{$message_line}/", $mail['body']); $this->assertTrue($has_header, new FormattableMarkup('Found the correct "@header" line in the body.', ['@header' => $header])); } Loading