diff options
author | Kjartan Mannes <kjartan@2.no-reply.drupal.org> | 2003-10-03 22:44:32 +0000 |
---|---|---|
committer | Kjartan Mannes <kjartan@2.no-reply.drupal.org> | 2003-10-03 22:44:32 +0000 |
commit | cb6e232990efe12155362347502dbc15d3e734f4 (patch) | |
tree | 61f90ba4ef32e8dd277e67d149a30e9e7292ae5b | |
parent | a33df1de5d3f5feb3193ee36ff8cb2f0bd5f9c98 (diff) | |
download | brdo-cb6e232990efe12155362347502dbc15d3e734f4.tar.gz brdo-cb6e232990efe12155362347502dbc15d3e734f4.tar.bz2 |
- Re-wrote user_mail_encode().
-rw-r--r-- | modules/user.module | 34 | ||||
-rw-r--r-- | modules/user/user.module | 34 |
2 files changed, 22 insertions, 46 deletions
diff --git a/modules/user.module b/modules/user.module index 6d7a97f80..fc604a51a 100644 --- a/modules/user.module +++ b/modules/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 <gordon at kanazawa-gu dot ac dot jp> -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) { 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 <gordon at kanazawa-gu dot ac dot jp> -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) { |