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