Changeset 32070
- Timestamp:
- 04/07/2015 08:09:46 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/pluggable.php
r32045 r32070 303 303 // Mainly for legacy -- process a From: header if it's there 304 304 case 'from': 305 if ( strpos($content, '<' ) !== false ) { 306 // So... making my life hard again? 307 $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 ); 308 $from_name = str_replace( '"', '', $from_name ); 309 $from_name = trim( $from_name ); 310 311 $from_email = substr( $content, strpos( $content, '<' ) + 1 ); 305 $bracket_pos = strpos( $content, '<' ); 306 if ( $bracket_pos !== false ) { 307 // Text before the bracketed email is the "From" name. 308 if ( $bracket_pos > 0 ) { 309 $from_name = substr( $content, 0, $bracket_pos - 1 ); 310 $from_name = str_replace( '"', '', $from_name ); 311 $from_name = trim( $from_name ); 312 } 313 314 $from_email = substr( $content, $bracket_pos + 1 ); 312 315 $from_email = str_replace( '>', '', $from_email ); 313 316 $from_email = trim( $from_email ); 314 } else { 317 318 // Avoid setting an empty $from_email. 319 } elseif ( '' !== trim( $content ) ) { 315 320 $from_email = trim( $content ); 316 321 } … … 318 323 case 'content-type': 319 324 if ( strpos( $content, ';' ) !== false ) { 320 list( $type, $charset ) = explode( ';', $content );325 list( $type, $charset_content ) = explode( ';', $content ); 321 326 $content_type = trim( $type ); 322 if ( false !== stripos( $charset , 'charset=' ) ) {323 $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) );324 } elseif ( false !== stripos( $charset , 'boundary=' ) ) {325 $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset ) );327 if ( false !== stripos( $charset_content, 'charset=' ) ) { 328 $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset_content ) ); 329 } elseif ( false !== stripos( $charset_content, 'boundary=' ) ) { 330 $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) ); 326 331 $charset = ''; 327 332 } 328 } else { 333 334 // Avoid setting an empty $content_type. 335 } elseif ( '' !== trim( $content ) ) { 329 336 $content_type = trim( $content ); 330 337 } -
trunk/tests/phpunit/tests/mail.php
r31622 r32070 157 157 $this->assertFalse( wp_mail( 'invalid.address', 'subject', 'body', '', array() ) ); 158 158 } 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 } 159 249 }
Note: See TracChangeset
for help on using the changeset viewer.