Merge "Add SPARQL client to core"
[lhc/web/wiklou.git] / includes / mail / UserMailer.php
index 1059d7b..fb0f2f9 100644 (file)
@@ -102,10 +102,10 @@ class UserMailer {
         * @param MailAddress $from Sender's email
         * @param string $subject Email's subject.
         * @param string $body Email's text or Array of two strings to be the text and html bodies
-        * @param array $options:
-        *              'replyTo' MailAddress
-        *              'contentType' string default 'text/plain; charset=UTF-8'
-        *              'headers' array Extra headers to set
+        * @param array $options Keys:
+        *     'replyTo' MailAddress
+        *     'contentType' string default 'text/plain; charset=UTF-8'
+        *     'headers' array Extra headers to set
         *
         * @throws MWException
         * @throws Exception
@@ -175,18 +175,18 @@ class UserMailer {
                                // first send to non-split address list, then to split addresses one by one
                                $status = Status::newGood();
                                if ( $to ) {
-                                       $status->merge( UserMailer::sendInternal(
+                                       $status->merge( self::sendInternal(
                                                $to, $from, $subject, $body, $options ) );
                                }
                                foreach ( $splitTo as $newTo ) {
-                                       $status->merge( UserMailer::sendInternal(
+                                       $status->merge( self::sendInternal(
                                                [ $newTo ], $from, $subject, $body, $options ) );
                                }
                                return $status;
                        }
                }
 
-               return UserMailer::sendInternal( $to, $from, $subject, $body, $options );
+               return self::sendInternal( $to, $from, $subject, $body, $options );
        }
 
        /**
@@ -196,10 +196,10 @@ class UserMailer {
         * @param MailAddress $from Sender's email
         * @param string $subject Email's subject.
         * @param string $body Email's text or Array of two strings to be the text and html bodies
-        * @param array $options:
-        *              'replyTo' MailAddress
-        *              'contentType' string default 'text/plain; charset=UTF-8'
-        *              'headers' array Extra headers to set
+        * @param array $options Keys:
+        *     'replyTo' MailAddress
+        *     'contentType' string default 'text/plain; charset=UTF-8'
+        *     'headers' array Extra headers to set
         *
         * @throws MWException
         * @throws Exception
@@ -268,7 +268,14 @@ class UserMailer {
                // 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.
-               $extraParams .= ' -f ' . $returnPath;
+
+               // PHP runs this through escapeshellcmd(). However that's not sufficient
+               // escaping (e.g. due to spaces). MediaWiki's email sanitizer should generally
+               // be good enough, but just in case, put in double quotes, and remove any
+               // double quotes present (" is not allowed in emails, so should have no
+               // effect, although this might cause apostrophees to be double escaped)
+               $returnPathCLI = '"' . str_replace( '"', '', $returnPath ) . '"';
+               $extraParams .= ' -f ' . $returnPathCLI;
 
                $headers['Return-Path'] = $returnPath;
 
@@ -283,7 +290,7 @@ class UserMailer {
                        ->getFullURL( '', false, PROTO_CANONICAL ) . '>';
 
                // Line endings need to be different on Unix and Windows due to
-               // the bug described at http://trac.wordpress.org/ticket/2603
+               // the bug described at https://core.trac.wordpress.org/ticket/2603
                $endl = PHP_EOL;
 
                if ( is_array( $body ) ) {
@@ -353,13 +360,13 @@ class UserMailer {
                                require_once 'Mail.php';
                        }
 
-                       MediaWiki\suppressWarnings();
+                       Wikimedia\suppressWarnings();
 
                        // Create the mail object using the Mail::factory method
                        $mail_object =& Mail::factory( 'smtp', $wgSMTP );
                        if ( PEAR::isError( $mail_object ) ) {
                                wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" );
-                               MediaWiki\restoreWarnings();
+                               Wikimedia\restoreWarnings();
                                return Status::newFatal( 'pear-mail-error', $mail_object->getMessage() );
                        }
 
@@ -379,11 +386,11 @@ class UserMailer {
                                $status = self::sendWithPear( $mail_object, $chunk, $headers, $body );
                                // FIXME : some chunks might be sent while others are not!
                                if ( !$status->isOK() ) {
-                                       MediaWiki\restoreWarnings();
+                                       Wikimedia\restoreWarnings();
                                        return $status;
                                }
                        }
-                       MediaWiki\restoreWarnings();
+                       Wikimedia\restoreWarnings();
                        return Status::newGood();
                } else {
                        // PHP mail()