} else {
return $this->address;
}
+ } else {
+ return "";
}
}
return implode( $endl, $string );
}
+ /**
+ * Create a value suitable for the MessageId Header
+ *
+ * @return String
+ */
+ static function makeMsgId() {
+ global $wgSMTP, $wgServer;
+
+ $msgid = uniqid( wfWikiID() . ".", true ); /* true required for cygwin */
+ if ( is_array($wgSMTP) && isset($wgSMTP['IDHost']) && $wgSMTP['IDHost'] ) {
+ $domain = $wgSMTP['IDHost'];
+ } else {
+ $url = wfParseUrl($wgServer);
+ $domain = $url['host'];
+ }
+ return "<$msgid@$domain>";
+ }
+
/**
* This function will perform a direct (authenticated) login to
* a SMTP Server to use for mail relaying if 'wgSMTP' specifies an
$headers['From'] = $from->toString();
$headers['Return-Path'] = $from->toString();
+ $dest = array();
+ if ( is_array( $to ) ) {
+ foreach ( $to as $u ) {
+ if ( $u->address ) {
+ $dest[] = $u->address;
+ }
+ }
+ } else if( $to->address ) {
+ $dest[] = $to->address;
+ }
+ if ( count( $dest ) == 0 ) {
+ return Status::newFatal( 'user-mail-no-addy' );
+ }
+
if ( $wgEnotifImpersonal ) {
$headers['To'] = 'undisclosed-recipients:;';
}
else {
- $headers['To'] = implode( ", ", (array )$dest );
+ $headers['To'] = implode( ", ", $dest );
}
if ( $replyto ) {
$headers['Content-type'] = ( is_null( $contentType ) ?
'text/plain; charset=UTF-8' : $contentType );
$headers['Content-transfer-encoding'] = '8bit';
- // @todo FIXME
- $headers['Message-ID'] = "<$msgid@" . $wgSMTP['IDHost'] . '>';
+
+ $headers['Message-ID'] = self::makeMsgId();
$headers['X-Mailer'] = 'MediaWiki mailer';
$headers['From'] = $from->toString();
+ $ret = wfRunHooks( 'AlternateUserMailer', array( $headers, $to, $from, $subject, $body ) );
+ if ( $ret === false ) {
+ return Status::newGood();
+ } else if ( $ret !== true ) {
+ return Status::newFatal( 'php-mail-error', $ret );
+ }
+
if ( is_array( $wgSMTP ) ) {
if ( function_exists( 'stream_resolve_include_path' ) ) {
$found = stream_resolve_include_path( 'Mail.php' );
}
require_once( 'Mail.php' );
- $msgid = str_replace( " ", "_", microtime() );
- if ( function_exists( 'posix_getpid' ) ) {
- $msgid .= '.' . posix_getpid();
- }
-
- if ( is_array( $to ) ) {
- $dest = array();
- foreach ( $to as $u ) {
- $dest[] = $u->address;
- }
- } else {
- $dest = $to->address;
- }
-
wfSuppressWarnings();
// Create the mail object using the Mail::factory method
return Status::newFatal( 'pear-mail-error', $mail_object->getMessage() );
}
- wfDebug( "Sending mail via PEAR::Mail to $dest\n" );
- $chunks = array_chunk( (array)$dest, $wgEnotifMaxRecips );
+ wfDebug( "Sending mail via PEAR::Mail\n" );
+ $chunks = array_chunk( $dest, $wgEnotifMaxRecips );
foreach ( $chunks as $chunk ) {
$status = self::sendWithPear( $mail_object, $chunk, $headers, $body );
if ( !$status->isOK() ) {
ini_set( 'html_errors', '0' );
set_error_handler( 'UserMailer::errorHandler' );
- if ( !is_array( $to ) ) {
- $to = array( $to );
- }
- foreach ( $to as $recip ) {
- $sent = mail( $recip->toString(), self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
+ $safeMode = wfIniGetBool( 'safe_mode' );
+ foreach ( $dest as $recip ) {
+ if ( $safeMode ) {
+ $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers );
+ } else {
+ $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
+ }
}
restore_error_handler();
return Status::newFatal( 'php-mail-error', self::$mErrorString );
} elseif ( ! $sent ) {
// mail function only tells if there's an error
- wfDebug( "Error sending mail\n" );
+ wfDebug( "Unknown error sending mail\n" );
return Status::newFatal( 'php-mail-error-unknown' );
} else {
return Status::newGood();
* @param $oldid (default: false)
*/
public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false ) {
- global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker;
+ global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker, $wgEnotifMinorEdits,
+ $wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk;
if ( $title->getNamespace() < 0 ) {
return;
}
}
+ $sendEmail = true;
+ // If nobody is watching the page, and there are no users notified on all changes
+ // don't bother creating a job/trying to send emails
+ // $watchers deals with $wgEnotifWatchlist
+ if ( !count( $watchers ) && !count( $wgUsersNotifiedOnAllChanges ) ) {
+ $sendEmail = false;
+ // Only send notification for non minor edits, unless $wgEnotifMinorEdits
+ if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
+ $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
+ if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) {
+ $sendEmail = true;
+ }
+ }
+ }
+
+ if ( !$sendEmail ) {
+ return;
+ }
if ( $wgEnotifUseJobQ ) {
$params = array(
'editor' => $editor->getName(),
} else {
$this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers );
}
-
}
/**
$userTalkId = false;
if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
- if ( $wgEnotifUserTalk && $isUserTalkPage ) {
+
+ if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) {
$targetUser = User::newFromName( $title->getText() );
- if ( !$targetUser || $targetUser->isAnon() ) {
- wfDebug( __METHOD__ . ": user talk page edited, but user does not exist\n" );
- } elseif ( $targetUser->getId() == $editor->getId() ) {
- wfDebug( __METHOD__ . ": user edited their own talk page, no notification sent\n" );
- } elseif ( $targetUser->getOption( 'enotifusertalkpages' ) &&
- ( !$minorEdit || $targetUser->getOption( 'enotifminoredits' ) ) )
- {
- if ( $targetUser->isEmailConfirmed() ) {
- wfDebug( __METHOD__ . ": sending talk page update notification\n" );
- $this->compose( $targetUser );
- $userTalkId = $targetUser->getId();
- } else {
- wfDebug( __METHOD__ . ": talk page owner doesn't have validated email\n" );
- }
- } else {
- wfDebug( __METHOD__ . ": talk page owner doesn't want notifications\n" );
- }
+ $this->compose( $targetUser );
+ $userTalkId = $targetUser->getId();
}
if ( $wgEnotifWatchlist ) {
wfProfileOut( __METHOD__ );
}
+ /**
+ * @param $editor User
+ * @param $title Title bool
+ * @param $minorEdit
+ * @return bool
+ */
+ private function canSendUserTalkEmail( $editor, $title, $minorEdit ) {
+ global $wgEnotifUserTalk;
+ $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
+
+ if ( $wgEnotifUserTalk && $isUserTalkPage ) {
+ $targetUser = User::newFromName( $title->getText() );
+
+ if ( !$targetUser || $targetUser->isAnon() ) {
+ wfDebug( __METHOD__ . ": user talk page edited, but user does not exist\n" );
+ } elseif ( $targetUser->getId() == $editor->getId() ) {
+ wfDebug( __METHOD__ . ": user edited their own talk page, no notification sent\n" );
+ } elseif ( $targetUser->getOption( 'enotifusertalkpages' ) &&
+ ( !$minorEdit || $targetUser->getOption( 'enotifminoredits' ) ) )
+ {
+ if ( $targetUser->isEmailConfirmed() ) {
+ wfDebug( __METHOD__ . ": sending talk page update notification\n" );
+ return true;
+ } else {
+ wfDebug( __METHOD__ . ": talk page owner doesn't have validated email\n" );
+ }
+ } else {
+ wfDebug( __METHOD__ . ": talk page owner doesn't want notifications\n" );
+ }
+ }
+ return false;
+ }
+
/**
* Generate the generic "this page has been changed" e-mail text.
*/
$keys = array();
if ( $this->oldid ) {
- $difflink = $this->title->getFullUrl( 'diff=0&oldid=' . $this->oldid );
+ $difflink = $this->title->getCanonicalUrl( 'diff=0&oldid=' . $this->oldid );
$keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastvisited', $difflink );
$keys['$OLDID'] = $this->oldid;
$keys['$CHANGEDORCREATED'] = wfMsgForContent( 'changed' );
* revision.
*/
$keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastdiff',
- $this->title->getFullURL( "oldid={$this->oldid}&diff=next" ) );
+ $this->title->getCanonicalUrl( "oldid={$this->oldid}&diff=next" ) );
}
$body = strtr( $body, $keys );
$pagetitle = $this->title->getPrefixedText();
$keys['$PAGETITLE'] = $pagetitle;
- $keys['$PAGETITLE_URL'] = $this->title->getFullUrl();
+ $keys['$PAGETITLE_URL'] = $this->title->getCanonicalUrl();
$keys['$PAGEMINOREDIT'] = $medit;
$keys['$PAGESUMMARY'] = $summary;
- $keys['$UNWATCHURL'] = $this->title->getFullUrl( 'action=unwatch' );
+ $keys['$UNWATCHURL'] = $this->title->getCanonicalUrl( 'action=unwatch' );
$subject = strtr( $subject, $keys );
$subject = str_replace( '$PAGEEDITOR', $name, $subject );
$keys['$PAGEEDITOR'] = $name;
$emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $name );
- $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getFullUrl();
+ $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getCanonicalUrl();
}
$userPage = $editor->getUserPage();
- $keys['$PAGEEDITOR_WIKI'] = $userPage->getFullUrl();
+ $keys['$PAGEEDITOR_WIKI'] = $userPage->getCanonicalUrl();
$body = strtr( $body, $keys );
$body = wordwrap( $body, 72 );