r93397 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93396‎ | r93397 | r93398 >
Date:16:56, 28 July 2011
Author:mah
Status:resolved (Comments)
Tags:hashar 
Comment:
Reduce mail header differences by moving all the header creation code
to one place.
Modified paths:
  • /trunk/phase3/includes/UserMailer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/UserMailer.php
@@ -105,6 +105,21 @@
106106 }
107107
108108 /**
 109+ * Creates a single string from an associative array
 110+ *
 111+ * @param $header Associative Array: keys are header field names,
 112+ * values are ... values.
 113+ * @param $endl String: The end of line character. Defaults to "\n"
 114+ * @return String
 115+ */
 116+ static function arrayToHeaderString( $headers, $endl = "\n" ) {
 117+ foreach( $headers as $name => $value ) {
 118+ $string[] = "$name: $value";
 119+ }
 120+ return implode( $endl, $string );
 121+ }
 122+
 123+ /**
109124 * This function will perform a direct (authenticated) login to
110125 * a SMTP Server to use for mail relaying if 'wgSMTP' specifies an
111126 * array of parameters. It requires PEAR:Mail to do that.
@@ -127,7 +142,7 @@
128143 // This wouldn't be necessary if implode() worked on arrays of
129144 // objects using __toString(). http://bugs.php.net/bug.php?id=36612
130145 foreach ( $to as $t ) {
131 - $emails .= $t->toString() . ",";
 146+ $emails .= $t->toString() . ",";
132147 }
133148 $emails = rtrim( $emails, ',' );
134149 wfDebug( __METHOD__ . ': sending mail to ' . $emails . "\n" );
@@ -135,6 +150,30 @@
136151 wfDebug( __METHOD__ . ': sending mail to ' . implode( ',', array( $to->toString() ) ) . "\n" );
137152 }
138153
 154+ $headers['From'] = $from->toString();
 155+ $headers['Return-Path'] = $from->toString();
 156+
 157+ if ( $wgEnotifImpersonal ) {
 158+ $headers['To'] = 'undisclosed-recipients:;';
 159+ }
 160+ else {
 161+ $headers['To'] = implode( ", ", (array )$dest );
 162+ }
 163+
 164+ if ( $replyto ) {
 165+ $headers['Reply-To'] = $replyto->toString();
 166+ }
 167+ $headers['Subject'] = self::quotedPrintable( $subject );
 168+ $headers['Date'] = date( 'r' );
 169+ $headers['MIME-Version'] = '1.0';
 170+ $headers['Content-type'] = ( is_null( $contentType ) ?
 171+ 'text/plain; charset=UTF-8' : $contentType );
 172+ $headers['Content-transfer-encoding'] = '8bit';
 173+ // @todo FIXME
 174+ $headers['Message-ID'] = "<$msgid@" . $wgSMTP['IDHost'] . '>';
 175+ $headers['X-Mailer'] = 'MediaWiki mailer';
 176+ $headers['From'] = $from->toString();
 177+
139178 if ( is_array( $wgSMTP ) ) {
140179 if ( function_exists( 'stream_resolve_include_path' ) ) {
141180 $found = stream_resolve_include_path( 'Mail.php' );
@@ -160,29 +199,6 @@
161200 $dest = $to->address;
162201 }
163202
164 - $headers['From'] = $from->toString();
165 - $headers['Return-Path'] = $from->toString();
166 -
167 - if ( $wgEnotifImpersonal ) {
168 - $headers['To'] = 'undisclosed-recipients:;';
169 - }
170 - else {
171 - $headers['To'] = implode( ', ', (array)$dest );
172 - }
173 -
174 - if ( $replyto ) {
175 - $headers['Reply-To'] = $replyto->toString();
176 - }
177 - $headers['Subject'] = self::quotedPrintable( $subject );
178 - $headers['Date'] = date( 'r' );
179 - $headers['MIME-Version'] = '1.0';
180 - $headers['Content-type'] = ( is_null( $contentType ) ?
181 - 'text/plain; charset=UTF-8' : $contentType );
182 - $headers['Content-transfer-encoding'] = '8bit';
183 - // @todo FIXME
184 - $headers['Message-ID'] = "<$msgid@" . $wgSMTP['IDHost'] . '>';
185 - $headers['X-Mailer'] = 'MediaWiki mailer';
186 -
187203 wfSuppressWarnings();
188204
189205 // Create the mail object using the Mail::factory method
@@ -214,19 +230,8 @@
215231 $endl = "\n";
216232 }
217233
218 - $headers = array(
219 - 'MIME-Version: 1.0',
220 - "Content-type: $contentType",
221 - 'Content-Transfer-Encoding: 8bit',
222 - 'X-Mailer: MediaWiki mailer',
223 - 'From: ' . $from->toString(),
224 - );
225 - if ( $replyto ) {
226 - $headers[] = 'Reply-To: ' . $replyto->toString();
227 - }
 234+ $headers = self::arrayToHeaderString( $headers, $endl );
228235
229 - $headers = implode( $endl, $headers );
230 -
231236 wfDebug( "Sending mail via internal mail() function\n" );
232237
233238 self::$mErrorString = '';

Follow-up revisions

RevisionCommit summaryAuthorDate
r93410* followup r93397 — missing $dest...mah19:03, 28 July 2011
r93417follow up r93397 — missed msgidmah19:38, 28 July 2011
r111765(bug 34421) avoid duplicate Subject headers...hashar17:02, 17 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 Raymond (talk | contribs)   19:10, 28 July 2011

Seen on translatewiki.net:

PHP Notice: Undefined variable: msgid in /www/w/includes/UserMailer.php on line 163
#Comment by Raymond (talk | contribs)   19:14, 28 July 2011

After r93410 it is now line 174

#Comment by Hashar (talk | contribs)   16:56, 16 February 2012

Cause bug 34421

Status & tagging log