X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fmail%2FUserMailer.php;h=102d61599ca8ca663214ba855a4527b2da48c2fb;hp=fb0f2f99f06eb24149c84b665b10e3dae250be5a;hb=c57aacb782f5ce5e53253192a53d736ece300d3c;hpb=0c2687f44eb0e8c7f480b7303f89056682ba0bfb diff --git a/includes/mail/UserMailer.php b/includes/mail/UserMailer.php index fb0f2f99f0..102d61599c 100644 --- a/includes/mail/UserMailer.php +++ b/includes/mail/UserMailer.php @@ -189,6 +189,35 @@ class UserMailer { return self::sendInternal( $to, $from, $subject, $body, $options ); } + /** + * Whether the PEAR Mail_mime library is usable. This will + * try and load it if it is not already. + * + * @return bool + */ + private static function isMailMimeUsable() { + static $usable = null; + if ( $usable === null ) { + $usable = class_exists( 'Mail_mime' ); + } + return $usable; + } + + /** + * Whether the PEAR Mail library is usable. This will + * try and load it if it is not already. + * + * @return bool + */ + private static function isMailUsable() { + static $usable = null; + if ( $usable === null ) { + $usable = class_exists( 'Mail' ); + } + + return $usable; + } + /** * Helper function fo UserMailer::send() which does the actual sending. It expects a $to * list which the UserMailerSplitTo hook would not split further. @@ -215,10 +244,9 @@ class UserMailer { 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'] : []; + $replyto = $options['replyTo'] ?? null; + $contentType = $options['contentType'] ?? 'text/plain; charset=UTF-8'; + $headers = $options['headers'] ?? []; // Allow transformation of content, such as encrypting/signing $error = false; @@ -296,15 +324,12 @@ class UserMailer { if ( is_array( $body ) ) { // we are sending a multipart message wfDebug( "Assembling multipart mime email\n" ); - if ( !stream_resolve_include_path( 'Mail/mime.php' ) ) { + if ( !self::isMailMimeUsable() ) { wfDebug( "PEAR Mail_Mime package is not installed. Falling back to text email.\n" ); // remove the html body for text email fall back $body = $body['text']; } else { - // Check if pear/mail_mime is already loaded (via composer) - if ( !class_exists( 'Mail_mime' ) ) { - require_once 'Mail/mime.php'; - } + // pear/mail_mime is already loaded by this point if ( wfIsWindows() ) { $body['text'] = str_replace( "\n", "\r\n", $body['text'] ); $body['html'] = str_replace( "\n", "\r\n", $body['html'] ); @@ -352,18 +377,14 @@ class UserMailer { if ( is_array( $wgSMTP ) ) { // Check if pear/mail is already loaded (via composer) - if ( !class_exists( 'Mail' ) ) { - // PEAR MAILER - if ( !stream_resolve_include_path( 'Mail.php' ) ) { - throw new MWException( 'PEAR mail package is not installed' ); - } - require_once 'Mail.php'; + if ( !self::isMailUsable() ) { + throw new MWException( 'PEAR mail package is not installed' ); } Wikimedia\suppressWarnings(); // Create the mail object using the Mail::factory method - $mail_object =& Mail::factory( 'smtp', $wgSMTP ); + $mail_object = Mail::factory( 'smtp', $wgSMTP ); if ( PEAR::isError( $mail_object ) ) { wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" ); Wikimedia\restoreWarnings(); @@ -409,7 +430,7 @@ class UserMailer { try { foreach ( $to as $recip ) { $sent = mail( - $recip, + $recip->toString(), self::quotedPrintable( $subject ), $body, $headers,