v2.1.9
This commit is contained in:
parent
476389b914
commit
25dd2146b1
10 changed files with 286 additions and 231 deletions
|
|
@ -382,8 +382,10 @@ class Plugin {
|
|||
}
|
||||
|
||||
foreach ( $mail_context['to'] as $recipient ) {
|
||||
list( $recipient_address, $recipient_name ) = self::split_name_and_address( $recipient );
|
||||
|
||||
try {
|
||||
$phpmailer->addAddress( $recipient );
|
||||
$phpmailer->addAddress( $recipient_address, $recipient_name );
|
||||
} catch ( PHPMailerException $exception ) {
|
||||
return new WP_Error(
|
||||
'robotstxt_smtp_amazon_ses_invalid_recipient',
|
||||
|
|
@ -404,8 +406,10 @@ class Plugin {
|
|||
}
|
||||
|
||||
foreach ( $parsed_headers['cc'] ?? array() as $cc ) {
|
||||
list( $cc_address, $cc_name ) = self::split_name_and_address( $cc );
|
||||
|
||||
try {
|
||||
$phpmailer->addCC( $cc );
|
||||
$phpmailer->addCC( $cc_address, $cc_name );
|
||||
} catch ( PHPMailerException $exception ) {
|
||||
return new WP_Error(
|
||||
'robotstxt_smtp_amazon_ses_invalid_cc',
|
||||
|
|
@ -426,8 +430,10 @@ class Plugin {
|
|||
}
|
||||
|
||||
foreach ( $parsed_headers['bcc'] ?? array() as $bcc ) {
|
||||
list( $bcc_address, $bcc_name ) = self::split_name_and_address( $bcc );
|
||||
|
||||
try {
|
||||
$phpmailer->addBCC( $bcc );
|
||||
$phpmailer->addBCC( $bcc_address, $bcc_name );
|
||||
} catch ( PHPMailerException $exception ) {
|
||||
return new WP_Error(
|
||||
'robotstxt_smtp_amazon_ses_invalid_bcc',
|
||||
|
|
@ -448,8 +454,10 @@ class Plugin {
|
|||
}
|
||||
|
||||
foreach ( $parsed_headers['reply_to'] ?? array() as $reply_to ) {
|
||||
list( $reply_to_address, $reply_to_name ) = self::split_name_and_address( $reply_to );
|
||||
|
||||
try {
|
||||
$phpmailer->addReplyTo( $reply_to );
|
||||
$phpmailer->addReplyTo( $reply_to_address, $reply_to_name );
|
||||
} catch ( PHPMailerException $exception ) {
|
||||
return new WP_Error(
|
||||
'robotstxt_smtp_amazon_ses_invalid_reply_to',
|
||||
|
|
@ -748,12 +756,41 @@ class Plugin {
|
|||
}
|
||||
|
||||
/**
|
||||
* Ensures the attachments argument is converted into an array of paths.
|
||||
* Splits a recipient string into an email address and an optional display name.
|
||||
*
|
||||
* @param mixed $attachments Attachment data supplied to wp_mail().
|
||||
* Callers such as wp_mail() may supply addresses in the combined
|
||||
* "Name <email@example.com>" form. PHPMailer expects the address and the
|
||||
* display name as separate arguments, so they must be split first.
|
||||
*
|
||||
* @return array<int, string>
|
||||
* @since 2.1.9
|
||||
*
|
||||
* @param string $recipient Recipient as supplied to wp_mail().
|
||||
* @return array{0: string, 1: string} Email address and display name (empty string when absent).
|
||||
*/
|
||||
public static function split_name_and_address( string $recipient ): array {
|
||||
$recipient = trim( $recipient );
|
||||
|
||||
if ( preg_match( '/^(.*)<([^>]+)>$/s', $recipient, $matches ) ) {
|
||||
$name = trim( (string) preg_replace( '/\s+/', ' ', $matches[1] ) );
|
||||
$address = trim( $matches[2] );
|
||||
|
||||
if ( strlen( $name ) > 1 && '"' === $name[0] && '"' === substr( $name, -1 ) ) {
|
||||
$name = substr( $name, 1, -1 );
|
||||
}
|
||||
|
||||
return array( $address, $name );
|
||||
}
|
||||
|
||||
return array( $recipient, '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the attachments argument is converted into an array of paths.
|
||||
*
|
||||
* @param mixed $attachments Attachment data supplied to wp_mail().
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function normalize_attachments( $attachments ): array {
|
||||
if ( empty( $attachments ) ) {
|
||||
return array();
|
||||
|
|
|
|||
Loading…
Reference in a new issue