Update mailer logic (#34659)
This commit is contained in:
parent
3e85dde082
commit
12af191888
|
@ -0,0 +1,3 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: tweak
|
||||||
|
Comment: No changelog needed, simple logic clean up.
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue