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