Fix param docs and passed type of UserMailer::sendWithPear
authorUmherirrender <umherirrender_de.wp@web.de>
Wed, 11 Sep 2019 20:12:04 +0000 (22:12 +0200)
committerUmherirrender <umherirrender_de.wp@web.de>
Thu, 12 Sep 2019 18:00:43 +0000 (20:00 +0200)
Mail::send accepts mixed for recipients and only array for headers
The documentation for recipients allows string with comma-separated list
or a string array
https://github.com/pear/Mail/blob/master/Mail/mail.php#L115-L119

Change-Id: Ia8269e91a7dcfe09d41bd03f8830b83f28812564

includes/mail/UserMailer.php

index 47fa16f..0783068 100644 (file)
@@ -34,8 +34,8 @@ class UserMailer {
         * Send mail using a PEAR mailer
         *
         * @param Mail_smtp $mailer
         * Send mail using a PEAR mailer
         *
         * @param Mail_smtp $mailer
-        * @param string $dest
-        * @param string $headers
+        * @param string[]|string $dest
+        * @param array $headers
         * @param string $body
         *
         * @return Status
         * @param string $body
         *
         * @return Status
@@ -382,6 +382,8 @@ class UserMailer {
                                throw new MWException( 'PEAR mail package is not installed' );
                        }
 
                                throw new MWException( 'PEAR mail package is not installed' );
                        }
 
+                       $recips = array_map( 'strval', $to );
+
                        Wikimedia\suppressWarnings();
 
                        // Create the mail object using the Mail::factory method
                        Wikimedia\suppressWarnings();
 
                        // Create the mail object using the Mail::factory method
@@ -397,13 +399,13 @@ class UserMailer {
                        $headers['Subject'] = self::quotedPrintable( $subject );
 
                        // When sending only to one recipient, shows it its email using To:
                        $headers['Subject'] = self::quotedPrintable( $subject );
 
                        // When sending only to one recipient, shows it its email using To:
-                       if ( count( $to ) == 1 ) {
-                               $headers['To'] = $to[0]->toString();
+                       if ( count( $recips ) == 1 ) {
+                               $headers['To'] = $recips[0];
                        }
 
                        // Split jobs since SMTP servers tends to limit the maximum
                        // number of possible recipients.
                        }
 
                        // Split jobs since SMTP servers tends to limit the maximum
                        // number of possible recipients.
-                       $chunks = array_chunk( $to, $wgEnotifMaxRecips );
+                       $chunks = array_chunk( $recips, $wgEnotifMaxRecips );
                        foreach ( $chunks as $chunk ) {
                                $status = self::sendWithPear( $mail_object, $chunk, $headers, $body );
                                // FIXME : some chunks might be sent while others are not!
                        foreach ( $chunks as $chunk ) {
                                $status = self::sendWithPear( $mail_object, $chunk, $headers, $body );
                                // FIXME : some chunks might be sent while others are not!