Update mailer logic (#34659)

This commit is contained in:
Roy Ho 2022-09-13 15:32:35 -07:00 committed by GitHub
parent 3e85dde082
commit 12af191888
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -0,0 +1,3 @@
Significance: patch
Type: tweak
Comment: No changelog needed, simple logic clean up.

View File

@ -265,12 +265,19 @@ class WC_Email extends WC_Settings_API {
* @return PHPMailer * @return PHPMailer
*/ */
public function handle_multipart( $mailer ) { public function handle_multipart( $mailer ) {
if ( $this->sending && 'multipart' === $this->get_email_type() ) { if ( ! $this->sending ) {
return $mailer;
}
if ( 'multipart' === $this->get_email_type() ) {
$mailer->AltBody = wordwrap( // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $mailer->AltBody = wordwrap( // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
preg_replace( $this->plain_search, $this->plain_replace, wp_strip_all_tags( $this->get_content_plain() ) ) preg_replace( $this->plain_search, $this->plain_replace, wp_strip_all_tags( $this->get_content_plain() ) )
); );
$this->sending = false; } else {
$mailer->AltBody = ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
} }
$this->sending = false;
return $mailer; return $mailer;
} }
@ -686,6 +693,9 @@ class WC_Email extends WC_Settings_API {
remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );
// Clear the AltBody (if set) so that it does not leak across to different emails.
$this->clear_alt_body_field();
/** /**
* Action hook fired when an email is sent. * Action hook fired when an email is sent.
* *
@ -1117,4 +1127,15 @@ class WC_Email extends WC_Settings_API {
); );
} }
} }
/**
* Clears the PhpMailer AltBody field, to prevent that content from leaking across emails.
*/
private function clear_alt_body_field(): void {
global $phpmailer;
if ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer ) {
$phpmailer->AltBody = ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
}
}
} }