Make WordPress Core


Ignore:
Timestamp:
07/13/2016 06:03:52 PM (10 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/mail.php

    r37358 r38058  
    308308                $this->assertNotContains( 'quoted-printable', $GLOBALS['phpmailer']->mock_sent[0]['header'] );
    309309        }
     310
     311        /**
     312         * @ticket 21659
     313         */
     314        public function test_wp_mail_addresses_arent_encoded() {
     315                $to      = 'Lukáš To <to@example.org>';
     316                $subject = 'Testing #21659';
     317                $message = 'Only the name should be encoded, not the address.';
     318
     319                $headers = array(
     320                        'From'     => 'From: Lukáš From <from@example.org>',
     321                        'Cc'       => 'Cc: Lukáš CC <cc@example.org>',
     322                        'Bcc'      => 'Bcc: Lukáš BCC <bcc@example.org>',
     323                        'Reply-To' => 'Reply-To: Lukáš Reply-To <reply_to@example.org>',
     324                );
     325
     326                $expected = array(
     327                        'To'       => 'To: =?UTF-8?B?THVrw6HFoSBUbw==?= <to@example.org>',
     328                        'From'     => 'From: =?UTF-8?Q?Luk=C3=A1=C5=A1_From?= <from@example.org>',
     329                        'Cc'       => 'Cc: =?UTF-8?B?THVrw6HFoSBDQw==?= <cc@example.org>',
     330                        'Bcc'      => 'Bcc: =?UTF-8?B?THVrw6HFoSBCQ0M=?= <bcc@example.org>',
     331                        'Reply-To' => 'Reply-To: =?UTF-8?Q?Luk=C3=A1=C5=A1_Reply-To?= <reply_to@example.org>',
     332                );
     333
     334                wp_mail( $to, $subject, $message, array_values( $headers ) );
     335
     336                $mailer        = tests_retrieve_phpmailer_instance();
     337                $sent_headers  = preg_split( "/\r\n|\n|\r/", $mailer->get_sent()->header );
     338                $headers['To'] = "To: $to";
     339
     340                foreach ( $headers as $header => $value ) {
     341                        $target_headers = preg_grep( "/^$header:/", $sent_headers );
     342                        $this->assertEquals( $expected[ $header ], array_pop( $target_headers ) );
     343                }
     344        }
    310345}
Note: See TracChangeset for help on using the changeset viewer.