2023-03-10 15:39:41 +00:00
|
|
|
<?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;
|
|
|
|
|
|
2023-03-10 19:01:48 +00:00
|
|
|
use BadMethodCallException;
|
|
|
|
|
use CentralIdLookup;
|
2023-03-10 15:39:41 +00:00
|
|
|
use Config;
|
|
|
|
|
use MailAddress;
|
2023-03-10 19:01:48 +00:00
|
|
|
use MediaWiki\Config\ServiceOptions;
|
|
|
|
|
use MediaWiki\HookContainer\HookContainer;
|
2023-05-06 20:01:10 +00:00
|
|
|
use MediaWiki\HookContainer\HookRunner;
|
2023-03-10 15:39:41 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2023-03-10 19:01:48 +00:00
|
|
|
use MediaWiki\Permissions\PermissionManager;
|
2023-03-10 15:39:41 +00:00
|
|
|
use MediaWiki\Preferences\MultiUsernameFilter;
|
2023-03-10 19:01:48 +00:00
|
|
|
use MediaWiki\User\UserFactory;
|
|
|
|
|
use MediaWiki\User\UserOptionsLookup;
|
|
|
|
|
use MessageLocalizer;
|
2023-03-10 15:39:41 +00:00
|
|
|
use MessageSpecifier;
|
2023-03-10 19:01:48 +00:00
|
|
|
use RuntimeException;
|
2023-03-10 15:39:41 +00:00
|
|
|
use SpecialPage;
|
2023-03-11 16:00:50 +00:00
|
|
|
use StatusValue;
|
2023-03-10 15:39:41 +00:00
|
|
|
use ThrottledError;
|
2023-03-10 19:01:48 +00:00
|
|
|
use UnexpectedValueException;
|
2023-03-10 15:39:41 +00:00
|
|
|
use User;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Command for sending emails to users.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.40
|
|
|
|
|
* @unstable
|
|
|
|
|
*/
|
|
|
|
|
class EmailUser {
|
2023-03-10 19:01:48 +00:00
|
|
|
/**
|
|
|
|
|
* @internal For use by ServiceWiring
|
|
|
|
|
*/
|
|
|
|
|
public const CONSTRUCTOR_OPTIONS = [
|
|
|
|
|
MainConfigNames::EnableEmail,
|
|
|
|
|
MainConfigNames::EnableUserEmail,
|
|
|
|
|
MainConfigNames::EnableSpecialMute,
|
|
|
|
|
MainConfigNames::PasswordSender,
|
|
|
|
|
MainConfigNames::UserEmailUseReplyTo,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/** @var ServiceOptions */
|
|
|
|
|
private ServiceOptions $options;
|
|
|
|
|
/** @var HookRunner */
|
|
|
|
|
private HookRunner $hookRunner;
|
|
|
|
|
/** @var UserOptionsLookup */
|
|
|
|
|
private UserOptionsLookup $userOptionsLookup;
|
|
|
|
|
/** @var CentralIdLookup */
|
|
|
|
|
private CentralIdLookup $centralIdLookup;
|
|
|
|
|
/** @var PermissionManager */
|
|
|
|
|
private PermissionManager $permissionManager;
|
|
|
|
|
/** @var UserFactory */
|
|
|
|
|
private UserFactory $userFactory;
|
|
|
|
|
/** @var IEmailer */
|
|
|
|
|
private IEmailer $emailer;
|
|
|
|
|
|
|
|
|
|
/** @var ServiceOptions|null Temporary property for BC with SpecialEmailUser */
|
|
|
|
|
private ?ServiceOptions $oldOptions;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param ServiceOptions $options
|
|
|
|
|
* @param HookContainer $hookContainer
|
|
|
|
|
* @param UserOptionsLookup $userOptionsLookup
|
|
|
|
|
* @param CentralIdLookup $centralIdLookup
|
|
|
|
|
* @param PermissionManager $permissionManager
|
|
|
|
|
* @param UserFactory $userFactory
|
|
|
|
|
* @param IEmailer $emailer
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
ServiceOptions $options,
|
|
|
|
|
HookContainer $hookContainer,
|
|
|
|
|
UserOptionsLookup $userOptionsLookup,
|
|
|
|
|
CentralIdLookup $centralIdLookup,
|
|
|
|
|
PermissionManager $permissionManager,
|
|
|
|
|
UserFactory $userFactory,
|
|
|
|
|
IEmailer $emailer
|
|
|
|
|
) {
|
|
|
|
|
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
|
|
|
|
|
$this->options = $options;
|
|
|
|
|
$this->hookRunner = new HookRunner( $hookContainer );
|
|
|
|
|
$this->userOptionsLookup = $userOptionsLookup;
|
|
|
|
|
$this->centralIdLookup = $centralIdLookup;
|
|
|
|
|
$this->permissionManager = $permissionManager;
|
|
|
|
|
$this->userFactory = $userFactory;
|
|
|
|
|
$this->emailer = $emailer;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 15:39:41 +00:00
|
|
|
/**
|
|
|
|
|
* Validate target User
|
|
|
|
|
*
|
|
|
|
|
* @param string $target Target user name
|
|
|
|
|
* @param User $sender User sending the email
|
2023-03-11 23:59:30 +00:00
|
|
|
* @return StatusValue With errors, or with a User object as value on success.
|
2023-03-10 15:39:41 +00:00
|
|
|
*/
|
2023-03-11 23:59:30 +00:00
|
|
|
public function getTarget( string $target, User $sender ): StatusValue {
|
2023-03-11 16:00:50 +00:00
|
|
|
$nu = $this->userFactory->newFromName( $target );
|
|
|
|
|
if ( !$nu instanceof User ) {
|
2023-03-11 23:59:30 +00:00
|
|
|
return StatusValue::newFatal( 'emailnotarget' );
|
2023-03-10 15:39:41 +00:00
|
|
|
}
|
2023-03-11 23:59:30 +00:00
|
|
|
$status = $this->validateTarget( $nu, $sender );
|
|
|
|
|
if ( !$status->isGood() ) {
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
return StatusValue::newGood( $nu );
|
2023-03-10 15:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validate target User
|
|
|
|
|
*
|
2023-03-11 16:00:50 +00:00
|
|
|
* @param User $target Target user
|
2023-03-10 15:39:41 +00:00
|
|
|
* @param User $sender User sending the email
|
2023-03-11 23:59:30 +00:00
|
|
|
* @return StatusValue
|
2023-03-10 15:39:41 +00:00
|
|
|
*/
|
2023-03-11 23:59:30 +00:00
|
|
|
public function validateTarget( User $target, User $sender ): StatusValue {
|
2023-03-11 16:00:50 +00:00
|
|
|
if ( !$target->getId() ) {
|
2023-03-11 23:59:30 +00:00
|
|
|
return StatusValue::newFatal( 'emailnotarget' );
|
2023-03-10 15:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$target->isEmailConfirmed() ) {
|
2023-03-11 23:59:30 +00:00
|
|
|
return StatusValue::newFatal( 'noemailtext' );
|
2023-03-10 15:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$target->canReceiveEmail() ) {
|
2023-03-11 23:59:30 +00:00
|
|
|
return StatusValue::newFatal( 'nowikiemailtext' );
|
2023-03-10 15:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-10 19:01:48 +00:00
|
|
|
if ( !$this->userOptionsLookup->getOption( $target, 'email-allow-new-users' ) && $sender->isNewbie() ) {
|
2023-03-11 23:59:30 +00:00
|
|
|
return StatusValue::newFatal( 'nowikiemailtext' );
|
2023-03-10 15:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-10 19:01:48 +00:00
|
|
|
$muteList = $this->userOptionsLookup->getOption(
|
2023-03-10 15:39:41 +00:00
|
|
|
$target,
|
|
|
|
|
'email-blacklist',
|
|
|
|
|
''
|
|
|
|
|
);
|
|
|
|
|
if ( $muteList ) {
|
|
|
|
|
$muteList = MultiUsernameFilter::splitIds( $muteList );
|
2023-03-10 19:01:48 +00:00
|
|
|
$senderId = $this->centralIdLookup->centralIdFromLocalUser( $sender );
|
2023-03-10 15:39:41 +00:00
|
|
|
if ( $senderId !== 0 && in_array( $senderId, $muteList ) ) {
|
2023-03-11 23:59:30 +00:00
|
|
|
return StatusValue::newFatal( 'nowikiemailtext' );
|
2023-03-10 15:39:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-11 23:59:30 +00:00
|
|
|
return StatusValue::newGood();
|
2023-03-10 15:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-10 19:01:48 +00:00
|
|
|
/**
|
|
|
|
|
* @param Config $config
|
|
|
|
|
* @internal Kept only for BC with SpecialEmailUser
|
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
|
*/
|
|
|
|
|
public function overrideOptionsFromConfig( Config $config ): void {
|
|
|
|
|
$this->oldOptions = $this->options;
|
|
|
|
|
$this->options = new ServiceOptions( self::CONSTRUCTOR_OPTIONS, $config );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @internal Kept only for BC with SpecialEmailUser
|
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
|
*/
|
|
|
|
|
public function restoreOriginalOptions(): void {
|
|
|
|
|
if ( !$this->oldOptions ) {
|
|
|
|
|
throw new BadMethodCallException( 'Did not override options.' );
|
|
|
|
|
}
|
|
|
|
|
$this->options = $this->oldOptions;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 15:39:41 +00:00
|
|
|
/**
|
|
|
|
|
* Check whether a user is allowed to send email
|
|
|
|
|
*
|
|
|
|
|
* @param User $user
|
|
|
|
|
* @param string $editToken
|
|
|
|
|
* @return null|string|array Null on success, string on error, or array on
|
|
|
|
|
* hook error
|
|
|
|
|
*/
|
2023-03-11 16:00:50 +00:00
|
|
|
public function getPermissionsError( User $user, string $editToken ) {
|
2023-03-10 19:01:48 +00:00
|
|
|
if (
|
|
|
|
|
!$this->options->get( MainConfigNames::EnableEmail ) ||
|
|
|
|
|
!$this->options->get( MainConfigNames::EnableUserEmail )
|
|
|
|
|
) {
|
2023-03-10 15:39:41 +00:00
|
|
|
return 'usermaildisabled';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run this before checking 'sendemail' permission
|
|
|
|
|
// to show appropriate message to anons (T160309)
|
|
|
|
|
if ( !$user->isEmailConfirmed() ) {
|
|
|
|
|
return 'mailnologin';
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 19:01:48 +00:00
|
|
|
if ( !$this->permissionManager->userHasRight( $user, 'sendemail' ) ) {
|
2023-03-10 15:39:41 +00:00
|
|
|
return 'badaccess';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $user->isBlockedFromEmailuser() ) {
|
|
|
|
|
return "blockedemailuser";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check the ping limiter without incrementing it - we'll check it
|
|
|
|
|
// again later and increment it on a successful send
|
|
|
|
|
if ( $user->pingLimiter( 'sendemail', 0 ) ) {
|
|
|
|
|
return 'actionthrottledtext';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$hookErr = false;
|
|
|
|
|
|
2023-03-10 19:01:48 +00:00
|
|
|
$this->hookRunner->onUserCanSendEmail( $user, $hookErr );
|
|
|
|
|
$this->hookRunner->onEmailUserPermissionsErrors( $user, $editToken, $hookErr );
|
2023-03-10 15:39:41 +00:00
|
|
|
|
|
|
|
|
return $hookErr ?: null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Really send a mail. Permissions should have been checked using
|
|
|
|
|
* getPermissionsError(). It is probably also a good
|
|
|
|
|
* idea to check the edit token and ping limiter in advance.
|
|
|
|
|
*
|
2023-03-10 19:01:48 +00:00
|
|
|
* @param string $targetName
|
|
|
|
|
* @param string $subject
|
|
|
|
|
* @param string $text
|
|
|
|
|
* @param bool $CCMe
|
|
|
|
|
* @param User $sender
|
|
|
|
|
* @param MessageLocalizer $messageLocalizer
|
2023-03-11 16:00:50 +00:00
|
|
|
* @return StatusValue
|
2023-03-10 15:39:41 +00:00
|
|
|
*/
|
2023-03-10 19:01:48 +00:00
|
|
|
public function submit(
|
2023-03-11 16:00:50 +00:00
|
|
|
string $targetName,
|
|
|
|
|
string $subject,
|
|
|
|
|
string $text,
|
|
|
|
|
bool $CCMe,
|
2023-03-10 19:01:48 +00:00
|
|
|
User $sender,
|
|
|
|
|
MessageLocalizer $messageLocalizer
|
2023-03-11 16:00:50 +00:00
|
|
|
): StatusValue {
|
2023-03-11 23:59:30 +00:00
|
|
|
$targetStatus = $this->getTarget( $targetName, $sender );
|
|
|
|
|
if ( !$targetStatus->isGood() ) {
|
|
|
|
|
return $targetStatus;
|
2023-03-10 15:39:41 +00:00
|
|
|
}
|
2023-03-11 23:59:30 +00:00
|
|
|
$target = $targetStatus->getValue();
|
2023-03-10 15:39:41 +00:00
|
|
|
|
|
|
|
|
$toAddress = MailAddress::newFromUser( $target );
|
|
|
|
|
$fromAddress = MailAddress::newFromUser( $sender );
|
|
|
|
|
|
|
|
|
|
// Add a standard footer and trim up trailing newlines
|
|
|
|
|
$text = rtrim( $text ) . "\n\n-- \n";
|
2023-03-10 19:01:48 +00:00
|
|
|
$text .= $messageLocalizer->msg(
|
2023-03-10 15:39:41 +00:00
|
|
|
'emailuserfooter',
|
|
|
|
|
$fromAddress->name,
|
|
|
|
|
$toAddress->name
|
|
|
|
|
)->inContentLanguage()->text();
|
|
|
|
|
|
2023-03-10 19:01:48 +00:00
|
|
|
if ( $this->options->get( MainConfigNames::EnableSpecialMute ) ) {
|
|
|
|
|
$text .= "\n" . $messageLocalizer->msg(
|
2023-03-10 15:39:41 +00:00
|
|
|
'specialmute-email-footer',
|
2023-03-10 19:01:48 +00:00
|
|
|
$this->getSpecialMuteCanonicalURL( $sender->getName() ),
|
2023-03-10 15:39:41 +00:00
|
|
|
$sender->getName()
|
|
|
|
|
)->inContentLanguage()->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check and increment the rate limits
|
|
|
|
|
if ( $sender->pingLimiter( 'sendemail' ) ) {
|
2023-03-10 19:01:48 +00:00
|
|
|
throw $this->getThrottledError();
|
2023-03-10 15:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$error = false;
|
2023-03-11 16:00:50 +00:00
|
|
|
// FIXME Replace this hook with a new one that returns errors in a SINGLE format.
|
2023-03-10 19:01:48 +00:00
|
|
|
if ( !$this->hookRunner->onEmailUser( $toAddress, $fromAddress, $subject, $text, $error ) ) {
|
2023-03-11 16:00:50 +00:00
|
|
|
if ( $error instanceof StatusValue ) {
|
2023-03-10 15:39:41 +00:00
|
|
|
return $error;
|
|
|
|
|
} elseif ( $error === false || $error === '' || $error === [] ) {
|
|
|
|
|
// Possibly to tell HTMLForm to pretend there was no submission?
|
2023-03-11 16:00:50 +00:00
|
|
|
return StatusValue::newFatal( 'hookaborted' );
|
2023-03-10 15:39:41 +00:00
|
|
|
} elseif ( $error === true ) {
|
|
|
|
|
// Hook sent the mail itself and indicates success?
|
2023-03-11 16:00:50 +00:00
|
|
|
return StatusValue::newGood();
|
2023-03-10 15:39:41 +00:00
|
|
|
} elseif ( is_array( $error ) ) {
|
2023-03-11 16:00:50 +00:00
|
|
|
$status = StatusValue::newGood();
|
2023-03-10 15:39:41 +00:00
|
|
|
foreach ( $error as $e ) {
|
|
|
|
|
$status->fatal( $e );
|
|
|
|
|
}
|
|
|
|
|
return $status;
|
|
|
|
|
} elseif ( $error instanceof MessageSpecifier ) {
|
2023-03-11 16:00:50 +00:00
|
|
|
return StatusValue::newFatal( $error );
|
2023-03-10 15:39:41 +00:00
|
|
|
} else {
|
|
|
|
|
// Setting $error to something else was deprecated in 1.29 and
|
|
|
|
|
// removed in 1.36, and so an exception is now thrown
|
|
|
|
|
$type = is_object( $error ) ? get_class( $error ) : gettype( $error );
|
2023-03-10 19:01:48 +00:00
|
|
|
throw new UnexpectedValueException(
|
2023-03-10 15:39:41 +00:00
|
|
|
'EmailUser hook set $error to unsupported type ' . $type
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-11 16:00:50 +00:00
|
|
|
[ $mailFrom, $replyTo ] = $this->getFromAndReplyTo( $fromAddress, $messageLocalizer );
|
2023-03-10 15:39:41 +00:00
|
|
|
|
2023-03-11 16:00:50 +00:00
|
|
|
$status = $this->emailer->send(
|
2023-03-10 15:39:41 +00:00
|
|
|
$toAddress,
|
|
|
|
|
$mailFrom,
|
|
|
|
|
$subject,
|
|
|
|
|
$text,
|
|
|
|
|
null,
|
|
|
|
|
[ 'replyTo' => $replyTo ]
|
2023-03-11 16:00:50 +00:00
|
|
|
);
|
2023-03-10 15:39:41 +00:00
|
|
|
|
|
|
|
|
if ( !$status->isGood() ) {
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if the user requested a copy of this mail, do this now,
|
|
|
|
|
// unless they are emailing themselves, in which case one
|
|
|
|
|
// copy of the message is sufficient.
|
2023-03-11 16:00:50 +00:00
|
|
|
if ( $CCMe && !$toAddress->equals( $fromAddress ) ) {
|
2023-03-10 15:39:41 +00:00
|
|
|
$ccTo = $fromAddress;
|
|
|
|
|
$ccFrom = $fromAddress;
|
2023-03-10 19:01:48 +00:00
|
|
|
$ccSubject = $messageLocalizer->msg( 'emailccsubject' )->plaintextParams(
|
2023-03-10 15:39:41 +00:00
|
|
|
$target->getName(),
|
|
|
|
|
$subject
|
|
|
|
|
)->text();
|
|
|
|
|
$ccText = $text;
|
|
|
|
|
|
2023-03-10 19:01:48 +00:00
|
|
|
$this->hookRunner->onEmailUserCC( $ccTo, $ccFrom, $ccSubject, $ccText );
|
2023-03-10 15:39:41 +00:00
|
|
|
|
2023-03-11 16:00:50 +00:00
|
|
|
[ $mailFrom, $replyTo ] = $this->getFromAndReplyTo( $ccFrom, $messageLocalizer );
|
2023-03-10 15:39:41 +00:00
|
|
|
|
2023-03-10 19:01:48 +00:00
|
|
|
$ccStatus = $this->emailer->send(
|
2023-03-10 15:39:41 +00:00
|
|
|
$ccTo,
|
|
|
|
|
$mailFrom,
|
|
|
|
|
$ccSubject,
|
|
|
|
|
$ccText,
|
|
|
|
|
null,
|
|
|
|
|
[ 'replyTo' => $replyTo ]
|
|
|
|
|
);
|
|
|
|
|
$status->merge( $ccStatus );
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 19:01:48 +00:00
|
|
|
$this->hookRunner->onEmailUserComplete( $toAddress, $fromAddress, $subject, $text );
|
2023-03-10 15:39:41 +00:00
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
2023-03-10 19:01:48 +00:00
|
|
|
|
2023-03-11 16:00:50 +00:00
|
|
|
/**
|
|
|
|
|
* @param MailAddress $fromAddress
|
|
|
|
|
* @param MessageLocalizer $messageLocalizer
|
|
|
|
|
* @return array
|
|
|
|
|
* @phan-return array{0:MailAddress,1:?MailAddress}
|
|
|
|
|
*/
|
|
|
|
|
private function getFromAndReplyTo( MailAddress $fromAddress, MessageLocalizer $messageLocalizer ): array {
|
|
|
|
|
if ( $this->options->get( MainConfigNames::UserEmailUseReplyTo ) ) {
|
|
|
|
|
/**
|
|
|
|
|
* Put the generic wiki autogenerated address in the From:
|
|
|
|
|
* header and reserve the user for Reply-To.
|
|
|
|
|
*
|
|
|
|
|
* This is a bit ugly, but will serve to differentiate
|
|
|
|
|
* wiki-borne mails from direct mails and protects against
|
|
|
|
|
* SPF and bounce problems with some mailers (see below).
|
|
|
|
|
*/
|
|
|
|
|
$mailFrom = new MailAddress(
|
|
|
|
|
$this->options->get( MainConfigNames::PasswordSender ),
|
|
|
|
|
$messageLocalizer->msg( 'emailsender' )->inContentLanguage()->text()
|
|
|
|
|
);
|
|
|
|
|
$replyTo = $fromAddress;
|
|
|
|
|
} else {
|
|
|
|
|
/**
|
|
|
|
|
* Put the sending user's e-mail address in the From: header.
|
|
|
|
|
*
|
|
|
|
|
* This is clean-looking and convenient, but has issues.
|
|
|
|
|
* One is that it doesn't as clearly differentiate the wiki mail
|
|
|
|
|
* from "directly" sent mails.
|
|
|
|
|
*
|
|
|
|
|
* Another is that some mailers (like sSMTP) will use the From
|
|
|
|
|
* address as the envelope sender as well. For open sites this
|
|
|
|
|
* can cause mails to be flunked for SPF violations (since the
|
|
|
|
|
* wiki server isn't an authorized sender for various users'
|
|
|
|
|
* domains) as well as creating a privacy issue as bounces
|
|
|
|
|
* containing the recipient's e-mail address may get sent to
|
|
|
|
|
* the sending user.
|
|
|
|
|
*/
|
|
|
|
|
$mailFrom = $fromAddress;
|
|
|
|
|
$replyTo = null;
|
|
|
|
|
}
|
|
|
|
|
return [ $mailFrom, $replyTo ];
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 19:01:48 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $targetName
|
|
|
|
|
* @return string
|
|
|
|
|
* XXX This code is still heavily reliant on global state, so temporarily skip it in tests.
|
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
|
*/
|
|
|
|
|
private function getSpecialMuteCanonicalURL( string $targetName ): string {
|
|
|
|
|
if ( defined( 'MW_PHPUNIT_TEST' ) ) {
|
|
|
|
|
return "Ceci n'est pas une URL";
|
|
|
|
|
}
|
|
|
|
|
return SpecialPage::getTitleFor( 'Mute', $targetName )->getCanonicalURL();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return RuntimeException|ThrottledError
|
|
|
|
|
* XXX ErrorPageError (that ThrottledError inherits from) runs heavy logic involving the global state in the
|
|
|
|
|
* constructor, and cannot be used in unit tests. See T281935.
|
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
|
*/
|
|
|
|
|
private function getThrottledError() {
|
|
|
|
|
if ( defined( 'MW_PHPUNIT_TEST' ) ) {
|
|
|
|
|
return new RuntimeException( "You are throttled, and I am not running heavy logic in the constructor" );
|
|
|
|
|
}
|
|
|
|
|
return new ThrottledError();
|
|
|
|
|
}
|
2023-03-10 15:39:41 +00:00
|
|
|
}
|