Skip to content

Commit

Permalink
Merge pull request #5851 from Automattic/staging
Browse files Browse the repository at this point in the history
Production release v20240910.0
  • Loading branch information
rebeccahum authored Sep 10, 2024
2 parents 25d0e09 + 7902a38 commit a9be98e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
34 changes: 34 additions & 0 deletions tests/test-vip-mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,40 @@ public function test_smtp_servers_not_overwritten(): void {
self::assertEquals( $expected, $mailer->Host );
}

public function test_smtp_servers_not_overwritten_when_not_present_in_host_overwrite_allow_list(): void {
Constant_Mocker::define( 'VIP_SMTP_HOST_OVERWRITE_ALLOW_LIST', 'server1,not-preset-server,server2' );

$GLOBALS['all_smtp_servers'] = [ 'server1', 'server2' ];

$expected = 'preset-server';

add_action( 'phpmailer_init', function ( PHPMailer &$phpmailer ) use ( $expected ) {
$phpmailer->isSMTP();
$phpmailer->Host = $expected;
} );

wp_mail( 'test@example.com', 'Test', 'Test' );
$mailer = tests_retrieve_phpmailer_instance();

self::assertEquals( $expected, $mailer->Host );
}

public function test_smtp_servers_are_overwritten_when_present_in_host_overwrite_allow_list(): void {
Constant_Mocker::define( 'VIP_SMTP_HOST_OVERWRITE_ALLOW_LIST', 'server1,overwritable-host,server2' );

$GLOBALS['all_smtp_servers'] = [ 'new-host' ];

add_action( 'phpmailer_init', function ( PHPMailer &$phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = 'overwritable-host';
} );

wp_mail( 'test@example.com', 'Test', 'Test' );
$mailer = tests_retrieve_phpmailer_instance();

self::assertEquals( 'new-host', $mailer->Host );
}

/**
* @ticket GH-3638
*/
Expand Down
6 changes: 5 additions & 1 deletion vip-mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ public function phpmailer_init( &$phpmailer ): void {
return;
}

if ( 'smtp' === $phpmailer->Mailer ) {
$host_overwrite_allow_list = defined( 'VIP_SMTP_HOST_OVERWRITE_ALLOW_LIST' )
? array_map( 'trim', explode( ',', constant( 'VIP_SMTP_HOST_OVERWRITE_ALLOW_LIST' ) ) )
: [];

if ( 'smtp' === $phpmailer->Mailer && ! in_array( $phpmailer->Host, $host_overwrite_allow_list, true ) ) {
return;
}

Expand Down

0 comments on commit a9be98e

Please sign in to comment.