summaryrefslogtreecommitdiff
path: root/includes/unicode.inc
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-09-29 12:37:58 +0000
committerDries Buytaert <dries@buytaert.net>2005-09-29 12:37:58 +0000
commitc4757dd807b3f41504f8cab08a4e786f70036575 (patch)
treed7ce016d2ca989904ed579e9e6a19279839cd664 /includes/unicode.inc
parentbf08ab83b621a7db54f5ff63e1a0765f986a852c (diff)
downloadbrdo-c4757dd807b3f41504f8cab08a4e786f70036575.tar.gz
brdo-c4757dd807b3f41504f8cab08a4e786f70036575.tar.bz2
- Patch #32465 by Steven/killes: mime decode function.
Diffstat (limited to 'includes/unicode.inc')
-rw-r--r--includes/unicode.inc25
1 files changed, 25 insertions, 0 deletions
diff --git a/includes/unicode.inc b/includes/unicode.inc
index 511179adf..04751ed79 100644
--- a/includes/unicode.inc
+++ b/includes/unicode.inc
@@ -234,6 +234,31 @@ function mime_header_encode($string) {
}
/**
+ * Complement to mime_header_encode
+ */
+function mime_header_decode($header) {
+ // First step: encoded chunks followed by other encoded chunks (need to collapse whitespace)
+ $header = preg_replace_callback('/=\?([^?]+)\?(Q|B)\?([^?]+|\?(?!=))\?=\s+(?==\?)/', '_mime_header_decode', $header);
+ // Second step: remaining chunks (do not collapse whitespace)
+ return preg_replace_callback('/=\?([^?]+)\?(Q|B)\?([^?]+|\?(?!=))\?=/', '_mime_header_decode', $header);
+}
+
+/**
+ * Helper function to mime_header_decode
+ */
+function _mime_header_decode($matches) {
+ // Regexp groups:
+ // 1: Character set name
+ // 2: Escaping method (Q or B)
+ // 3: Encoded data
+ $data = ($matches[2] == 'B') ? base64_decode($matches[3]) : str_replace('_', ' ', quoted_printable_decode($matches[3]));
+ if (strtolower($matches[1]) != 'utf-8') {
+ $data = drupal_convert_to_utf8($data, $matches[1]);
+ }
+ return $data;
+}
+
+/**
* Decode all HTML entities (including numerical ones) to regular UTF-8 bytes.
* Double-escaped entities will only be decoded once ("&amp;lt;" becomes "&lt;", not "<").
*