r111925 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111924‎ | r111925 | r111926 >
Date:13:32, 20 February 2012
Author:hashar
Status:ok (Comments)
Tags:
Comment:
MFT to 1.19wmf1 r111832

(bug 34421) duplicate Subject / wrong To: headers in mail
Modified paths:
  • /branches/wmf/1.19wmf1/includes/UserMailer.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.19wmf1/includes/UserMailer.php
@@ -162,29 +162,52 @@
163163
164164 wfDebug( __METHOD__ . ': sending mail to ' . implode( ', ', $to ) . "\n" );
165165
166 - $dest = array();
 166+ # Make sure we have at least one address
 167+ $has_address = false;
167168 foreach ( $to as $u ) {
168169 if ( $u->address ) {
169 - $dest[] = $u->address;
 170+ $has_address = true;
 171+ break;
170172 }
171173 }
172 - if ( count( $dest ) == 0 ) {
 174+ if ( !$has_address ) {
173175 return Status::newFatal( 'user-mail-no-addy' );
174176 }
175177
 178+ # Forge email headers
 179+ # -------------------
 180+ #
 181+ # WARNING
 182+ #
 183+ # DO NOT add To: or Subject: headers at this step. They need to be
 184+ # handled differently depending upon the mailer we are going to use.
 185+ #
 186+ # To:
 187+ # PHP mail() first argument is the mail receiver. The argument is
 188+ # used as a recipient destination and as a To header.
 189+ #
 190+ # PEAR mailer has a recipient argument which is only used to
 191+ # send the mail. If no To header is given, PEAR will set it to
 192+ # to 'undisclosed-recipients:'.
 193+ #
 194+ # NOTE: To: is for presentation, the actual recipient is specified
 195+ # by the mailer using the Rcpt-To: header.
 196+ #
 197+ # Subject:
 198+ # PHP mail() second argument to pass the subject, passing a Subject
 199+ # as an additional header will result in a duplicate header.
 200+ #
 201+ # PEAR mailer should be passed a Subject header.
 202+ #
 203+ # -- hashar 20120218
 204+
176205 $headers['From'] = $from->toString();
177206 $headers['Return-Path'] = $from->address;
178 - if ( count( $to ) == 1 ) {
179 - $headers['To'] = $to[0]->toString();
180 - } else {
181 - $headers['To'] = 'undisclosed-recipients:;';
182 - }
183207
184208 if ( $replyto ) {
185209 $headers['Reply-To'] = $replyto->toString();
186210 }
187211
188 - $headers['Subject'] = self::quotedPrintable( $subject );
189212 $headers['Date'] = date( 'r' );
190213 $headers['MIME-Version'] = '1.0';
191214 $headers['Content-type'] = ( is_null( $contentType ) ?
@@ -202,6 +225,10 @@
203226 }
204227
205228 if ( is_array( $wgSMTP ) ) {
 229+ #
 230+ # PEAR MAILER
 231+ #
 232+
206233 if ( function_exists( 'stream_resolve_include_path' ) ) {
207234 $found = stream_resolve_include_path( 'Mail.php' );
208235 } else {
@@ -223,9 +250,20 @@
224251 }
225252
226253 wfDebug( "Sending mail via PEAR::Mail\n" );
227 - $chunks = array_chunk( $dest, $wgEnotifMaxRecips );
 254+
 255+ $headers['Subject'] = self::quotedPrintable( $subject );
 256+
 257+ # When sending only to one recipient, shows it its email using To:
 258+ if ( count( $to ) == 1 ) {
 259+ $headers['To'] = $to[0]->toString();
 260+ }
 261+
 262+ # Split jobs since SMTP servers tends to limit the maximum
 263+ # number of possible recipients.
 264+ $chunks = array_chunk( $to, $wgEnotifMaxRecips );
228265 foreach ( $chunks as $chunk ) {
229266 $status = self::sendWithPear( $mail_object, $chunk, $headers, $body );
 267+ # FIXME : some chunks might be sent while others are not!
230268 if ( !$status->isOK() ) {
231269 wfRestoreWarnings();
232270 return $status;
@@ -234,6 +272,10 @@
235273 wfRestoreWarnings();
236274 return Status::newGood();
237275 } else {
 276+ #
 277+ # PHP mail()
 278+ #
 279+
238280 # Line endings need to be different on Unix and Windows due to
239281 # the bug described at http://trac.wordpress.org/ticket/2603
240282 if ( wfIsWindows() ) {
@@ -243,6 +285,9 @@
244286 $endl = "\n";
245287 }
246288
 289+ if( count($to) > 1 ) {
 290+ $headers['To'] = 'undisclosed-recipients:;';
 291+ }
247292 $headers = self::arrayToHeaderString( $headers, $endl );
248293
249294 wfDebug( "Sending mail via internal mail() function\n" );
@@ -253,7 +298,7 @@
254299 set_error_handler( 'UserMailer::errorHandler' );
255300
256301 $safeMode = wfIniGetBool( 'safe_mode' );
257 - foreach ( $dest as $recip ) {
 302+ foreach ( $to as $recip ) {
258303 if ( $safeMode ) {
259304 $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers );
260305 } else {
Property changes on: branches/wmf/1.19wmf1/includes/UserMailer.php
___________________________________________________________________
Added: svn:mergeinfo
261306 Merged /branches/new-installer/phase3/includes/UserMailer.php:r43664-66004
262307 Merged /branches/wmf-deployment/includes/UserMailer.php:r53381
263308 Merged /branches/JSTesting/includes/UserMailer.php:r100352-107913
264309 Merged /branches/REL1_15/phase3/includes/UserMailer.php:r51646
265310 Merged /branches/wmf/1.18wmf1/includes/UserMailer.php:r97508,111667
266311 Merged /branches/sqlite/includes/UserMailer.php:r58211-58321
267312 Merged /trunk/phase3/includes/UserMailer.php:r111029,111034,111067,111085,111128,111144,111251,111397,111571,111574,111597,111673,111695,111697,111750,111827,111832

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111765(bug 34421) avoid duplicate Subject headers...hashar17:02, 17 February 2012
r111819revert r111765 bug 34421 avoid duplicate Subject headers...hashar10:37, 18 February 2012
r111820(bug 34421) avoid duplicate Subject headers in mail...hashar10:57, 18 February 2012
r111832(bug 34421) duplicate Subject / wrong To: headers in mail...hashar15:34, 18 February 2012

Comments

#Comment by Hashar (talk | contribs)   13:38, 20 February 2012

Tested on testwiki and then generalized on Mon, 20 Feb 2012 13:37:00 +0000

Status & tagging log