From c8ac9622ea9c1c6f396db58714b7aa509166c6cb Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sat, 11 Jul 2015 22:07:18 -0700 Subject: [PATCH] Clean up UserMailer::send() parameters $replyto and $contentType should now be passed as an array of $options. This will make it easier to add more options in the future without having a long list of optional parameters. Change-Id: I2c38bb438bd01e0ed2552024a40311f3e8e2dc08 --- includes/User.php | 4 +++- includes/jobqueue/jobs/EmaillingJob.php | 2 +- includes/mail/EmailNotification.php | 8 ++++++-- includes/mail/UserMailer.php | 26 ++++++++++++++++++++----- includes/specials/SpecialEmailuser.php | 4 +++- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/includes/User.php b/includes/User.php index d627a6db3c..4c044bde15 100644 --- a/includes/User.php +++ b/includes/User.php @@ -4252,7 +4252,9 @@ class User implements IDBAccessObject { } $to = MailAddress::newFromUser( $this ); - return UserMailer::send( $to, $sender, $subject, $body, $replyto ); + return UserMailer::send( $to, $sender, $subject, $body, array( + 'replyTo' => $replyto, + ) ); } /** diff --git a/includes/jobqueue/jobs/EmaillingJob.php b/includes/jobqueue/jobs/EmaillingJob.php index 68e96fcf31..beeb067370 100644 --- a/includes/jobqueue/jobs/EmaillingJob.php +++ b/includes/jobqueue/jobs/EmaillingJob.php @@ -38,7 +38,7 @@ class EmaillingJob extends Job { $this->params['from'], $this->params['subj'], $this->params['body'], - $this->params['replyto'] + array( 'replyTo' => $this->params['replyto'] ) ); return $status->isOK(); diff --git a/includes/mail/EmailNotification.php b/includes/mail/EmailNotification.php index 1027732867..0eed45034e 100644 --- a/includes/mail/EmailNotification.php +++ b/includes/mail/EmailNotification.php @@ -478,7 +478,9 @@ class EmailNotification { $wgContLang->userTime( $this->timestamp, $watchingUser ) ), $this->body ); - return UserMailer::send( $to, $this->from, $this->subject, $body, $this->replyto ); + return UserMailer::send( $to, $this->from, $this->subject, $body, array( + 'replyTo' => $this->replyto, + ) ); } /** @@ -503,7 +505,9 @@ class EmailNotification { $wgContLang->time( $this->timestamp, false, false ) ), $this->body ); - return UserMailer::send( $addresses, $this->from, $this->subject, $body, $this->replyto ); + return UserMailer::send( $addresses, $this->from, $this->subject, $body, array( + 'replyTo' => $this->replyto, + ) ); } } diff --git a/includes/mail/UserMailer.php b/includes/mail/UserMailer.php index 546cc8cda5..d83ae93624 100644 --- a/includes/mail/UserMailer.php +++ b/includes/mail/UserMailer.php @@ -102,16 +102,32 @@ 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 MailAddress $replyto Optional reply-to email (default: null). - * @param string $contentType Optional custom Content-Type (default: text/plain; charset=UTF-8) + * @param array $options: + * 'replyTo' MailAddress + * 'contentType' string default 'text/plain; charset=UTF-8' + * + * Previous versions of this function had $replyto as the 5th argument and $contentType + * as the 6th. These are still supported for backwards compatability, but deprecated. + * * @throws MWException * @throws Exception * @return Status */ - public static function send( $to, $from, $subject, $body, $replyto = null, - $contentType = 'text/plain; charset=UTF-8' - ) { + public static function send( $to, $from, $subject, $body, $options = array() ) { global $wgSMTP, $wgEnotifMaxRecips, $wgAdditionalMailParams, $wgAllowHTMLEmail; + $contentType = 'text/plain; charset=UTF-8'; + if ( is_array( $options ) ) { + $replyto = isset( $options['replyTo'] ) ? $options['replyTo'] : null; + $contentType = isset( $options['contentType'] ) ? $options['contentType'] : $contentType; + } else { + // Old calling style + wfDeprecated( __METHOD__ . ' with $replyto as 5th parameter', '1.26' ); + $replyto = $options; + if ( func_num_args() === 6 ) { + $contentType = func_get_arg( 5 ); + } + } + $mime = null; if ( !is_array( $to ) ) { $to = array( $to ); diff --git a/includes/specials/SpecialEmailuser.php b/includes/specials/SpecialEmailuser.php index c55fa94c4f..1754471d5c 100644 --- a/includes/specials/SpecialEmailuser.php +++ b/includes/specials/SpecialEmailuser.php @@ -356,7 +356,9 @@ class SpecialEmailUser extends UnlistedSpecialPage { $replyTo = null; } - $status = UserMailer::send( $to, $mailFrom, $subject, $text, $replyTo ); + $status = UserMailer::send( $to, $mailFrom, $subject, $text, array( + 'replyTo' => $replyTo, + ) ); if ( !$status->isGood() ) { return $status; -- 2.20.1