re: r93415
[lhc/web/wiklou.git] / includes / UserMailer.php
1 <?php
2 /**
3 * Classes used to send e-mails
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @author <brion@pobox.com>
22 * @author <mail@tgries.de>
23 * @author Tim Starling
24 */
25
26
27 /**
28 * Stores a single person's name and email address.
29 * These are passed in via the constructor, and will be returned in SMTP
30 * header format when requested.
31 */
32 class MailAddress {
33 /**
34 * @param $address string|User string with an email address, or a User object
35 * @param $name String: human-readable name if a string address is given
36 * @param $realName String: human-readable real name if a string address is given
37 */
38 function __construct( $address, $name = null, $realName = null ) {
39 if ( is_object( $address ) && $address instanceof User ) {
40 $this->address = $address->getEmail();
41 $this->name = $address->getName();
42 $this->realName = $address->getRealName();
43 } else {
44 $this->address = strval( $address );
45 $this->name = strval( $name );
46 $this->realName = strval( $realName );
47 }
48 }
49
50 /**
51 * Return formatted and quoted address to insert into SMTP headers
52 * @return string
53 */
54 function toString() {
55 # PHP's mail() implementation under Windows is somewhat shite, and
56 # can't handle "Joe Bloggs <joe@bloggs.com>" format email addresses,
57 # so don't bother generating them
58 if ( $this->address ) {
59 if ( $this->name != '' && !wfIsWindows() ) {
60 global $wgEnotifUseRealName;
61 $name = ( $wgEnotifUseRealName && $this->realName ) ? $this->realName : $this->name;
62 $quoted = UserMailer::quotedPrintable( $name );
63 if ( strpos( $quoted, '.' ) !== false || strpos( $quoted, ',' ) !== false ) {
64 $quoted = '"' . $quoted . '"';
65 }
66 return "$quoted <{$this->address}>";
67 } else {
68 return $this->address;
69 }
70 } else {
71 return "";
72 }
73 }
74
75 function __toString() {
76 return $this->toString();
77 }
78 }
79
80
81 /**
82 * Collection of static functions for sending mail
83 */
84 class UserMailer {
85 static $mErrorString;
86
87 /**
88 * Send mail using a PEAR mailer
89 *
90 * @param $mailer
91 * @param $dest
92 * @param $headers
93 * @param $body
94 *
95 * @return Status
96 */
97 protected static function sendWithPear( $mailer, $dest, $headers, $body ) {
98 $mailResult = $mailer->send( $dest, $headers, $body );
99
100 # Based on the result return an error string,
101 if ( PEAR::isError( $mailResult ) ) {
102 wfDebug( "PEAR::Mail failed: " . $mailResult->getMessage() . "\n" );
103 return Status::newFatal( 'pear-mail-error', $mailResult->getMessage() );
104 } else {
105 return Status::newGood();
106 }
107 }
108
109 /**
110 * Creates a single string from an associative array
111 *
112 * @param $header Associative Array: keys are header field names,
113 * values are ... values.
114 * @param $endl String: The end of line character. Defaults to "\n"
115 * @return String
116 */
117 static function arrayToHeaderString( $headers, $endl = "\n" ) {
118 foreach( $headers as $name => $value ) {
119 $string[] = "$name: $value";
120 }
121 return implode( $endl, $string );
122 }
123
124 /**
125 * Create a value suitable for the MessageId Header
126 *
127 * @return String
128 */
129 static function makeMsgId() {
130 global $wgServer;
131
132 $msgid = uniqid( "UserMailer", true ); /* true required for cygwin */
133 return "<$msgid@$wgServer>";
134 }
135
136 /**
137 * This function will perform a direct (authenticated) login to
138 * a SMTP Server to use for mail relaying if 'wgSMTP' specifies an
139 * array of parameters. It requires PEAR:Mail to do that.
140 * Otherwise it just uses the standard PHP 'mail' function.
141 *
142 * @param $to MailAddress: recipient's email (or an array of them)
143 * @param $from MailAddress: sender's email
144 * @param $subject String: email's subject.
145 * @param $body String: email's text.
146 * @param $replyto MailAddress: optional reply-to email (default: null).
147 * @param $contentType String: optional custom Content-Type (default: text/plain; charset=UTF-8)
148 * @return Status object
149 */
150 public static function send( $to, $from, $subject, $body, $replyto = null, $contentType = 'text/plain; charset=UTF-8' ) {
151 global $wgSMTP, $wgEnotifImpersonal;
152 global $wgEnotifMaxRecips, $wgAdditionalMailParams;
153
154 $emails = '';
155 wfDebug( __METHOD__ . ': sending mail to ' . implode( ',', array( $to->toString() ) ) . "\n" );
156
157 $headers['From'] = $from->toString();
158 $headers['Return-Path'] = $from->toString();
159
160 $dest = array();
161 if ( is_array( $to ) ) {
162 foreach ( $to as $u ) {
163 if ( $u->address ) {
164 $dest[] = $u->address;
165 }
166 }
167 } else if( $to->address ) {
168 $dest[] = $to->address;
169 }
170 if ( count( $dest ) == 0 ) {
171 return Status::newFatal( 'user-mail-no-addy' );
172 }
173
174 if ( $wgEnotifImpersonal ) {
175 $headers['To'] = 'undisclosed-recipients:;';
176 }
177 else {
178 $headers['To'] = implode( ", ", $dest );
179 }
180
181 if ( $replyto ) {
182 $headers['Reply-To'] = $replyto->toString();
183 }
184 $headers['Subject'] = self::quotedPrintable( $subject );
185 $headers['Date'] = date( 'r' );
186 $headers['MIME-Version'] = '1.0';
187 $headers['Content-type'] = ( is_null( $contentType ) ?
188 'text/plain; charset=UTF-8' : $contentType );
189 $headers['Content-transfer-encoding'] = '8bit';
190
191 $headers['Message-ID'] = self::makeMsgId();
192 $headers['X-Mailer'] = 'MediaWiki mailer';
193 $headers['From'] = $from->toString();
194
195 $ret = wfRunHooks( 'AlternateUserMailer', array( $headers, $to, $from, $subject, $body ) );
196 if ( $ret === false ) {
197 return Status::newGood();
198 } else if ( $ret !== true ) {
199 return Status::newFatal( 'php-mail-error', $ret );
200 }
201
202 if ( is_array( $wgSMTP ) ) {
203 if ( function_exists( 'stream_resolve_include_path' ) ) {
204 $found = stream_resolve_include_path( 'Mail.php' );
205 } else {
206 $found = Fallback::stream_resolve_include_path( 'Mail.php' );
207 }
208 if ( !$found ) {
209 throw new MWException( 'PEAR mail package is not installed' );
210 }
211 require_once( 'Mail.php' );
212
213 wfSuppressWarnings();
214
215 // Create the mail object using the Mail::factory method
216 $mail_object =& Mail::factory( 'smtp', $wgSMTP );
217 if ( PEAR::isError( $mail_object ) ) {
218 wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" );
219 wfRestoreWarnings();
220 return Status::newFatal( 'pear-mail-error', $mail_object->getMessage() );
221 }
222
223 wfDebug( "Sending mail via PEAR::Mail\n" );
224 $chunks = array_chunk( $dest, $wgEnotifMaxRecips );
225 foreach ( $chunks as $chunk ) {
226 $status = self::sendWithPear( $mail_object, $chunk, $headers, $body );
227 if ( !$status->isOK() ) {
228 wfRestoreWarnings();
229 return $status;
230 }
231 }
232 wfRestoreWarnings();
233 return Status::newGood();
234 } else {
235 # Line endings need to be different on Unix and Windows due to
236 # the bug described at http://trac.wordpress.org/ticket/2603
237 if ( wfIsWindows() ) {
238 $body = str_replace( "\n", "\r\n", $body );
239 $endl = "\r\n";
240 } else {
241 $endl = "\n";
242 }
243
244 $headers = self::arrayToHeaderString( $headers, $endl );
245
246 wfDebug( "Sending mail via internal mail() function\n" );
247
248 self::$mErrorString = '';
249 $html_errors = ini_get( 'html_errors' );
250 ini_set( 'html_errors', '0' );
251 set_error_handler( 'UserMailer::errorHandler' );
252
253 foreach ( $dest as $recip ) {
254 $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
255 }
256
257 restore_error_handler();
258 ini_set( 'html_errors', $html_errors );
259
260 if ( self::$mErrorString ) {
261 wfDebug( "Error sending mail: " . self::$mErrorString . "\n" );
262 return Status::newFatal( 'php-mail-error', self::$mErrorString );
263 } elseif ( ! $sent ) {
264 // mail function only tells if there's an error
265 wfDebug( "Unknown error sending mail\n" );
266 return Status::newFatal( 'php-mail-error-unknown' );
267 } else {
268 return Status::newGood();
269 }
270 }
271 }
272
273 /**
274 * Set the mail error message in self::$mErrorString
275 *
276 * @param $code Integer: error number
277 * @param $string String: error message
278 */
279 static function errorHandler( $code, $string ) {
280 self::$mErrorString = preg_replace( '/^mail\(\)(\s*\[.*?\])?: /', '', $string );
281 }
282
283 /**
284 * Converts a string into a valid RFC 822 "phrase", such as is used for the sender name
285 * @param $phrase string
286 * @return string
287 */
288 public static function rfc822Phrase( $phrase ) {
289 $phrase = strtr( $phrase, array( "\r" => '', "\n" => '', '"' => '' ) );
290 return '"' . $phrase . '"';
291 }
292
293 /**
294 * Converts a string into quoted-printable format
295 * @since 1.17
296 */
297 public static function quotedPrintable( $string, $charset = '' ) {
298 # Probably incomplete; see RFC 2045
299 if( empty( $charset ) ) {
300 $charset = 'UTF-8';
301 }
302 $charset = strtoupper( $charset );
303 $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ?
304
305 $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff=';
306 $replace = $illegal . '\t ?_';
307 if( !preg_match( "/[$illegal]/", $string ) ) {
308 return $string;
309 }
310 $out = "=?$charset?Q?";
311 $out .= preg_replace_callback( "/([$replace])/",
312 array( __CLASS__, 'quotedPrintableCallback' ), $string );
313 $out .= '?=';
314 return $out;
315 }
316
317 protected static function quotedPrintableCallback( $matches ) {
318 return sprintf( "=%02X", ord( $matches[1] ) );
319 }
320 }
321
322 /**
323 * This module processes the email notifications when the current page is
324 * changed. It looks up the table watchlist to find out which users are watching
325 * that page.
326 *
327 * The current implementation sends independent emails to each watching user for
328 * the following reason:
329 *
330 * - Each watching user will be notified about the page edit time expressed in
331 * his/her local time (UTC is shown additionally). To achieve this, we need to
332 * find the individual timeoffset of each watching user from the preferences..
333 *
334 * Suggested improvement to slack down the number of sent emails: We could think
335 * of sending out bulk mails (bcc:user1,user2...) for all these users having the
336 * same timeoffset in their preferences.
337 *
338 * Visit the documentation pages under http://meta.wikipedia.com/Enotif
339 *
340 *
341 */
342 class EmailNotification {
343 protected $to, $subject, $body, $replyto, $from;
344 protected $user, $title, $timestamp, $summary, $minorEdit, $oldid, $composed_common, $editor;
345 protected $mailTargets = array();
346
347 /**
348 * Send emails corresponding to the user $editor editing the page $title.
349 * Also updates wl_notificationtimestamp.
350 *
351 * May be deferred via the job queue.
352 *
353 * @param $editor User object
354 * @param $title Title object
355 * @param $timestamp
356 * @param $summary
357 * @param $minorEdit
358 * @param $oldid (default: false)
359 */
360 public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false ) {
361 global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker;
362
363 if ( $title->getNamespace() < 0 ) {
364 return;
365 }
366
367 // Build a list of users to notfiy
368 $watchers = array();
369 if ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) {
370 $dbw = wfGetDB( DB_MASTER );
371 $res = $dbw->select( array( 'watchlist' ),
372 array( 'wl_user' ),
373 array(
374 'wl_title' => $title->getDBkey(),
375 'wl_namespace' => $title->getNamespace(),
376 'wl_user != ' . intval( $editor->getID() ),
377 'wl_notificationtimestamp IS NULL',
378 ), __METHOD__
379 );
380 foreach ( $res as $row ) {
381 $watchers[] = intval( $row->wl_user );
382 }
383 if ( $watchers ) {
384 // Update wl_notificationtimestamp for all watching users except
385 // the editor
386 $dbw->begin();
387 $dbw->update( 'watchlist',
388 array( /* SET */
389 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
390 ), array( /* WHERE */
391 'wl_title' => $title->getDBkey(),
392 'wl_namespace' => $title->getNamespace(),
393 'wl_user' => $watchers
394 ), __METHOD__
395 );
396 $dbw->commit();
397 }
398 }
399
400 if ( $wgEnotifUseJobQ ) {
401 $params = array(
402 'editor' => $editor->getName(),
403 'editorID' => $editor->getID(),
404 'timestamp' => $timestamp,
405 'summary' => $summary,
406 'minorEdit' => $minorEdit,
407 'oldid' => $oldid,
408 'watchers' => $watchers
409 );
410 $job = new EnotifNotifyJob( $title, $params );
411 $job->insert();
412 } else {
413 $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers );
414 }
415
416 }
417
418 /**
419 * Immediate version of notifyOnPageChange().
420 *
421 * Send emails corresponding to the user $editor editing the page $title.
422 * Also updates wl_notificationtimestamp.
423 *
424 * @param $editor User object
425 * @param $title Title object
426 * @param $timestamp string Edit timestamp
427 * @param $summary string Edit summary
428 * @param $minorEdit bool
429 * @param $oldid int Revision ID
430 * @param $watchers array of user IDs
431 */
432 public function actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers ) {
433 # we use $wgPasswordSender as sender's address
434 global $wgEnotifWatchlist;
435 global $wgEnotifMinorEdits, $wgEnotifUserTalk;
436
437 wfProfileIn( __METHOD__ );
438
439 # The following code is only run, if several conditions are met:
440 # 1. EmailNotification for pages (other than user_talk pages) must be enabled
441 # 2. minor edits (changes) are only regarded if the global flag indicates so
442
443 $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
444
445 $this->title = $title;
446 $this->timestamp = $timestamp;
447 $this->summary = $summary;
448 $this->minorEdit = $minorEdit;
449 $this->oldid = $oldid;
450 $this->editor = $editor;
451 $this->composed_common = false;
452
453 $userTalkId = false;
454
455 if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
456 if ( $wgEnotifUserTalk && $isUserTalkPage ) {
457 $targetUser = User::newFromName( $title->getText() );
458 if ( !$targetUser || $targetUser->isAnon() ) {
459 wfDebug( __METHOD__ . ": user talk page edited, but user does not exist\n" );
460 } elseif ( $targetUser->getId() == $editor->getId() ) {
461 wfDebug( __METHOD__ . ": user edited their own talk page, no notification sent\n" );
462 } elseif ( $targetUser->getOption( 'enotifusertalkpages' ) &&
463 ( !$minorEdit || $targetUser->getOption( 'enotifminoredits' ) ) )
464 {
465 if ( $targetUser->isEmailConfirmed() ) {
466 wfDebug( __METHOD__ . ": sending talk page update notification\n" );
467 $this->compose( $targetUser );
468 $userTalkId = $targetUser->getId();
469 } else {
470 wfDebug( __METHOD__ . ": talk page owner doesn't have validated email\n" );
471 }
472 } else {
473 wfDebug( __METHOD__ . ": talk page owner doesn't want notifications\n" );
474 }
475 }
476
477 if ( $wgEnotifWatchlist ) {
478 // Send updates to watchers other than the current editor
479 $userArray = UserArray::newFromIDs( $watchers );
480 foreach ( $userArray as $watchingUser ) {
481 if ( $watchingUser->getOption( 'enotifwatchlistpages' ) &&
482 ( !$minorEdit || $watchingUser->getOption( 'enotifminoredits' ) ) &&
483 $watchingUser->isEmailConfirmed() &&
484 $watchingUser->getID() != $userTalkId )
485 {
486 $this->compose( $watchingUser );
487 }
488 }
489 }
490 }
491
492 global $wgUsersNotifiedOnAllChanges;
493 foreach ( $wgUsersNotifiedOnAllChanges as $name ) {
494 $user = User::newFromName( $name );
495 $this->compose( $user );
496 }
497
498 $this->sendMails();
499 wfProfileOut( __METHOD__ );
500 }
501
502 /**
503 * Generate the generic "this page has been changed" e-mail text.
504 */
505 private function composeCommonMailtext() {
506 global $wgPasswordSender, $wgPasswordSenderName, $wgNoReplyAddress;
507 global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress;
508 global $wgEnotifImpersonal, $wgEnotifUseRealName;
509
510 $this->composed_common = true;
511
512 $summary = ( $this->summary == '' ) ? ' - ' : $this->summary;
513 $medit = ( $this->minorEdit ) ? wfMsgForContent( 'minoredit' ) : '';
514
515 # You as the WikiAdmin and Sysops can make use of plenty of
516 # named variables when composing your notification emails while
517 # simply editing the Meta pages
518
519 $subject = wfMsgForContent( 'enotif_subject' );
520 $body = wfMsgForContent( 'enotif_body' );
521 $from = ''; /* fail safe */
522 $replyto = ''; /* fail safe */
523 $keys = array();
524
525 if ( $this->oldid ) {
526 $difflink = $this->title->getFullUrl( 'diff=0&oldid=' . $this->oldid );
527 $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastvisited', $difflink );
528 $keys['$OLDID'] = $this->oldid;
529 $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'changed' );
530 } else {
531 $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_newpagetext' );
532 # clear $OLDID placeholder in the message template
533 $keys['$OLDID'] = '';
534 $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'created' );
535 }
536
537 if ( $wgEnotifImpersonal && $this->oldid ) {
538 /**
539 * For impersonal mail, show a diff link to the last
540 * revision.
541 */
542 $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastdiff',
543 $this->title->getFullURL( "oldid={$this->oldid}&diff=next" ) );
544 }
545
546 $body = strtr( $body, $keys );
547 $pagetitle = $this->title->getPrefixedText();
548 $keys['$PAGETITLE'] = $pagetitle;
549 $keys['$PAGETITLE_URL'] = $this->title->getFullUrl();
550
551 $keys['$PAGEMINOREDIT'] = $medit;
552 $keys['$PAGESUMMARY'] = $summary;
553 $keys['$UNWATCHURL'] = $this->title->getFullUrl( 'action=unwatch' );
554
555 $subject = strtr( $subject, $keys );
556
557 # Reveal the page editor's address as REPLY-TO address only if
558 # the user has not opted-out and the option is enabled at the
559 # global configuration level.
560 $editor = $this->editor;
561 $name = $wgEnotifUseRealName ? $editor->getRealName() : $editor->getName();
562 $adminAddress = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
563 $editorAddress = new MailAddress( $editor );
564 if ( $wgEnotifRevealEditorAddress
565 && ( $editor->getEmail() != '' )
566 && $editor->getOption( 'enotifrevealaddr' ) ) {
567 if ( $wgEnotifFromEditor ) {
568 $from = $editorAddress;
569 } else {
570 $from = $adminAddress;
571 $replyto = $editorAddress;
572 }
573 } else {
574 $from = $adminAddress;
575 $replyto = new MailAddress( $wgNoReplyAddress );
576 }
577
578 if ( $editor->isAnon() ) {
579 # real anon (user:xxx.xxx.xxx.xxx)
580 $utext = wfMsgForContent( 'enotif_anon_editor', $name );
581 $subject = str_replace( '$PAGEEDITOR', $utext, $subject );
582 $keys['$PAGEEDITOR'] = $utext;
583 $keys['$PAGEEDITOR_EMAIL'] = wfMsgForContent( 'noemailtitle' );
584 } else {
585 $subject = str_replace( '$PAGEEDITOR', $name, $subject );
586 $keys['$PAGEEDITOR'] = $name;
587 $emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $name );
588 $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getFullUrl();
589 }
590 $userPage = $editor->getUserPage();
591 $keys['$PAGEEDITOR_WIKI'] = $userPage->getFullUrl();
592 $body = strtr( $body, $keys );
593 $body = wordwrap( $body, 72 );
594
595 # now save this as the constant user-independent part of the message
596 $this->from = $from;
597 $this->replyto = $replyto;
598 $this->subject = $subject;
599 $this->body = $body;
600 }
601
602 /**
603 * Compose a mail to a given user and either queue it for sending, or send it now,
604 * depending on settings.
605 *
606 * Call sendMails() to send any mails that were queued.
607 */
608 function compose( $user ) {
609 global $wgEnotifImpersonal;
610
611 if ( !$this->composed_common )
612 $this->composeCommonMailtext();
613
614 if ( $wgEnotifImpersonal ) {
615 $this->mailTargets[] = new MailAddress( $user );
616 } else {
617 $this->sendPersonalised( $user );
618 }
619 }
620
621 /**
622 * Send any queued mails
623 */
624 function sendMails() {
625 global $wgEnotifImpersonal;
626 if ( $wgEnotifImpersonal ) {
627 $this->sendImpersonal( $this->mailTargets );
628 }
629 }
630
631 /**
632 * Does the per-user customizations to a notification e-mail (name,
633 * timestamp in proper timezone, etc) and sends it out.
634 * Returns true if the mail was sent successfully.
635 *
636 * @param $watchingUser User object
637 * @return Boolean
638 * @private
639 */
640 function sendPersonalised( $watchingUser ) {
641 global $wgContLang, $wgEnotifUseRealName;
642 // From the PHP manual:
643 // Note: The to parameter cannot be an address in the form of "Something <someone@example.com>".
644 // The mail command will not parse this properly while talking with the MTA.
645 $to = new MailAddress( $watchingUser );
646 $name = $wgEnotifUseRealName ? $watchingUser->getRealName() : $watchingUser->getName();
647 $body = str_replace( '$WATCHINGUSERNAME', $name, $this->body );
648
649 $timecorrection = $watchingUser->getOption( 'timecorrection' );
650
651 # $PAGEEDITDATE is the time and date of the page change
652 # expressed in terms of individual local time of the notification
653 # recipient, i.e. watching user
654 $body = str_replace(
655 array( '$PAGEEDITDATEANDTIME',
656 '$PAGEEDITDATE',
657 '$PAGEEDITTIME' ),
658 array( $wgContLang->timeanddate( $this->timestamp, true, false, $timecorrection ),
659 $wgContLang->date( $this->timestamp, true, false, $timecorrection ),
660 $wgContLang->time( $this->timestamp, true, false, $timecorrection ) ),
661 $body );
662
663 return UserMailer::send( $to, $this->from, $this->subject, $body, $this->replyto );
664 }
665
666 /**
667 * Same as sendPersonalised but does impersonal mail suitable for bulk
668 * mailing. Takes an array of MailAddress objects.
669 */
670 function sendImpersonal( $addresses ) {
671 global $wgContLang;
672
673 if ( empty( $addresses ) )
674 return;
675
676 $body = str_replace(
677 array( '$WATCHINGUSERNAME',
678 '$PAGEEDITDATE',
679 '$PAGEEDITTIME' ),
680 array( wfMsgForContent( 'enotif_impersonal_salutation' ),
681 $wgContLang->date( $this->timestamp, true, false, false ),
682 $wgContLang->time( $this->timestamp, true, false, false ) ),
683 $this->body );
684
685 return UserMailer::send( $addresses, $this->from, $this->subject, $body, $this->replyto );
686 }
687
688 } # end of class EmailNotification