From cb6e232990efe12155362347502dbc15d3e734f4 Mon Sep 17 00:00:00 2001 From: Kjartan Mannes Date: Fri, 3 Oct 2003 22:44:32 +0000 Subject: - Re-wrote user_mail_encode(). --- modules/user/user.module | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) (limited to 'modules/user/user.module') diff --git a/modules/user/user.module b/modules/user/user.module index 6d7a97f80..fc604a51a 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -324,33 +324,21 @@ function user_mail($mail, $subject, $message, $header) { $mail, user_mail_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 + "MIME-Version: 1.0\nContent-type: text/plain; charset=UTF-8; format=flowed\nContent-transfer-encoding: 8Bit\n" . $header ); } } -// Original code by -function user_mail_encode($string) { - - // define start delimimter, end delimiter and spacer - $end = "?="; - $start = "=?UTF-8?B?"; - $spacer = "{$end}\r\n{$start}"; - - // determine length of encoded text within - // chunks and ensure length is even - $length = 75 - strlen($start) - strlen($end); - $length = floor($length/2) * 2; - - // encode the string and split it into chunks - // with spacers after each chunk - $string = base64_encode($string); - $string = chunk_split($string, $length, $spacer); - - // remove trailing spacer and add start and end delimiters - $spacer = preg_quote($spacer); - $string = preg_replace("/{$spacer}$/", "", $string); - return ($start . $string . $end); +function user_mail_encode($string, $charset = "UTF-8") { + /* + ** Used to encodes mail headers that contain non US- ASCII + ** characters. + ** http://www.rfc-editor.org/rfc/rfc2047.txt + */ + $maxlen = 75 - 7 - strlen($charset); + $string = trim(chunk_split(base64_encode($string), $maxlen, "\n")); + $string = trim(preg_replace('/^(.*)$/m', " =?$charset?B?\\1?=", $string)); + return $string; } function user_deny($type, $mask) { -- cgit v1.2.3