WordPress.org

Make WordPress Core

Ticket #44548: 44548.patch

File 44548.patch, 6.7 KB (added by miyauchi, 17 months ago)
  • src/wp-includes/pluggable.php

    diff --git src/wp-includes/pluggable.php src/wp-includes/pluggable.php
    index cb06297b57..79078b8be6 100644
    if ( ! function_exists( 'wp_mail' ) ) : 
    453453                 */
    454454                $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
    455455
     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
    456465                // Set custom headers
    457466                if ( ! empty( $headers ) ) {
    458467                        foreach ( (array) $headers as $name => $content ) {
  • tests/phpunit/includes/mock-mailer.php

    diff --git tests/phpunit/includes/mock-mailer.php tests/phpunit/includes/mock-mailer.php
    index ece2aa3640..8dcf3e2a08 100644
    class MockPHPMailer extends PHPMailer { 
    55        var $mock_sent = array();
    66
    77        function preSend() {
    8                 $this->Encoding = '8bit';
    98                return parent::preSend();
    109        }
    1110
  • tests/phpunit/tests/mail.php

    diff --git tests/phpunit/tests/mail.php tests/phpunit/tests/mail.php
    index 951615136b..ab79f29fea 100644
    class Tests_Mail extends WP_UnitTestCase { 
    8080                $mailer = tests_retrieve_phpmailer_instance();
    8181
    8282                // 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 ) );
    8484                $this->assertTrue( strpos( $mailer->get_sent()->header, 'boundary="----=_Part_4892_25692638.1192452070893"' ) > 0 );
    8585                $this->assertTrue( strpos( $mailer->get_sent()->header, 'charset=' ) > 0 );
    8686        }
    class Tests_Mail extends WP_UnitTestCase { 
    112112                $this->assertEquals( 'The Carbon Guy', $mailer->get_recipient( 'cc' )->name );
    113113                $this->assertEquals( 'bcc@bcc.com', $mailer->get_recipient( 'bcc' )->address );
    114114                $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 ) );
    116116        }
    117117
    118118        /**
    class Tests_Mail extends WP_UnitTestCase { 
    132132                $this->assertEquals( 'Name', $mailer->get_recipient( 'to' )->name );
    133133                $this->assertEquals( 'another_address@different-tld.com', $mailer->get_recipient( 'to', 0, 1 )->address );
    134134                $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 ) );
    136136        }
    137137
    138138        function test_wp_mail_multiple_to_addresses() {
    class Tests_Mail extends WP_UnitTestCase { 
    145145                $mailer = tests_retrieve_phpmailer_instance();
    146146                $this->assertEquals( 'address@tld.com', $mailer->get_recipient( 'to' )->address );
    147147                $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 ) );
    149149        }
    150150
    151151        /**
    class Tests_Mail extends WP_UnitTestCase { 
    160160
    161161                $mailer = tests_retrieve_phpmailer_instance();
    162162                $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 ) );
    164164        }
    165165
    166166        /**
    class Tests_Mail extends WP_UnitTestCase { 
    391391                $this->assertEquals( 'wp_mail_failed', $call_args[0]->get_error_code() );
    392392                $this->assertEquals( $expected_error_data, $call_args[0]->get_error_data() );
    393393        }
     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        }
    394411}
  • tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php

    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 
    8181                $this->assertSame( 'request-confirmed', get_post_status( self::$request_id ) );
    8282                $this->assertSame( self::$requester_email, $mailer->get_recipient( 'to' )->address );
    8383                $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 ) );
    8686                $this->assertTrue( $email_sent );
    8787        }
    8888
    class Tests_Privacy_WpPrivacySendPersonalDataExportEmail extends WP_UnitTestCase 
    128128                remove_filter( 'wp_privacy_export_expiration', array( $this, 'modify_export_expiration' ) );
    129129
    130130                $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 ) );
    132133        }
    133134
    134135        /**
    class Tests_Privacy_WpPrivacySendPersonalDataExportEmail extends WP_UnitTestCase 
    155156                remove_filter( 'wp_privacy_personal_data_email_content', array( $this, 'modify_email_content' ) );
    156157
    157158                $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 ) );
    159161        }
    160162
    161163        /**