mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Mail: Improve handling of UTF-8 address headers.
Previously, `wp_mail()` implemented Reply-To as a generic header, using PHPMailer's `addCustomHeader()`. As such, the email address portion of the header was being incorrectly encoded when the name portion contained UTF-8 characters. Switching to PHPMailer's more specific `addReplyTo()` method fixes the issue. For greater readability, the handling of all address-related headers (To, CC, BCC, Reply-To) has been standardized. Props szepe.viktor, iandunn, bpetty, stephenharris. Fixes #21659. git-svn-id: https://develop.svn.wordpress.org/trunk@38058 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -17,7 +17,7 @@ class MockPHPMailer extends PHPMailer {
|
||||
'to' => $this->to,
|
||||
'cc' => $this->cc,
|
||||
'bcc' => $this->bcc,
|
||||
'header' => $this->MIMEHeader,
|
||||
'header' => $this->MIMEHeader . $this->mailHeader,
|
||||
'subject' => $this->Subject,
|
||||
'body' => $this->MIMEBody,
|
||||
);
|
||||
|
||||
@@ -307,4 +307,39 @@ class Tests_Mail extends WP_UnitTestCase {
|
||||
|
||||
$this->assertNotContains( 'quoted-printable', $GLOBALS['phpmailer']->mock_sent[0]['header'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 21659
|
||||
*/
|
||||
public function test_wp_mail_addresses_arent_encoded() {
|
||||
$to = 'Lukáš To <to@example.org>';
|
||||
$subject = 'Testing #21659';
|
||||
$message = 'Only the name should be encoded, not the address.';
|
||||
|
||||
$headers = array(
|
||||
'From' => 'From: Lukáš From <from@example.org>',
|
||||
'Cc' => 'Cc: Lukáš CC <cc@example.org>',
|
||||
'Bcc' => 'Bcc: Lukáš BCC <bcc@example.org>',
|
||||
'Reply-To' => 'Reply-To: Lukáš Reply-To <reply_to@example.org>',
|
||||
);
|
||||
|
||||
$expected = array(
|
||||
'To' => 'To: =?UTF-8?B?THVrw6HFoSBUbw==?= <to@example.org>',
|
||||
'From' => 'From: =?UTF-8?Q?Luk=C3=A1=C5=A1_From?= <from@example.org>',
|
||||
'Cc' => 'Cc: =?UTF-8?B?THVrw6HFoSBDQw==?= <cc@example.org>',
|
||||
'Bcc' => 'Bcc: =?UTF-8?B?THVrw6HFoSBCQ0M=?= <bcc@example.org>',
|
||||
'Reply-To' => 'Reply-To: =?UTF-8?Q?Luk=C3=A1=C5=A1_Reply-To?= <reply_to@example.org>',
|
||||
);
|
||||
|
||||
wp_mail( $to, $subject, $message, array_values( $headers ) );
|
||||
|
||||
$mailer = tests_retrieve_phpmailer_instance();
|
||||
$sent_headers = preg_split( "/\r\n|\n|\r/", $mailer->get_sent()->header );
|
||||
$headers['To'] = "To: $to";
|
||||
|
||||
foreach ( $headers as $header => $value ) {
|
||||
$target_headers = preg_grep( "/^$header:/", $sent_headers );
|
||||
$this->assertEquals( $expected[ $header ], array_pop( $target_headers ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user