Index: trunk/phase3/includes/UserMailer.php |
— | — | @@ -105,6 +105,21 @@ |
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
| 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 | + /** |
109 | 124 | * This function will perform a direct (authenticated) login to |
110 | 125 | * a SMTP Server to use for mail relaying if 'wgSMTP' specifies an |
111 | 126 | * array of parameters. It requires PEAR:Mail to do that. |
— | — | @@ -127,7 +142,7 @@ |
128 | 143 | // This wouldn't be necessary if implode() worked on arrays of |
129 | 144 | // objects using __toString(). http://bugs.php.net/bug.php?id=36612 |
130 | 145 | foreach ( $to as $t ) { |
131 | | - $emails .= $t->toString() . ","; |
| 146 | + $emails .= $t->toString() . ","; |
132 | 147 | } |
133 | 148 | $emails = rtrim( $emails, ',' ); |
134 | 149 | wfDebug( __METHOD__ . ': sending mail to ' . $emails . "\n" ); |
— | — | @@ -135,6 +150,30 @@ |
136 | 151 | wfDebug( __METHOD__ . ': sending mail to ' . implode( ',', array( $to->toString() ) ) . "\n" ); |
137 | 152 | } |
138 | 153 | |
| 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 | + |
139 | 178 | if ( is_array( $wgSMTP ) ) { |
140 | 179 | if ( function_exists( 'stream_resolve_include_path' ) ) { |
141 | 180 | $found = stream_resolve_include_path( 'Mail.php' ); |
— | — | @@ -160,29 +199,6 @@ |
161 | 200 | $dest = $to->address; |
162 | 201 | } |
163 | 202 | |
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 | | - |
187 | 203 | wfSuppressWarnings(); |
188 | 204 | |
189 | 205 | // Create the mail object using the Mail::factory method |
— | — | @@ -214,19 +230,8 @@ |
215 | 231 | $endl = "\n"; |
216 | 232 | } |
217 | 233 | |
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 ); |
228 | 235 | |
229 | | - $headers = implode( $endl, $headers ); |
230 | | - |
231 | 236 | wfDebug( "Sending mail via internal mail() function\n" ); |
232 | 237 | |
233 | 238 | self::$mErrorString = ''; |