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