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