wfDebug( "Target is invalid user.\n" );
return 'notarget';
- } elseif ( !$target->isEmailConfirmed() ) {
+ }
+
+ if ( !$target->isEmailConfirmed() ) {
wfDebug( "User has no valid email.\n" );
return 'noemail';
- } elseif ( !$target->canReceiveEmail() ) {
+ }
+
+ if ( !$target->canReceiveEmail() ) {
wfDebug( "User does not allow user emails.\n" );
return 'nowikiemail';
- } elseif ( $sender !== null ) {
+ }
+
+ if ( $sender !== null && !$target->getOption( 'email-allow-new-users' ) &&
+ $sender->isNewbie()
+ ) {
+ wfDebug( "User does not allow user emails from new users.\n" );
+
+ return 'nowikiemail';
+ }
+
+ if ( $sender !== null ) {
$blacklist = $target->getOption( 'email-blacklist', [] );
if ( $blacklist ) {
$lookup = CentralIdLookup::factory();
return "blockedemailuser";
}
- if ( $user->pingLimiter( 'emailuser' ) ) {
+ // Check the ping limiter without incrementing it - we'll check it
+ // again later and increment it on a successful send
+ if ( $user->pingLimiter( 'emailuser', 0 ) ) {
wfDebug( "Ping limiter triggered.\n" );
return 'actionthrottledtext';
$text .= $context->msg( 'emailuserfooter',
$from->name, $to->name )->inContentLanguage()->text();
+ // Check and increment the rate limits
+ if ( $context->getUser()->pingLimiter( 'emailuser' ) ) {
+ throw new ThrottledError();
+ }
+
$error = false;
if ( !Hooks::run( 'EmailUser', [ &$to, &$from, &$subject, &$text, &$error ] ) ) {
if ( $error instanceof Status ) {