Ticket #10420: 10420_4.patch
| File 10420_4.patch, 7.0 KB (added by nacin, 4 years ago) |
|---|
-
pluggable.php
244 244 * @uses PHPMailer 245 245 * @ 246 246 * 247 * @param string $to Email address to send message247 * @param string|array $to Array or comma-separated list of email addresses to send message. 248 248 * @param string $subject Email subject 249 249 * @param string $message Message contents 250 250 * @param string|array $headers Optional. Additional headers. … … 256 256 extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) ); 257 257 258 258 if ( !is_array($attachments) ) 259 $attachments = explode( "\n", $attachments);259 $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) ); 260 260 261 261 global $phpmailer; 262 262 … … 274 274 if ( !is_array( $headers ) ) { 275 275 // Explode the headers out, so this function can take both 276 276 // string headers and an array of headers. 277 $tempheaders = (array) explode( "\n", $headers);277 $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) ); 278 278 } else { 279 279 $tempheaders = $headers; 280 280 } … … 295 295 list( $name, $content ) = explode( ':', trim( $header ), 2 ); 296 296 297 297 // Cleanup crew 298 $name = trim( $name);298 $name = trim( $name ); 299 299 $content = trim( $content ); 300 300 301 // Mainly for legacy -- process a From: header if it's there 302 if ( 'from' == strtolower($name) ) { 303 if ( strpos($content, '<' ) !== false ) { 304 // So... making my life hard again? 305 $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 ); 306 $from_name = str_replace( '"', '', $from_name ); 307 $from_name = trim( $from_name ); 301 switch ( strtolower( $name ) ) { 302 // Mainly for legacy -- process a From: header if it's there 303 case 'from': 304 if ( strpos($content, '<' ) !== false ) { 305 // So... making my life hard again? 306 $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 ); 307 $from_name = str_replace( '"', '', $from_name ); 308 $from_name = trim( $from_name ); 308 309 309 $from_email = substr( $content, strpos( $content, '<' ) + 1 ); 310 $from_email = str_replace( '>', '', $from_email ); 311 $from_email = trim( $from_email ); 312 } else { 313 $from_email = trim( $content ); 314 } 315 } elseif ( 'content-type' == strtolower($name) ) { 316 if ( strpos( $content,';' ) !== false ) { 317 list( $type, $charset ) = explode( ';', $content ); 318 $content_type = trim( $type ); 319 if ( false !== stripos( $charset, 'charset=' ) ) { 320 $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) ); 321 } elseif ( false !== stripos( $charset, 'boundary=' ) ) { 322 $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset ) ); 323 $charset = ''; 310 $from_email = substr( $content, strpos( $content, '<' ) + 1 ); 311 $from_email = str_replace( '>', '', $from_email ); 312 $from_email = trim( $from_email ); 313 } else { 314 $from_email = trim( $content ); 324 315 } 325 } else { 326 $content_type = trim( $content ); 327 } 328 } elseif ( 'cc' == strtolower($name) ) { 329 $cc = explode(",", $content); 330 } elseif ( 'bcc' == strtolower($name) ) { 331 $bcc = explode(",", $content); 332 } else { 333 // Add it to our grand headers array 334 $headers[trim( $name )] = trim( $content ); 316 break; 317 case 'content-type': 318 if ( strpos( $content, ';' ) !== false ) { 319 list( $type, $charset ) = explode( ';', $content ); 320 $content_type = trim( $type ); 321 if ( false !== stripos( $charset, 'charset=' ) ) { 322 $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) ); 323 } elseif ( false !== stripos( $charset, 'boundary=' ) ) { 324 $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset ) ); 325 $charset = ''; 326 } 327 } else { 328 $content_type = trim( $content ); 329 } 330 break; 331 case 'cc': 332 $cc = array_merge( (array) $cc, explode( ",", $content ) ); 333 break; 334 case 'bcc': 335 $bcc = array_merge( (array) $bcc, explode( ",", $content ) ); 336 break; 337 default: 338 // Add it to our grand headers array 339 $headers[trim( $name )] = trim( $content ); 340 break; 335 341 } 336 342 } 337 343 } … … 348 354 349 355 // From email and name 350 356 // If we don't have a name from the input headers 351 if ( !isset( $from_name ) ) {357 if ( !isset( $from_name ) ) 352 358 $from_name = 'WordPress'; 353 }354 359 355 360 /* If we don't have an email from the input headers default to wordpress@$sitename 356 361 * Some hosts will block outgoing mail from this address if it doesn't exist but … … 370 375 } 371 376 372 377 // Plugin authors can override the potentially troublesome default 373 $phpmailer->From = apply_filters( 'wp_mail_from', $from_email );374 $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name );378 $phpmailer->From = apply_filters( 'wp_mail_from' , $from_email ); 379 $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name ); 375 380 376 // Set destination address 377 $phpmailer->AddAddress( $to ); 381 // Set destination addresses 382 if ( !is_array( $to ) ) 383 $to = explode( ',', $to ); 378 384 385 if ( !empty( $to ) ) { 386 foreach ( (array) $to as $recipient ) { 387 $phpmailer->AddAddress( trim( $recipient ) ); 388 } 389 } 390 379 391 // Set mail's subject and body 380 392 $phpmailer->Subject = $subject; 381 $phpmailer->Body = $message;393 $phpmailer->Body = $message; 382 394 383 395 // Add any CC and BCC recipients 384 if ( !empty( $cc) ) {396 if ( !empty( $cc ) ) { 385 397 foreach ( (array) $cc as $recipient ) { 386 398 $phpmailer->AddCc( trim($recipient) ); 387 399 } 388 400 } 389 if ( !empty($bcc) ) { 401 402 if ( !empty( $bcc ) ) { 390 403 foreach ( (array) $bcc as $recipient) { 391 404 $phpmailer->AddBcc( trim($recipient) ); 392 405 } … … 397 410 398 411 // Set Content-Type and charset 399 412 // If we don't have a content-type from the input headers 400 if ( !isset( $content_type ) ) {413 if ( !isset( $content_type ) ) 401 414 $content_type = 'text/plain'; 402 }403 415 404 416 $content_type = apply_filters( 'wp_mail_content_type', $content_type ); 405 417 406 418 $phpmailer->ContentType = $content_type; 407 419 408 420 // Set whether it's plaintext or not, depending on $content_type 409 if ( $content_type == 'text/html' ) {421 if ( 'text/html' == $content_type ) 410 422 $phpmailer->IsHTML( true ); 411 }412 423 413 424 // If we don't have a charset from the input headers 414 if ( !isset( $charset ) ) {425 if ( !isset( $charset ) ) 415 426 $charset = get_bloginfo( 'charset' ); 416 }417 427 418 428 // Set the content-type and charset 419 429 $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset ); … … 423 433 foreach( (array) $headers as $name => $content ) { 424 434 $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) ); 425 435 } 426 if ( false !== stripos( $content_type, 'multipart' ) && ! empty($boundary) ) { 436 437 if ( false !== stripos( $content_type, 'multipart' ) && ! empty($boundary) ) 427 438 $phpmailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) ); 428 }429 439 } 430 440 431 441 if ( !empty( $attachments ) ) {
