MediaWiki  REL1_19
UserMailer.php
Go to the documentation of this file.
00001 <?php
00032 class MailAddress {
00038         function __construct( $address, $name = null, $realName = null ) {
00039                 if ( is_object( $address ) && $address instanceof User ) {
00040                         $this->address = $address->getEmail();
00041                         $this->name = $address->getName();
00042                         $this->realName = $address->getRealName();
00043                 } else {
00044                         $this->address = strval( $address );
00045                         $this->name = strval( $name );
00046                         $this->realName = strval( $realName );
00047                 }
00048         }
00049 
00054         function toString() {
00055                 # PHP's mail() implementation under Windows is somewhat shite, and
00056                 # can't handle "Joe Bloggs <[email protected]>" format email addresses,
00057                 # so don't bother generating them
00058                 if ( $this->address ) {
00059                         if ( $this->name != '' && !wfIsWindows() ) {
00060                                 global $wgEnotifUseRealName;
00061                                 $name = ( $wgEnotifUseRealName && $this->realName ) ? $this->realName : $this->name;
00062                                 $quoted = UserMailer::quotedPrintable( $name );
00063                                 if ( strpos( $quoted, '.' ) !== false || strpos( $quoted, ',' ) !== false ) {
00064                                         $quoted = '"' . $quoted . '"';
00065                                 }
00066                                 return "$quoted <{$this->address}>";
00067                         } else {
00068                                 return $this->address;
00069                         }
00070                 } else {
00071                         return "";
00072                 }
00073         }
00074 
00075         function __toString() {
00076                 return $this->toString();
00077         }
00078 }
00079 
00080 
00084 class UserMailer {
00085         static $mErrorString;
00086 
00097         protected static function sendWithPear( $mailer, $dest, $headers, $body ) {
00098                 $mailResult = $mailer->send( $dest, $headers, $body );
00099 
00100                 # Based on the result return an error string,
00101                 if ( PEAR::isError( $mailResult ) ) {
00102                         wfDebug( "PEAR::Mail failed: " . $mailResult->getMessage() . "\n" );
00103                         return Status::newFatal( 'pear-mail-error', $mailResult->getMessage() );
00104                 } else {
00105                         return Status::newGood();
00106                 }
00107         }
00108 
00117         static function arrayToHeaderString( $headers, $endl = "\n" ) {
00118                 foreach( $headers as $name => $value ) {
00119                         $string[] = "$name: $value";
00120                 }
00121                 return implode( $endl, $string );
00122         }
00123 
00129         static function makeMsgId() {
00130                 global $wgSMTP, $wgServer;
00131 
00132                 $msgid = uniqid( wfWikiID() . ".", true ); /* true required for cygwin */
00133                 if ( is_array($wgSMTP) && isset($wgSMTP['IDHost']) && $wgSMTP['IDHost'] ) {
00134                         $domain = $wgSMTP['IDHost'];
00135                 } else {
00136                         $url = wfParseUrl($wgServer);
00137                         $domain = $url['host'];
00138                 }
00139                 return "<$msgid@$domain>";
00140         }
00141 
00156         public static function send( $to, $from, $subject, $body, $replyto = null, $contentType = 'text/plain; charset=UTF-8' ) {
00157                 global $wgSMTP, $wgEnotifMaxRecips, $wgAdditionalMailParams;
00158 
00159                 if ( !is_array( $to ) ) {
00160                         $to = array( $to );
00161                 }
00162 
00163                 wfDebug( __METHOD__ . ': sending mail to ' . implode( ', ', $to ) . "\n" );
00164 
00165                 # Make sure we have at least one address
00166                 $has_address = false;
00167                 foreach ( $to as $u ) {
00168                         if ( $u->address ) {
00169                                 $has_address = true;
00170                                 break;
00171                         }
00172                 }
00173                 if ( !$has_address ) {
00174                         return Status::newFatal( 'user-mail-no-addy' );
00175                 }
00176 
00177                 # Forge email headers
00178                 # -------------------
00179                 #
00180                 # WARNING
00181                 #
00182                 # DO NOT add To: or Subject: headers at this step. They need to be
00183                 # handled differently depending upon the mailer we are going to use.
00184                 #
00185                 # To:
00186                 #  PHP mail() first argument is the mail receiver. The argument is
00187                 #  used as a recipient destination and as a To header.
00188                 #
00189                 #  PEAR mailer has a recipient argument which is only used to
00190                 #  send the mail. If no To header is given, PEAR will set it to
00191                 #  to 'undisclosed-recipients:'.
00192                 #
00193                 #  NOTE: To: is for presentation, the actual recipient is specified
00194                 #  by the mailer using the Rcpt-To: header.
00195                 #
00196                 # Subject: 
00197                 #  PHP mail() second argument to pass the subject, passing a Subject
00198                 #  as an additional header will result in a duplicate header.
00199                 #
00200                 #  PEAR mailer should be passed a Subject header.
00201                 #
00202                 # -- hashar 20120218
00203 
00204                 $headers['From'] = $from->toString();
00205                 $headers['Return-Path'] = $from->address;
00206 
00207                 if ( $replyto ) {
00208                         $headers['Reply-To'] = $replyto->toString();
00209                 }
00210 
00211                 $headers['Date'] = date( 'r' );
00212                 $headers['MIME-Version'] = '1.0';
00213                 $headers['Content-type'] = ( is_null( $contentType ) ?
00214                         'text/plain; charset=UTF-8' : $contentType );
00215                 $headers['Content-transfer-encoding'] = '8bit';
00216 
00217                 $headers['Message-ID'] = self::makeMsgId();
00218                 $headers['X-Mailer'] = 'MediaWiki mailer';
00219 
00220                 $ret = wfRunHooks( 'AlternateUserMailer', array( $headers, $to, $from, $subject, $body ) );
00221                 if ( $ret === false ) {
00222                         return Status::newGood();
00223                 } elseif ( $ret !== true ) {
00224                         return Status::newFatal( 'php-mail-error', $ret );
00225                 }
00226 
00227                 if ( is_array( $wgSMTP ) ) {
00228                         #
00229                         # PEAR MAILER
00230                         # 
00231 
00232                         if ( function_exists( 'stream_resolve_include_path' ) ) {
00233                                 $found = stream_resolve_include_path( 'Mail.php' );
00234                         } else {
00235                                 $found = Fallback::stream_resolve_include_path( 'Mail.php' );
00236                         }
00237                         if ( !$found ) {
00238                                 throw new MWException( 'PEAR mail package is not installed' );
00239                         }
00240                         require_once( 'Mail.php' );
00241 
00242                         wfSuppressWarnings();
00243 
00244                         // Create the mail object using the Mail::factory method
00245                         $mail_object =& Mail::factory( 'smtp', $wgSMTP );
00246                         if ( PEAR::isError( $mail_object ) ) {
00247                                 wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" );
00248                                 wfRestoreWarnings();
00249                                 return Status::newFatal( 'pear-mail-error', $mail_object->getMessage() );
00250                         }
00251 
00252                         wfDebug( "Sending mail via PEAR::Mail\n" );
00253 
00254                         $headers['Subject'] = self::quotedPrintable( $subject );
00255 
00256                         # When sending only to one recipient, shows it its email using To:
00257                         if ( count( $to ) == 1 ) {
00258                                 $headers['To'] = $to[0]->toString();
00259                         }
00260 
00261                         # Split jobs since SMTP servers tends to limit the maximum
00262                         # number of possible recipients.        
00263                         $chunks = array_chunk( $to, $wgEnotifMaxRecips );
00264                         foreach ( $chunks as $chunk ) {
00265                                 $status = self::sendWithPear( $mail_object, $chunk, $headers, $body );
00266                                 # FIXME : some chunks might be sent while others are not!
00267                                 if ( !$status->isOK() ) {
00268                                         wfRestoreWarnings();
00269                                         return $status;
00270                                 }
00271                         }
00272                         wfRestoreWarnings();
00273                         return Status::newGood();
00274                 } else  {
00275                         # 
00276                         # PHP mail()
00277                         #
00278 
00279                         # Line endings need to be different on Unix and Windows due to
00280                         # the bug described at http://trac.wordpress.org/ticket/2603
00281                         if ( wfIsWindows() ) {
00282                                 $body = str_replace( "\n", "\r\n", $body );
00283                                 $endl = "\r\n";
00284                         } else {
00285                                 $endl = "\n";
00286                         }
00287 
00288                         if( count($to) > 1 ) {
00289                                 $headers['To'] = 'undisclosed-recipients:;';
00290                         }
00291                         $headers = self::arrayToHeaderString( $headers, $endl );
00292 
00293                         wfDebug( "Sending mail via internal mail() function\n" );
00294 
00295                         self::$mErrorString = '';
00296                         $html_errors = ini_get( 'html_errors' );
00297                         ini_set( 'html_errors', '0' );
00298                         set_error_handler( 'UserMailer::errorHandler' );
00299 
00300                         $safeMode = wfIniGetBool( 'safe_mode' );
00301                         foreach ( $to as $recip ) {
00302                                 if ( $safeMode ) {
00303                                         $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers );
00304                                 } else {
00305                                         $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
00306                                 }
00307                         }
00308 
00309                         restore_error_handler();
00310                         ini_set( 'html_errors', $html_errors );
00311 
00312                         if ( self::$mErrorString ) {
00313                                 wfDebug( "Error sending mail: " . self::$mErrorString . "\n" );
00314                                 return Status::newFatal( 'php-mail-error', self::$mErrorString );
00315                         } elseif ( ! $sent ) {
00316                                 // mail function only tells if there's an error
00317                                 wfDebug( "Unknown error sending mail\n" );
00318                                 return Status::newFatal( 'php-mail-error-unknown' );
00319                         } else {
00320                                 return Status::newGood();
00321                         }
00322                 }
00323         }
00324 
00331         static function errorHandler( $code, $string ) {
00332                 self::$mErrorString = preg_replace( '/^mail\(\)(\s*\[.*?\])?: /', '', $string );
00333         }
00334 
00340         public static function rfc822Phrase( $phrase ) {
00341                 $phrase = strtr( $phrase, array( "\r" => '', "\n" => '', '"' => '' ) );
00342                 return '"' . $phrase . '"';
00343         }
00344 
00349         public static function quotedPrintable( $string, $charset = '' ) {
00350                 # Probably incomplete; see RFC 2045
00351                 if( empty( $charset ) ) {
00352                         $charset = 'UTF-8';
00353                 }
00354                 $charset = strtoupper( $charset );
00355                 $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ?
00356 
00357                 $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff=';
00358                 $replace = $illegal . '\t ?_';
00359                 if( !preg_match( "/[$illegal]/", $string ) ) {
00360                         return $string;
00361                 }
00362                 $out = "=?$charset?Q?";
00363                 $out .= preg_replace_callback( "/([$replace])/",
00364                         array( __CLASS__, 'quotedPrintableCallback' ), $string );
00365                 $out .= '?=';
00366                 return $out;
00367         }
00368 
00369         protected static function quotedPrintableCallback( $matches ) {
00370                 return sprintf( "=%02X", ord( $matches[1] ) );
00371         }
00372 }
00373 
00394 class EmailNotification {
00395         protected $subject, $body, $replyto, $from;
00396         protected $timestamp, $summary, $minorEdit, $oldid, $composed_common;
00397         protected $mailTargets = array();
00398 
00402         protected $title;
00403 
00407         protected $editor;
00408 
00422         public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false ) {
00423                 global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker, $wgEnotifMinorEdits,
00424                         $wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk;
00425 
00426                 if ( $title->getNamespace() < 0 ) {
00427                         return;
00428                 }
00429 
00430                 // Build a list of users to notfiy
00431                 $watchers = array();
00432                 if ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) {
00433                         $dbw = wfGetDB( DB_MASTER );
00434                         $res = $dbw->select( array( 'watchlist' ),
00435                                 array( 'wl_user' ),
00436                                 array(
00437                                         'wl_title' => $title->getDBkey(),
00438                                         'wl_namespace' => $title->getNamespace(),
00439                                         'wl_user != ' . intval( $editor->getID() ),
00440                                         'wl_notificationtimestamp IS NULL',
00441                                 ), __METHOD__
00442                         );
00443                         foreach ( $res as $row ) {
00444                                 $watchers[] = intval( $row->wl_user );
00445                         }
00446                         if ( $watchers ) {
00447                                 // Update wl_notificationtimestamp for all watching users except
00448                                 // the editor
00449                                 $dbw->begin();
00450                                 $dbw->update( 'watchlist',
00451                                         array( /* SET */
00452                                                 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
00453                                         ), array( /* WHERE */
00454                                                 'wl_title' => $title->getDBkey(),
00455                                                 'wl_namespace' => $title->getNamespace(),
00456                                                 'wl_user' => $watchers
00457                                         ), __METHOD__
00458                                 );
00459                                 $dbw->commit();
00460                         }
00461                 }
00462 
00463                 $sendEmail = true;
00464                 // If nobody is watching the page, and there are no users notified on all changes
00465                 // don't bother creating a job/trying to send emails
00466                 // $watchers deals with $wgEnotifWatchlist
00467                 if ( !count( $watchers ) && !count( $wgUsersNotifiedOnAllChanges ) ) {
00468                         $sendEmail = false;
00469                         // Only send notification for non minor edits, unless $wgEnotifMinorEdits
00470                         if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
00471                                 $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
00472                                 if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) {
00473                                         $sendEmail = true;
00474                                 }
00475                         }
00476                 }
00477 
00478                 if ( !$sendEmail ) {
00479                         return;
00480                 }
00481                 if ( $wgEnotifUseJobQ ) {
00482                         $params = array(
00483                                 'editor' => $editor->getName(),
00484                                 'editorID' => $editor->getID(),
00485                                 'timestamp' => $timestamp,
00486                                 'summary' => $summary,
00487                                 'minorEdit' => $minorEdit,
00488                                 'oldid' => $oldid,
00489                                 'watchers' => $watchers
00490                         );
00491                         $job = new EnotifNotifyJob( $title, $params );
00492                         $job->insert();
00493                 } else {
00494                         $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers );
00495                 }
00496         }
00497 
00512         public function actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers ) {
00513                 # we use $wgPasswordSender as sender's address
00514                 global $wgEnotifWatchlist;
00515                 global $wgEnotifMinorEdits, $wgEnotifUserTalk;
00516 
00517                 wfProfileIn( __METHOD__ );
00518 
00519                 # The following code is only run, if several conditions are met:
00520                 # 1. EmailNotification for pages (other than user_talk pages) must be enabled
00521                 # 2. minor edits (changes) are only regarded if the global flag indicates so
00522 
00523                 $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
00524 
00525                 $this->title = $title;
00526                 $this->timestamp = $timestamp;
00527                 $this->summary = $summary;
00528                 $this->minorEdit = $minorEdit;
00529                 $this->oldid = $oldid;
00530                 $this->editor = $editor;
00531                 $this->composed_common = false;
00532 
00533                 $userTalkId = false;
00534 
00535                 if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
00536 
00537                         if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) {
00538                                 $targetUser = User::newFromName( $title->getText() );
00539                                 $this->compose( $targetUser );
00540                                 $userTalkId = $targetUser->getId();
00541                         }
00542 
00543                         if ( $wgEnotifWatchlist ) {
00544                                 // Send updates to watchers other than the current editor
00545                                 $userArray = UserArray::newFromIDs( $watchers );
00546                                 foreach ( $userArray as $watchingUser ) {
00547                                         if ( $watchingUser->getOption( 'enotifwatchlistpages' ) &&
00548                                                 ( !$minorEdit || $watchingUser->getOption( 'enotifminoredits' ) ) &&
00549                                                 $watchingUser->isEmailConfirmed() &&
00550                                                 $watchingUser->getID() != $userTalkId )
00551                                         {
00552                                                 $this->compose( $watchingUser );
00553                                         }
00554                                 }
00555                         }
00556                 }
00557 
00558                 global $wgUsersNotifiedOnAllChanges;
00559                 foreach ( $wgUsersNotifiedOnAllChanges as $name ) {
00560                         if ( $editor->getName() == $name ) {
00561                                 // No point notifying the user that actually made the change!
00562                                 continue;
00563                         }
00564                         $user = User::newFromName( $name );
00565                         $this->compose( $user );
00566                 }
00567 
00568                 $this->sendMails();
00569                 wfProfileOut( __METHOD__ );
00570         }
00571 
00578         private function canSendUserTalkEmail( $editor, $title, $minorEdit ) {
00579                 global $wgEnotifUserTalk;
00580                 $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
00581 
00582                 if ( $wgEnotifUserTalk && $isUserTalkPage ) {
00583                         $targetUser = User::newFromName( $title->getText() );
00584 
00585                         if ( !$targetUser || $targetUser->isAnon() ) {
00586                                 wfDebug( __METHOD__ . ": user talk page edited, but user does not exist\n" );
00587                         } elseif ( $targetUser->getId() == $editor->getId() ) {
00588                                 wfDebug( __METHOD__ . ": user edited their own talk page, no notification sent\n" );
00589                         } elseif ( $targetUser->getOption( 'enotifusertalkpages' ) &&
00590                                 ( !$minorEdit || $targetUser->getOption( 'enotifminoredits' ) ) )
00591                         {
00592                                 if ( $targetUser->isEmailConfirmed() ) {
00593                                         wfDebug( __METHOD__ . ": sending talk page update notification\n" );
00594                                         return true;
00595                                 } else {
00596                                         wfDebug( __METHOD__ . ": talk page owner doesn't have validated email\n" );
00597                                 }
00598                         } else {
00599                                 wfDebug( __METHOD__ . ": talk page owner doesn't want notifications\n" );
00600                         }
00601                 }
00602                 return false;
00603         }
00604 
00608         private function composeCommonMailtext() {
00609                 global $wgPasswordSender, $wgPasswordSenderName, $wgNoReplyAddress;
00610                 global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress;
00611                 global $wgEnotifImpersonal, $wgEnotifUseRealName;
00612 
00613                 $this->composed_common = true;
00614 
00615                 # You as the WikiAdmin and Sysops can make use of plenty of
00616                 # named variables when composing your notification emails while
00617                 # simply editing the Meta pages
00618 
00619                 $keys = array();
00620                 $postTransformKeys = array();
00621 
00622                 if ( $this->oldid ) {
00623                         if ( $wgEnotifImpersonal ) {
00624                                 // For impersonal mail, show a diff link to the last revision.
00625                                 $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastdiff',
00626                                         $this->title->getCanonicalUrl( 'diff=next&oldid=' . $this->oldid ) );
00627                         } else {
00628                                 $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastvisited',
00629                                         $this->title->getCanonicalUrl( 'diff=0&oldid=' . $this->oldid ) );
00630                         }
00631                         $keys['$OLDID']   = $this->oldid;
00632                         $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'changed' );
00633                 } else {
00634                         $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_newpagetext' );
00635                         # clear $OLDID placeholder in the message template
00636                         $keys['$OLDID']   = '';
00637                         $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'created' );
00638                 }
00639 
00640                 $keys['$PAGETITLE'] = $this->title->getPrefixedText();
00641                 $keys['$PAGETITLE_URL'] = $this->title->getCanonicalUrl();
00642                 $keys['$PAGEMINOREDIT'] = $this->minorEdit ? wfMsgForContent( 'minoredit' ) : '';
00643                 $keys['$UNWATCHURL'] = $this->title->getCanonicalUrl( 'action=unwatch' );
00644 
00645                 if ( $this->editor->isAnon() ) {
00646                         # real anon (user:xxx.xxx.xxx.xxx)
00647                         $keys['$PAGEEDITOR'] = wfMsgForContent( 'enotif_anon_editor', $this->editor->getName() );
00648                         $keys['$PAGEEDITOR_EMAIL'] = wfMsgForContent( 'noemailtitle' );
00649                 } else {
00650                         $keys['$PAGEEDITOR'] = $wgEnotifUseRealName ? $this->editor->getRealName() : $this->editor->getName();
00651                         $emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $this->editor->getName() );
00652                         $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getCanonicalUrl();
00653                 }
00654 
00655                 $keys['$PAGEEDITOR_WIKI'] = $this->editor->getUserPage()->getCanonicalUrl();
00656 
00657                 # Replace this after transforming the message, bug 35019
00658                 $postTransformKeys['$PAGESUMMARY'] = $this->summary == '' ? ' - ' : $this->summary;
00659 
00660                 # Now build message's subject and body
00661 
00662                 $subject = wfMsgExt( 'enotif_subject', 'content' );
00663                 $subject = strtr( $subject, $keys );
00664                 $subject = MessageCache::singleton()->transform( $subject, false, null, $this->title );
00665                 $this->subject = strtr( $subject, $postTransformKeys );
00666 
00667                 $body = wfMsgExt( 'enotif_body', 'content' );
00668                 $body = strtr( $body, $keys );
00669                 $body = MessageCache::singleton()->transform( $body, false, null, $this->title );
00670                 $this->body = wordwrap( strtr( $body, $postTransformKeys ), 72 );
00671 
00672                 # Reveal the page editor's address as REPLY-TO address only if
00673                 # the user has not opted-out and the option is enabled at the
00674                 # global configuration level.
00675                 $adminAddress = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
00676                 if ( $wgEnotifRevealEditorAddress
00677                         && ( $this->editor->getEmail() != '' )
00678                         && $this->editor->getOption( 'enotifrevealaddr' ) )
00679                 {
00680                         $editorAddress = new MailAddress( $this->editor );
00681                         if ( $wgEnotifFromEditor ) {
00682                                 $this->from    = $editorAddress;
00683                         } else {
00684                                 $this->from    = $adminAddress;
00685                                 $this->replyto = $editorAddress;
00686                         }
00687                 } else {
00688                         $this->from    = $adminAddress;
00689                         $this->replyto = new MailAddress( $wgNoReplyAddress );
00690                 }
00691         }
00692 
00700         function compose( $user ) {
00701                 global $wgEnotifImpersonal;
00702 
00703                 if ( !$this->composed_common )
00704                         $this->composeCommonMailtext();
00705 
00706                 if ( $wgEnotifImpersonal ) {
00707                         $this->mailTargets[] = new MailAddress( $user );
00708                 } else {
00709                         $this->sendPersonalised( $user );
00710                 }
00711         }
00712 
00716         function sendMails() {
00717                 global $wgEnotifImpersonal;
00718                 if ( $wgEnotifImpersonal ) {
00719                         $this->sendImpersonal( $this->mailTargets );
00720                 }
00721         }
00722 
00732         function sendPersonalised( $watchingUser ) {
00733                 global $wgContLang, $wgEnotifUseRealName;
00734                 // From the PHP manual:
00735                 //     Note:  The to parameter cannot be an address in the form of "Something <[email protected]>".
00736                 //     The mail command will not parse this properly while talking with the MTA.
00737                 $to = new MailAddress( $watchingUser );
00738 
00739                 # $PAGEEDITDATE is the time and date of the page change
00740                 # expressed in terms of individual local time of the notification
00741                 # recipient, i.e. watching user
00742                 $body = str_replace(
00743                         array( '$WATCHINGUSERNAME',
00744                                 '$PAGEEDITDATE',
00745                                 '$PAGEEDITTIME' ),
00746                         array( $wgEnotifUseRealName ? $watchingUser->getRealName() : $watchingUser->getName(),
00747                                 $wgContLang->userDate( $this->timestamp, $watchingUser ),
00748                                 $wgContLang->userTime( $this->timestamp, $watchingUser ) ),
00749                         $this->body );
00750 
00751                 return UserMailer::send( $to, $this->from, $this->subject, $body, $this->replyto );
00752         }
00753 
00758         function sendImpersonal( $addresses ) {
00759                 global $wgContLang;
00760 
00761                 if ( empty( $addresses ) )
00762                         return;
00763 
00764                 $body = str_replace(
00765                                 array( '$WATCHINGUSERNAME',
00766                                         '$PAGEEDITDATE',
00767                                         '$PAGEEDITTIME' ),
00768                                 array( wfMsgForContent( 'enotif_impersonal_salutation' ),
00769                                         $wgContLang->date( $this->timestamp, false, false ),
00770                                         $wgContLang->time( $this->timestamp, false, false ) ),
00771                                 $this->body );
00772 
00773                 return UserMailer::send( $addresses, $this->from, $this->subject, $body, $this->replyto );
00774         }
00775 
00776 } # end of class EmailNotification