/**
* Send mail using a PEAR mailer
*
- * @param UserMailer $mailer
+ * @param Mail_smtp $mailer
* @param string $dest
* @param string $headers
* @param string $body
* @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 );
* @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
// 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
}
foreach ( $splitTo as $newTo ) {
$status->merge( UserMailer::sendInternal(
- array( $newTo ), $from, $subject, $body, $options ) );
+ [ $newTo ], $from, $subject, $body, $options ) );
}
return $status;
}
MailAddress $from,
$subject,
$body,
- $options = array()
+ $options = []
) {
global $wgSMTP, $wgEnotifMaxRecips, $wgAdditionalMailParams;
$mime = null;
$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 {
$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.
$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()
$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 );
}
}
- $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();
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();
* @return string
*/
public static function sanitizeHeaderValue( $val ) {
- return strtr( $val, array( "\r" => '', "\n" => '' ) );
+ return strtr( $val, [ "\r" => '', "\n" => '' ] );
}
/**
}
$out = "=?$charset?Q?";
$out .= preg_replace_callback( "/([$replace])/",
- array( __CLASS__, 'quotedPrintableCallback' ), $string );
+ [ __CLASS__, 'quotedPrintableCallback' ], $string );
$out .= '?=';
return $out;
}