diff options
author | Dries Buytaert <dries@buytaert.net> | 2004-08-17 21:35:26 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2004-08-17 21:35:26 +0000 |
commit | 78b052a6af5fc7c87c807821bfc9267f8007ed7b (patch) | |
tree | adbe5a0b21e963f49faff62f7214a1b0147ae6ad /includes/common.inc | |
parent | eeb2b17b7b932152ff951ef9b82f4f5003907242 (diff) | |
download | brdo-78b052a6af5fc7c87c807821bfc9267f8007ed7b.tar.gz brdo-78b052a6af5fc7c87c807821bfc9267f8007ed7b.tar.bz2 |
- The upload (filehandler) module has landed!
Diffstat (limited to 'includes/common.inc')
-rw-r--r-- | includes/common.inc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/includes/common.inc b/includes/common.inc index a15c0942e..cda083867 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1795,6 +1795,34 @@ function truncate_utf8($string, $len) { } /** + * Encodes MIME/HTTP header values that contain non US-ASCII + * characters. + * + * Example: mime_header_encode('tést.txt') returns '=?UTF-8?B?dMOpc3QudHh0?=' + * + * For more info: http://www.rfc-editor.org/rfc/rfc2047.txt + * + */ +function mime_header_encode($string, $charset = 'UTF-8') { + // Notes: + // - Only encode strings that contain non-ASCII characters. + // - The chunks come in groupings of 4 bytes when using base64 + // encoded. + // - trim() is used to ensure that no extra spacing is added by + // chunk_split() or preg_replace(). + // - Using \n as the chunk separator may cause problems on some + // systems and may have to be changed to \r\n or \r. + + if (!preg_match('/^[\x20-\x7E]*$/', $string)) { + $chunk_size = 75 - 7 - strlen($charset); + $chunk_size -= $chunk_size % 4; + $string = trim(chunk_split(base64_encode($string), $chunk_size, "\n")); + $string = trim(preg_replace('/^(.*)$/m', " =?$charset?B?\\1?=", $string)); + } + return $string; +} + +/** * Wrapper around PHP's eval(). Uses output buffering to capture both returned * and printed text. Unlike eval(), we require code to be surrounded by <?php ?> * tags (in other words, we evaluate the code as if it were a stand-alone PHP |