/** * @covers MailAddress::newFromUser */ public function testNewFromUser() { $user = $this->getMock('User'); $user->expects($this->any())->method('getName')->will($this->returnValue('UserName')); $user->expects($this->any())->method('getEmail')->will($this->returnValue('*****@*****.**')); $user->expects($this->any())->method('getRealName')->will($this->returnValue('Real name')); $ma = MailAddress::newFromUser($user); $this->assertInstanceOf('MailAddress', $ma); $this->setMwGlobals('wgEnotifUseRealName', true); $this->assertEquals('Real name <*****@*****.**>', $ma->toString()); $this->setMwGlobals('wgEnotifUseRealName', false); $this->assertEquals('UserName <*****@*****.**>', $ma->toString()); }
/** * @covers MailAddress::newFromUser */ public function testNewFromUser() { if (wfIsWindows()) { $this->markTestSkipped('This test only works on non-Windows platforms'); } $user = $this->getMock('User'); $user->expects($this->any())->method('getName')->will($this->returnValue('UserName')); $user->expects($this->any())->method('getEmail')->will($this->returnValue('*****@*****.**')); $user->expects($this->any())->method('getRealName')->will($this->returnValue('Real name')); $ma = MailAddress::newFromUser($user); $this->assertInstanceOf('MailAddress', $ma); $this->setMwGlobals('wgEnotifUseRealName', true); $this->assertEquals('Real name <*****@*****.**>', $ma->toString()); $this->setMwGlobals('wgEnotifUseRealName', false); $this->assertEquals('UserName <*****@*****.**>', $ma->toString()); }
protected function doResolveRequest($approved, $data) { $request = GlobalRenameRequest::newFromId($data['rid']); $oldUser = User::newFromName($request->getName()); if ($request->userIsGlobal() || $request->getWiki() === wfWikiId()) { $notifyEmail = MailAddress::newFromUser($oldUser); } else { $notifyEmail = $this->getRemoteUserMailAddress($request->getWiki(), $request->getName()); } $newUser = User::newFromName($request->getNewName(), 'creatable'); $status = new Status(); $session = $this->getContext()->exportSession(); if ($approved) { if ($request->userIsGlobal()) { // Trigger a global rename job $globalRenameUser = new GlobalRenameUser($this->getUser(), $oldUser, CentralAuthUser::getInstance($oldUser), $newUser, CentralAuthUser::getInstance($newUser), new GlobalRenameUserStatus($newUser->getName()), 'JobQueueGroup::singleton', new GlobalRenameUserDatabaseUpdates(), new GlobalRenameUserLogger($this->getUser()), $session); $status = $globalRenameUser->rename($data); } else { // If the user is local-only: // * rename the local user using LocalRenameUserJob // * create a global user attached only to the local wiki $job = new LocalRenameUserJob(Title::newFromText('Global rename job'), array('from' => $oldUser->getName(), 'to' => $newUser->getName(), 'renamer' => $this->getUser()->getName(), 'movepages' => true, 'suppressredirects' => true, 'promotetoglobal' => true, 'reason' => $data['reason'], 'session' => $session)); JobQueueGroup::singleton($request->getWiki())->push($job); // Now log it $this->logPromotionRename($oldUser->getName(), $request->getWiki(), $newUser->getName(), $data['reason']); $status = Status::newGood(); } } if ($status->isGood()) { $request->setStatus($approved ? GlobalRenameRequest::APPROVED : GlobalRenameRequest::REJECTED); $request->setCompleted(wfTimestampNow()); $request->setPerformer(CentralAuthUser::getInstance($this->getUser())->getId()); $request->setComments($data['comments']); if ($request->save()) { // Send email to the user about the change in status. if ($approved) { $subject = $this->msg('globalrenamequeue-email-subject-approved')->inContentLanguage()->text(); $body = $this->msg('globalrenamequeue-email-body-approved', array($oldUser->getName(), $newUser->getName()))->inContentLanguage()->text(); } else { $subject = $this->msg('globalrenamequeue-email-subject-rejected')->inContentLanguage()->text(); $body = $this->msg('globalrenamequeue-email-body-rejected', array($oldUser->getName(), $newUser->getName(), $request->getComments()))->inContentLanguage()->text(); } if ($notifyEmail !== null && $notifyEmail->address) { $type = $approved ? 'approval' : 'rejection'; wfDebugLog('CentralAuthRename', "Sending {$type} email to User:{$oldUser->getName()}/{$notifyEmail->address}"); $this->sendNotificationEmail($notifyEmail, $subject, $body); } } else { $status->fatal('globalrenamequeue-request-savefailed'); } } return $status; }
/** * Send an e-mail to this user's account. Does not check for * confirmed status or validity. * * @param string $subject Message subject * @param string $body Message body * @param User|null $from Optional sending user; if unspecified, default * $wgPasswordSender will be used. * @param string $replyto Reply-To address * @return Status */ public function sendMail($subject, $body, $from = null, $replyto = null) { global $wgPasswordSender; if ($from instanceof User) { $sender = MailAddress::newFromUser($from); } else { $sender = new MailAddress($wgPasswordSender, wfMessage('emailsender')->inContentLanguage()->text()); } $to = MailAddress::newFromUser($this); return UserMailer::send($to, $sender, $subject, $body, array('replyTo' => $replyto)); }
/** * 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. * * @param array $data * @param IContextSource $context * @return Status|string|bool Status object, or potentially a String on error * or maybe even true on success if anything uses the EmailUser hook. */ public static function submit(array $data, IContextSource $context) { $config = $context->getConfig(); $target = self::getTarget($data['Target']); if (!$target instanceof User) { // Messages used here: notargettext, noemailtext, nowikiemailtext return $context->msg($target . 'text')->parseAsBlock(); } $to = MailAddress::newFromUser($target); $from = MailAddress::newFromUser($context->getUser()); $subject = $data['Subject']; $text = $data['Text']; // Add a standard footer and trim up trailing newlines $text = rtrim($text) . "\n\n-- \n"; $text .= $context->msg('emailuserfooter', $from->name, $to->name)->inContentLanguage()->text(); $error = ''; if (!Hooks::run('EmailUser', array(&$to, &$from, &$subject, &$text, &$error))) { return $error; } if ($config->get('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($config->get('PasswordSender'), wfMessage('emailsender')->inContentLanguage()->text()); $replyTo = $from; } 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 = $from; $replyTo = null; } $status = UserMailer::send($to, $mailFrom, $subject, $text, array('replyTo' => $replyTo)); if (!$status->isGood()) { return $status; } else { // 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. if ($data['CCMe'] && $to != $from) { $cc_subject = $context->msg('emailccsubject')->rawParams($target->getName(), $subject)->text(); // target and sender are equal, because this is the CC for the sender Hooks::run('EmailUserCC', array(&$from, &$from, &$cc_subject, &$text)); $ccStatus = UserMailer::send($from, $from, $cc_subject, $text); $status->merge($ccStatus); } Hooks::run('EmailUserComplete', array($to, $from, $subject, $text)); return $status; } }
/** * Does the per-user customizations to a notification e-mail (name, * timestamp in proper timezone, etc) and sends it out. * Returns true if the mail was sent successfully. * * @param User $watchingUser * @return bool * @private */ function sendPersonalised($watchingUser) { global $wgContLang, $wgEnotifUseRealName; // From the PHP manual: // Note: The to parameter cannot be an address in the form of // "Something <*****@*****.**>". The mail command will not parse // this properly while talking with the MTA. $to = MailAddress::newFromUser($watchingUser); # $PAGEEDITDATE is the time and date of the page change # expressed in terms of individual local time of the notification # recipient, i.e. watching user $body = str_replace(array('$WATCHINGUSERNAME', '$PAGEEDITDATE', '$PAGEEDITTIME'), array($wgEnotifUseRealName && $watchingUser->getRealName() !== '' ? $watchingUser->getRealName() : $watchingUser->getName(), $wgContLang->userDate($this->timestamp, $watchingUser), $wgContLang->userTime($this->timestamp, $watchingUser)), $this->body); return UserMailer::send($to, $this->from, $this->subject, $body, $this->replyto); }
/** * Does the per-user customizations to a notification e-mail (name, * timestamp in proper timezone, etc) and sends it out. * Returns true if the mail was sent successfully. * * @param User $watchingUser * @param string $source * @return bool * @private */ function sendPersonalised($watchingUser, $source) { global $wgContLang, $wgEnotifUseRealName; // From the PHP manual: // Note: The to parameter cannot be an address in the form of // "Something <*****@*****.**>". The mail command will not parse // this properly while talking with the MTA. $to = MailAddress::newFromUser($watchingUser); # $PAGEEDITDATE is the time and date of the page change # expressed in terms of individual local time of the notification # recipient, i.e. watching user $body = str_replace(array('$WATCHINGUSERNAME', '$PAGEEDITDATE', '$PAGEEDITTIME'), array($wgEnotifUseRealName && $watchingUser->getRealName() !== '' ? $watchingUser->getRealName() : $watchingUser->getName(), $wgContLang->userDate($this->timestamp, $watchingUser), $wgContLang->userTime($this->timestamp, $watchingUser)), $this->body); $headers = array(); if ($source === self::WATCHLIST) { $headers['List-Help'] = 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Watchlist'; } return UserMailer::send($to, $this->from, $this->subject, $body, array('replyTo' => $this->replyto, 'headers' => $headers)); }