--- user.module 2006-08-07 09:29:40.000000000 +0100 +++ user.module.new1 2006-08-14 15:36:56.000000000 +0100 @@ -341,6 +341,31 @@ * Send an e-mail message. */ function user_mail($mail, $subject, $message, $header) { + $defaults = array( + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal' + ); + + // remove all '\r' and explode the header + $header = str_replace('\r', '', $header); + $headers = explode("\n", $header); + foreach($headers as $key) { + $dummy = explode(":", $key); + if (strtolower($dummy[0]) == 'reply-to') $dummy[0] = 'Reply-To'; + if (strtolower($dummy[0]) == 'return-path') $dummy[0] = 'Return-Path'; + if (strtolower($dummy[0]) == 'errors-to') $dummy[0] = 'Errors-To'; + if ($dummy[0] != '' && !isset($defaults[$dummy[0]])) { + $defaults[$dummy[0]] = $dummy[1]; + } + } + + if (isset($defaults['From'])) { + $defaults['Reply-To'] = $defaults['Return-Path'] = $defaults['Errors-To'] = $defaults['From']; + } + + // Allow for custom mail backend if (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) { include_once variable_get('smtp_library', ''); return user_mail_wrapper($mail, $subject, $message, $header); @@ -366,11 +391,15 @@ ** http://www.rfc-editor.org/rfc/rfc2646.txt ** */ + $mimeheaders = array(); + foreach ($headers as $name => $value) { + $mimeheaders[] = $name .': '. mime_header_encode($value); + } return mail( - $mail, + $to, mime_header_encode($subject), - str_replace("\r", '', $message), - "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8; format=flowed\nContent-transfer-encoding: 8Bit\n" . $header + str_replace("\r", '', $body), + join("\n", $mimeheaders) ); } }