Make WordPress Core

Ticket #28039: 28039.2.diff

File 28039.2.diff, 2.9 KB (added by mdawaffe, 11 years ago)

https://github.com/PHPMailer/PHPMailer/commit/9bdda8c8cb926a7676974f24fe308f58146f0e3d + UTs

  • src/wp-includes/class-phpmailer.php

     
    16671667    public function getMailMIME()
    16681668    {
    16691669        $result = '';
     1670        $ismultipart = true;
    16701671        switch ($this->message_type) {
    16711672            case 'inline':
    16721673                $result .= $this->headerLine('Content-Type', 'multipart/related;');
     
    16871688            default:
    16881689                // Catches case 'plain': and case '':
    16891690                $result .= $this->textLine('Content-Type: ' . $this->ContentType . '; charset=' . $this->CharSet);
     1691                $ismultipart = false;
    16901692                break;
    16911693        }
    16921694        //RFC1341 part 5 says 7bit is assumed if not specified
    16931695        if ($this->Encoding != '7bit') {
    1694             $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
     1696            //RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
     1697            if ($ismultipart) {
     1698                if ($this->Encoding == '8bit') {
     1699                    $result .= $this->headerLine('Content-Transfer-Encoding', '8bit');
     1700                }
     1701                //The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
     1702            } else {
     1703                $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
     1704            }
    16951705        }
    16961706
    16971707        if ($this->Mailer != 'mail') {
  • tests/phpunit/tests/mail.php

     
    190190                // Fatal errors
    191191                $this->assertFalse( wp_mail( 'invalid.address', 'subject', 'body', '', array() ) );
    192192        }
     193
     194        function wp_mail_quoted_printable( $mailer ) {
     195                $mailer->Encoding = 'quoted-printable';
     196        }
     197
     198        function wp_mail_set_text_message( $mailer ) {
     199                $mailer->AltBody = 'Wörld';
     200        }
     201
     202        /**
     203         * > If an entity is of type "multipart" the Content-Transfer-Encoding is
     204         * > not permitted to have any value other than "7bit", "8bit" or
     205         * > "binary".
     206         * http://tools.ietf.org/html/rfc2045#section-6.4
     207         *
     208         * > "Content-Transfer-Encoding: 7BIT" is assumed if the
     209         * > Content-Transfer-Encoding header field is not present.
     210         * http://tools.ietf.org/html/rfc2045#section-6.1
     211         *
     212         * @ticket 28039
     213         */
     214        function test_wp_mail_content_transfer_encoding_in_quoted_printable_multipart() {
     215                add_action( 'phpmailer_init', array( $this, 'wp_mail_quoted_printable' ) );
     216                add_action( 'phpmailer_init', array( $this, 'wp_mail_set_text_message' ) );
     217
     218                wp_mail(
     219                        'user@example.com',
     220                        'Hello',
     221                        '<p><strong>Wörld</strong></p>',
     222                        'Content-Type: text/html'
     223                );
     224
     225                $this->assertNotContains( 'quoted-printable', $GLOBALS['phpmailer']->mock_sent[0]['header'] );
     226        }
    193227}