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