Make WordPress Core


Ignore:
Timestamp:
04/07/2015 08:09:46 PM (12 years ago)
Author:
boonebgorges
Message:

Improve handling of incomplete From and Content-Type headers in wp_mail().

When an incomplete header is provided (eg, 'From' with an email address but no
name), ensure that the WP defaults are filled in properly.

Props valendesigns.
Fixes #30266.

File:
1 edited

Legend:

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

    r31622 r32070  
    157157                $this->assertFalse( wp_mail( 'invalid.address', 'subject', 'body', '', array() ) );
    158158        }
     159
     160        /**
     161         * @ticket 30266
     162         */
     163        public function test_wp_mail_with_valid_from_header() {
     164                $to       = "address@tld.com";
     165                $subject  = "Testing";
     166                $message  = "Test Message";
     167                $headers  = "From: Foo <bar@example.com>";
     168                $expected = "From: Foo <bar@example.com>";
     169
     170                wp_mail( $to, $subject, $message, $headers );
     171
     172                $this->assertTrue( strpos( $GLOBALS['phpmailer']->mock_sent[0]['header'], $expected ) > 0 );
     173        }
     174
     175        /**
     176         * @ticket 30266
     177         */
     178        public function test_wp_mail_with_empty_from_header() {
     179                $to       = "address@tld.com";
     180                $subject  = "Testing";
     181                $message  = "Test Message";
     182                $headers  = "From: ";
     183                $expected = "From: WordPress <wordpress@example.com>";
     184
     185                wp_mail( $to, $subject, $message, $headers );
     186
     187                $this->assertTrue( strpos( $GLOBALS['phpmailer']->mock_sent[0]['header'], $expected ) > 0 );
     188        }
     189
     190        /**
     191         * @ticket 30266
     192         */
     193        public function test_wp_mail_with_empty_from_name_for_the_from_header() {
     194                $to       = "address@tld.com";
     195                $subject  = "Testing";
     196                $message  = "Test Message";
     197                $headers  = "From: <wordpress@example.com>";
     198                $expected = "From: WordPress <wordpress@example.com>";
     199
     200                wp_mail( $to, $subject, $message, $headers );
     201
     202                $this->assertTrue( strpos( $GLOBALS['phpmailer']->mock_sent[0]['header'], $expected ) > 0 );
     203        }
     204
     205        /**
     206         * @ticket 30266
     207         */
     208        public function test_wp_mail_with_valid_content_type_header() {
     209                $to       = "address@tld.com";
     210                $subject  = "Testing";
     211                $message  = "Test Message";
     212                $headers  = "Content-Type: text/html; charset=iso-8859-1";
     213                $expected = "Content-Type: text/html; charset=iso-8859-1";
     214
     215                wp_mail( $to, $subject, $message, $headers );
     216
     217                $this->assertTrue( strpos( $GLOBALS['phpmailer']->mock_sent[0]['header'], $expected ) > 0 );
     218        }
     219
     220        /**
     221         * @ticket 30266
     222         */
     223        public function test_wp_mail_with_empty_content_type_header() {
     224                $to       = "address@tld.com";
     225                $subject  = "Testing";
     226                $message  = "Test Message";
     227                $headers  = "Content-Type: ";
     228                $expected = "Content-Type: text/plain; charset=UTF-8";
     229
     230                wp_mail( $to, $subject, $message, $headers );
     231
     232                $this->assertTrue( strpos( $GLOBALS['phpmailer']->mock_sent[0]['header'], $expected ) > 0 );
     233        }
     234
     235        /**
     236         * @ticket 30266
     237         */
     238        public function test_wp_mail_with_empty_charset_for_the_content_type_header() {
     239                $to       = "address@tld.com";
     240                $subject  = "Testing";
     241                $message  = "Test Message";
     242                $headers  = "Content-Type: text/plain;";
     243                $expected = "Content-Type: text/plain; charset=UTF-8";
     244
     245                wp_mail( $to, $subject, $message, $headers );
     246
     247                $this->assertTrue( strpos( $GLOBALS['phpmailer']->mock_sent[0]['header'], $expected ) > 0 );
     248        }
    159249}
Note: See TracChangeset for help on using the changeset viewer.