diff --git src/wp-includes/pluggable.php src/wp-includes/pluggable.php
index cb06297b57..79078b8be6 100644
|
|
if ( ! function_exists( 'wp_mail' ) ) : |
453 | 453 | */ |
454 | 454 | $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset ); |
455 | 455 | |
| 456 | /** |
| 457 | * Filters the default wp_mail() encoding. |
| 458 | * |
| 459 | * @since 5.0.0 |
| 460 | * |
| 461 | * @param string $encoding Default email encoding. |
| 462 | */ |
| 463 | $phpmailer->Encoding = apply_filters( 'wp_mail_encoding', 'base64' ); |
| 464 | |
456 | 465 | // Set custom headers |
457 | 466 | if ( ! empty( $headers ) ) { |
458 | 467 | foreach ( (array) $headers as $name => $content ) { |
diff --git tests/phpunit/includes/mock-mailer.php tests/phpunit/includes/mock-mailer.php
index ece2aa3640..8dcf3e2a08 100644
|
|
class MockPHPMailer extends PHPMailer { |
5 | 5 | var $mock_sent = array(); |
6 | 6 | |
7 | 7 | function preSend() { |
8 | | $this->Encoding = '8bit'; |
9 | 8 | return parent::preSend(); |
10 | 9 | } |
11 | 10 | |
diff --git tests/phpunit/tests/mail.php tests/phpunit/tests/mail.php
index 951615136b..ab79f29fea 100644
|
|
class Tests_Mail extends WP_UnitTestCase { |
80 | 80 | $mailer = tests_retrieve_phpmailer_instance(); |
81 | 81 | |
82 | 82 | // We need some better assertions here but these catch the failure for now. |
83 | | $this->assertEquals( $body, $mailer->get_sent()->body ); |
| 83 | $this->assertEquals( $body, base64_decode( $mailer->get_sent()->body ) ); |
84 | 84 | $this->assertTrue( strpos( $mailer->get_sent()->header, 'boundary="----=_Part_4892_25692638.1192452070893"' ) > 0 ); |
85 | 85 | $this->assertTrue( strpos( $mailer->get_sent()->header, 'charset=' ) > 0 ); |
86 | 86 | } |
… |
… |
class Tests_Mail extends WP_UnitTestCase { |
112 | 112 | $this->assertEquals( 'The Carbon Guy', $mailer->get_recipient( 'cc' )->name ); |
113 | 113 | $this->assertEquals( 'bcc@bcc.com', $mailer->get_recipient( 'bcc' )->address ); |
114 | 114 | $this->assertEquals( 'The Blind Carbon Guy', $mailer->get_recipient( 'bcc' )->name ); |
115 | | $this->assertEquals( $message . "\n", $mailer->get_sent()->body ); |
| 115 | $this->assertEquals( $message, base64_decode( $mailer->get_sent()->body ) ); |
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
… |
… |
class Tests_Mail extends WP_UnitTestCase { |
132 | 132 | $this->assertEquals( 'Name', $mailer->get_recipient( 'to' )->name ); |
133 | 133 | $this->assertEquals( 'another_address@different-tld.com', $mailer->get_recipient( 'to', 0, 1 )->address ); |
134 | 134 | $this->assertEquals( 'Another Name', $mailer->get_recipient( 'to', 0, 1 )->name ); |
135 | | $this->assertEquals( $message . "\n", $mailer->get_sent()->body ); |
| 135 | $this->assertEquals( $message, base64_decode( $mailer->get_sent()->body ) ); |
136 | 136 | } |
137 | 137 | |
138 | 138 | function test_wp_mail_multiple_to_addresses() { |
… |
… |
class Tests_Mail extends WP_UnitTestCase { |
145 | 145 | $mailer = tests_retrieve_phpmailer_instance(); |
146 | 146 | $this->assertEquals( 'address@tld.com', $mailer->get_recipient( 'to' )->address ); |
147 | 147 | $this->assertEquals( 'another_address@different-tld.com', $mailer->get_recipient( 'to', 0, 1 )->address ); |
148 | | $this->assertEquals( $message . "\n", $mailer->get_sent()->body ); |
| 148 | $this->assertEquals( $message, base64_decode( $mailer->get_sent()->body ) ); |
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
… |
… |
class Tests_Mail extends WP_UnitTestCase { |
160 | 160 | |
161 | 161 | $mailer = tests_retrieve_phpmailer_instance(); |
162 | 162 | $this->assertEquals( 'address@tld.com', $mailer->get_recipient( 'to' )->address ); |
163 | | $this->assertEquals( $message . "\n", $mailer->get_sent()->body ); |
| 163 | $this->assertEquals( $message, base64_decode( $mailer->get_sent()->body ) ); |
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
… |
… |
class Tests_Mail extends WP_UnitTestCase { |
391 | 391 | $this->assertEquals( 'wp_mail_failed', $call_args[0]->get_error_code() ); |
392 | 392 | $this->assertEquals( $expected_error_data, $call_args[0]->get_error_data() ); |
393 | 393 | } |
| 394 | |
| 395 | /** |
| 396 | * @ticket 44548 |
| 397 | */ |
| 398 | public function test_wp_mail_should_encode_base64_with_japanese() |
| 399 | { |
| 400 | $to = 'hello@example.com'; |
| 401 | $subject = "けっして平生に説明人はもっとその活動たたまでをしがありましにもお話かけ合わうませから、どうには賑わすたくずますな。"; |
| 402 | $message = "私は同年どうぞこういう返事事に対するののうちにやっただろ。まあ事実を料理院は同時にそのお話でんばかりからなりていでからも助力知れますますば、どうにはなりたますたます。"; |
| 403 | wp_mail( $to, $subject, $message ); |
| 404 | $mailer = tests_retrieve_phpmailer_instance(); |
| 405 | $this->assertSame( 'hello@example.com', $mailer->get_recipient( 'to' )->address ); |
| 406 | |
| 407 | $this->assertSame( $subject, $mailer->get_sent()->subject ); |
| 408 | $this->assertSame( $message, base64_decode( $mailer->get_sent()->body ) ); |
| 409 | $this->assertRegExp( '/Content-Transfer-Encoding:\s+?base64/', $mailer->get_sent()->header ); |
| 410 | } |
394 | 411 | } |
diff --git tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php
index 3e8ae840db..efd57e9d06 100644
|
|
class Tests_Privacy_WpPrivacySendPersonalDataExportEmail extends WP_UnitTestCase |
81 | 81 | $this->assertSame( 'request-confirmed', get_post_status( self::$request_id ) ); |
82 | 82 | $this->assertSame( self::$requester_email, $mailer->get_recipient( 'to' )->address ); |
83 | 83 | $this->assertContains( 'Personal Data Export', $mailer->get_sent()->subject ); |
84 | | $this->assertContains( $archive_url, $mailer->get_sent()->body ); |
85 | | $this->assertContains( 'please download it', $mailer->get_sent()->body ); |
| 84 | $this->assertContains( $archive_url, base64_decode( $mailer->get_sent()->body ) ); |
| 85 | $this->assertContains( 'please download it', base64_decode( $mailer->get_sent()->body ) ); |
86 | 86 | $this->assertTrue( $email_sent ); |
87 | 87 | } |
88 | 88 | |
… |
… |
class Tests_Privacy_WpPrivacySendPersonalDataExportEmail extends WP_UnitTestCase |
128 | 128 | remove_filter( 'wp_privacy_export_expiration', array( $this, 'modify_export_expiration' ) ); |
129 | 129 | |
130 | 130 | $mailer = tests_retrieve_phpmailer_instance(); |
131 | | $this->assertContains( 'we will automatically delete the file on December 18, 2017,', $mailer->get_sent()->body ); |
| 131 | $this->assertContains( 'we will automatically delete the file on December 18, 2017,', |
| 132 | base64_decode( $mailer->get_sent()->body ) ); |
132 | 133 | } |
133 | 134 | |
134 | 135 | /** |
… |
… |
class Tests_Privacy_WpPrivacySendPersonalDataExportEmail extends WP_UnitTestCase |
155 | 156 | remove_filter( 'wp_privacy_personal_data_email_content', array( $this, 'modify_email_content' ) ); |
156 | 157 | |
157 | 158 | $mailer = tests_retrieve_phpmailer_instance(); |
158 | | $this->assertContains( 'Custom content for request ID: ' . self::$request_id, $mailer->get_sent()->body ); |
| 159 | $this->assertContains( 'Custom content for request ID: ' . self::$request_id, |
| 160 | base64_decode( $mailer->get_sent()->body ) ); |
159 | 161 | } |
160 | 162 | |
161 | 163 | /** |