Set envelope sender to the same as the From: address when PEAR mail is used. This...
[lhc/web/wiklou.git] / includes / UserMailer.php
index c27997e..0a7dc7f 100644 (file)
@@ -31,7 +31,7 @@
  */
 class MailAddress {
        /**
-        * @param $address Mixed: string with an email address, or a User object
+        * @param $address string|User string with an email address, or a User object
         * @param $name String: human-readable name if a string address is given
         * @param $realName String: human-readable real name if a string address is given
         */
@@ -82,6 +82,13 @@ class UserMailer {
 
        /**
         * Send mail using a PEAR mailer
+        *
+        * @param $mailer
+        * @param $dest
+        * @param $headers
+        * @param $body
+        *
+        * @return Status
         */
        protected static function sendWithPear( $mailer, $dest, $headers, $body ) {
                $mailResult = $mailer->send( $dest, $headers, $body );
@@ -138,17 +145,21 @@ class UserMailer {
                        require_once( 'Mail.php' );
 
                        $msgid = str_replace( " ", "_", microtime() );
-                       if ( function_exists( 'posix_getpid' ) )
+                       if ( function_exists( 'posix_getpid' ) ) {
                                $msgid .= '.' . posix_getpid();
+                       }
 
                        if ( is_array( $to ) ) {
                                $dest = array();
-                               foreach ( $to as $u )
+                               foreach ( $to as $u ) {
                                        $dest[] = $u->address;
-                       } else
+                               }
+                       } else {
                                $dest = $to->address;
+                       }
 
                        $headers['From'] = $from->toString();
+                       $headers['Return-Path'] = $from->toString();
 
                        if ( $wgEnotifImpersonal ) {
                                $headers['To'] = 'undisclosed-recipients:;';
@@ -203,7 +214,7 @@ class UserMailer {
 
                        $headers = array(
                                "MIME-Version: 1.0",
-                               "Content-type: $contentType", 
+                               "Content-type: $contentType",
                                "Content-Transfer-Encoding: 8bit",
                                "X-Mailer: MediaWiki mailer",
                                "From: " . $from->toString(),
@@ -256,6 +267,8 @@ class UserMailer {
 
        /**
         * Converts a string into a valid RFC 822 "phrase", such as is used for the sender name
+        * @param $phrase string
+        * @return string
         */
        public static function rfc822Phrase( $phrase ) {
                $phrase = strtr( $phrase, array( "\r" => '', "\n" => '', '"' => '' ) );
@@ -280,7 +293,7 @@ class UserMailer {
                        return $string;
                }
                $out = "=?$charset?Q?";
-               $out .= preg_replace_callback( "/([$replace])/", 
+               $out .= preg_replace_callback( "/([$replace])/",
                        array( __CLASS__, 'quotedPrintableCallback' ), $string );
                $out .= '?=';
                return $out;
@@ -332,8 +345,9 @@ class EmailNotification {
        public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false ) {
                global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker;
 
-               if ( $title->getNamespace() < 0 )
+               if ( $title->getNamespace() < 0 ) {
                        return;
+               }
 
                // Build a list of users to notfiy
                $watchers = array();
@@ -385,7 +399,7 @@ class EmailNotification {
 
        }
 
-       /*
+       /**
         * Immediate version of notifyOnPageChange().
         *
         * Send emails corresponding to the user $editor editing the page $title.
@@ -505,13 +519,13 @@ class EmailNotification {
                }
 
                if ( $wgEnotifImpersonal && $this->oldid ) {
-                       /*
+                       /**
                         * For impersonal mail, show a diff link to the last
                         * revision.
                         */
                        $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastdiff',
                                        $this->title->getFullURL( "oldid={$this->oldid}&diff=next" ) );
-        }
+               }
 
                $body = strtr( $body, $keys );
                $pagetitle = $this->title->getPrefixedText();
@@ -532,8 +546,8 @@ class EmailNotification {
                $adminAddress = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
                $editorAddress = new MailAddress( $editor );
                if ( $wgEnotifRevealEditorAddress
-                   && ( $editor->getEmail() != '' )
-                   && $editor->getOption( 'enotifrevealaddr' ) ) {
+                       && ( $editor->getEmail() != '' )
+                       && $editor->getOption( 'enotifrevealaddr' ) ) {
                        if ( $wgEnotifFromEditor ) {
                                $from    = $editorAddress;
                        } else {
@@ -545,7 +559,7 @@ class EmailNotification {
                        $replyto = new MailAddress( $wgNoReplyAddress );
                }
 
-               if ( $editor->isIP( $name ) ) {
+               if ( $editor->isAnon() ) {
                        # real anon (user:xxx.xxx.xxx.xxx)
                        $utext = wfMsgForContent( 'enotif_anon_editor', $name );
                        $subject = str_replace( '$PAGEEDITOR', $utext, $subject );
@@ -645,9 +659,11 @@ class EmailNotification {
 
                $body = str_replace(
                                array( '$WATCHINGUSERNAME',
-                                       '$PAGEEDITDATE' ),
+                                       '$PAGEEDITDATE',
+                                       '$PAGEEDITTIME' ),
                                array( wfMsgForContent( 'enotif_impersonal_salutation' ),
-                                       $wgContLang->timeanddate( $this->timestamp, true, false, false ) ),
+                                       $wgContLang->date( $this->timestamp, true, false, false ),
+                                       $wgContLang->time( $this->timestamp, true, false, false ) ),
                                $this->body );
 
                return UserMailer::send( $addresses, $this->from, $this->subject, $body, $this->replyto );