X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%20%22id_auteur=%24id%22%29%20.%20%22?a=blobdiff_plain;f=includes%2Fmail%2FUserMailer.php;h=464e7b8eee43adff57b70e537c2a1d4e07985512;hb=f9d7d3b8561dab3ddfd8798a77a5b72e03ac8c2b;hp=85595f128621c16200dcbb353260177aeed37bf3;hpb=ea9fcc1e4d3b572199d82c426024e3e5efe23879;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/mail/UserMailer.php b/includes/mail/UserMailer.php index 85595f1286..464e7b8eee 100644 --- a/includes/mail/UserMailer.php +++ b/includes/mail/UserMailer.php @@ -33,7 +33,7 @@ class UserMailer { /** * Send mail using a PEAR mailer * - * @param UserMailer $mailer + * @param Mail_smtp $mailer * @param string $dest * @param string $headers * @param string $body @@ -65,7 +65,7 @@ class UserMailer { * @return string */ static function arrayToHeaderString( $headers, $endl = PHP_EOL ) { - $strings = array(); + $strings = []; foreach ( $headers as $name => $value ) { // Prevent header injection by stripping newlines from value $value = self::sanitizeHeaderValue( $value ); @@ -114,20 +114,23 @@ class UserMailer { * @throws Exception * @return Status */ - public static function send( $to, $from, $subject, $body, $options = array() ) { + public static function send( $to, $from, $subject, $body, $options = [] ) { global $wgAllowHTMLEmail; - $contentType = 'text/plain; charset=UTF-8'; + if ( !is_array( $options ) ) { // Old calling style wfDeprecated( __METHOD__ . ' with $replyto as 5th parameter', '1.26' ); - $options = array( 'replyTo' => $options ); + $options = [ 'replyTo' => $options ]; if ( func_num_args() === 6 ) { $options['contentType'] = func_get_arg( 5 ); } } + if ( !isset( $options['contentType'] ) ) { + $options['contentType'] = 'text/plain; charset=UTF-8'; + } if ( !is_array( $to ) ) { - $to = array( $to ); + $to = [ $to ]; } // mail body must have some content @@ -176,7 +179,7 @@ class UserMailer { // target differently to split up the address list if ( count( $to ) > 1 ) { $oldTo = $to; - Hooks::run( 'UserMailerSplitTo', array( &$to ) ); + Hooks::run( 'UserMailerSplitTo', [ &$to ] ); if ( $oldTo != $to ) { $splitTo = array_diff( $oldTo, $to ); $to = array_diff( $oldTo, $splitTo ); // ignore new addresses added in the hook @@ -188,7 +191,7 @@ class UserMailer { } foreach ( $splitTo as $newTo ) { $status->merge( UserMailer::sendInternal( - array( $newTo ), $from, $subject, $body, $options ) ); + [ $newTo ], $from, $subject, $body, $options ) ); } return $status; } @@ -218,7 +221,7 @@ class UserMailer { MailAddress $from, $subject, $body, - $options = array() + $options = [] ) { global $wgSMTP, $wgEnotifMaxRecips, $wgAdditionalMailParams; $mime = null; @@ -226,11 +229,11 @@ class UserMailer { $replyto = isset( $options['replyTo'] ) ? $options['replyTo'] : null; $contentType = isset( $options['contentType'] ) ? $options['contentType'] : 'text/plain; charset=UTF-8'; - $headers = isset( $options['headers'] ) ? $options['headers'] : array(); + $headers = isset( $options['headers'] ) ? $options['headers'] : []; // Allow transformation of content, such as encrypting/signing $error = false; - if ( !Hooks::run( 'UserMailerTransformContent', array( $to, $from, &$body, &$error ) ) ) { + if ( !Hooks::run( 'UserMailerTransformContent', [ $to, $from, &$body, &$error ] ) ) { if ( $error ) { return Status::newFatal( 'php-mail-error', $error ); } else { @@ -272,7 +275,7 @@ class UserMailer { $extraParams = $wgAdditionalMailParams; // Hook to generate custom VERP address for 'Return-Path' - Hooks::run( 'UserMailerChangeReturnPath', array( $to, &$returnPath ) ); + Hooks::run( 'UserMailerChangeReturnPath', [ $to, &$returnPath ] ); // Add the envelope sender address using the -f command line option when PHP mail() is used. // Will default to the $from->address when the UserMailerChangeReturnPath hook fails and the // generated VERP address when the hook runs effectively. @@ -310,11 +313,11 @@ class UserMailer { $body['text'] = str_replace( "\n", "\r\n", $body['text'] ); $body['html'] = str_replace( "\n", "\r\n", $body['html'] ); } - $mime = new Mail_mime( array( + $mime = new Mail_mime( [ 'eol' => $endl, 'text_charset' => 'UTF-8', 'html_charset' => 'UTF-8' - ) ); + ] ); $mime->setTXTBody( $body['text'] ); $mime->setHTMLBody( $body['html'] ); $body = $mime->get(); // must call get() before headers() @@ -327,14 +330,13 @@ class UserMailer { $body = str_replace( "\n", "\r\n", $body ); } $headers['MIME-Version'] = '1.0'; - $headers['Content-type'] = ( is_null( $contentType ) ? - 'text/plain; charset=UTF-8' : $contentType ); + $headers['Content-type'] = $contentType; $headers['Content-transfer-encoding'] = '8bit'; } // allow transformation of MIME-encoded message if ( !Hooks::run( 'UserMailerTransformMessage', - array( $to, $from, &$subject, &$headers, &$body, &$error ) ) + [ $to, $from, &$subject, &$headers, &$body, &$error ] ) ) { if ( $error ) { return Status::newFatal( 'php-mail-error', $error ); @@ -343,7 +345,7 @@ class UserMailer { } } - $ret = Hooks::run( 'AlternateUserMailer', array( $headers, $to, $from, $subject, $body ) ); + $ret = Hooks::run( 'AlternateUserMailer', [ $headers, $to, $from, $subject, $body ] ); if ( $ret === false ) { // the hook implementation will return false to skip regular mail sending return Status::newGood(); @@ -409,20 +411,14 @@ class UserMailer { set_error_handler( 'UserMailer::errorHandler' ); try { - $safeMode = wfIniGetBool( 'safe_mode' ); - foreach ( $to as $recip ) { - if ( $safeMode ) { - $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers ); - } else { - $sent = mail( - $recip, - self::quotedPrintable( $subject ), - $body, - $headers, - $extraParams - ); - } + $sent = mail( + $recip, + self::quotedPrintable( $subject ), + $body, + $headers, + $extraParams + ); } } catch ( Exception $e ) { restore_error_handler(); @@ -461,7 +457,7 @@ class UserMailer { * @return string */ public static function sanitizeHeaderValue( $val ) { - return strtr( $val, array( "\r" => '', "\n" => '' ) ); + return strtr( $val, [ "\r" => '', "\n" => '' ] ); } /** @@ -505,7 +501,7 @@ class UserMailer { } $out = "=?$charset?Q?"; $out .= preg_replace_callback( "/([$replace])/", - array( __CLASS__, 'quotedPrintableCallback' ), $string ); + [ __CLASS__, 'quotedPrintableCallback' ], $string ); $out .= '?='; return $out; }