In preparation for moving to the EmailUserUtils service being added in [1], but can be done in parallel. Includes using some clearer variable names, and using the Emailer "service" (which is just a wrapper for UserMailer::send, but one that can be injected and thus something that will be used when the code is moved to the EmailUserUtils service, changing the code now to make it easier to follow) Additionally, expand Emailer::send to accept a single MailAddress as the to, like UserMailer::send. Includes removing support for onEmailUser hook setting $error to something other than a Status object, true, false, an empty string, an array, or a MessageSpecifier, which has been deprecated since 1.29 [1] Ie63ddcc9805f4dbaa7a33e780611d9de227b0dc1 Bug: T265541 Change-Id: Iad683060f739f4fd5ebfd56d19702ba0129f8538
54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
*
|
|
* @file
|
|
*/
|
|
|
|
namespace MediaWiki\Mail;
|
|
|
|
use MailAddress;
|
|
use StatusValue;
|
|
use UserMailer;
|
|
|
|
/**
|
|
* @internal
|
|
* @since 1.35
|
|
*/
|
|
class Emailer implements IEmailer {
|
|
|
|
/**
|
|
* @since 1.35
|
|
*
|
|
* This function will perform a direct (authenticated) login to
|
|
* a SMTP Server to use for mail relaying if 'wgSMTP' specifies an
|
|
* array of parameters. It requires PEAR:Mail to do that.
|
|
* Otherwise it just uses the standard PHP 'mail' function.
|
|
*
|
|
* @inheritDoc
|
|
*/
|
|
public function send(
|
|
$to,
|
|
MailAddress $from,
|
|
string $subject,
|
|
string $bodyText,
|
|
?string $bodyHtml = null,
|
|
array $options = []
|
|
): StatusValue {
|
|
$body = $bodyHtml ? [ 'text' => $bodyText, 'html' => $bodyHtml ] : $bodyText;
|
|
return UserMailer::send( $to, $from, $subject, $body, $options );
|
|
}
|
|
}
|