b73f27d9 |
1 | <?php |
2 | /******************************************************************************** |
3 | * include/encoding.inc.php : decoding subroutines |
4 | * -------------------------- |
5 | * |
6 | * This file is part of the banana distribution |
7 | * Copyright: See COPYING files that comes with this distribution |
8 | ********************************************************************************/ |
9 | |
10 | /** Decodes quoted-printable and UTF8 headers |
11 | * @param STRING $_value string to decode |
12 | */ |
13 | |
14 | function headerDecode($_value) { |
e785d91c |
15 | if (eregi('=\?.*\?.\?.*\?=',$_value)) { // is there anything encoded ? |
16 | if (eregi('=\?(.*)\?Q\?.*\?=',$_value,$charset)) { // quoted-printable decoding |
17 | $result1 = eregi_replace('(.*)=\?.*\?Q\?(.*)\?=(.*)','\1',$_value); |
18 | $result2 = eregi_replace('(.*)=\?.*\?Q\?(.*)\?=(.*)','\2',$_value); |
19 | $result3 = eregi_replace('(.*)=\?.*\?Q\?(.*)\?=(.*)','\3',$_value); |
20 | $result2 = str_replace("_"," ",quoted_printable_decode($result2)); |
21 | if ($charset[1] == "UTF-8") { |
22 | $result2 = utf8_decode($result2); |
23 | } |
24 | $newvalue = $result1.$result2.$result3; |
25 | } |
26 | if (eregi('=\?(.*)\?B\?.*\?=',$_value,$charset)) { // base64 decoding |
27 | $result1 = eregi_replace('(.*)=\?.*\?B\?(.*)\?=(.*)','\1',$_value); |
28 | $result2 = eregi_replace('(.*)=\?.*\?B\?(.*)\?=(.*)','\2',$_value); |
29 | $result3 = eregi_replace('(.*)=\?.*\?B\?(.*)\?=(.*)','\3',$_value); |
30 | $result2 = base64_decode($result2); |
31 | if ($charset[1] == "UTF-8") { |
32 | $result2 = utf8_decode($result2); |
33 | } |
34 | $newvalue = $result1.$result2.$result3; |
35 | } |
36 | if (!isset($newvalue)) { // nothing of the above, must be an unknown encoding... |
37 | $newvalue = $_value; |
38 | } else { |
39 | $newvalue=headerDecode($newvalue); // maybe there are more encoded |
40 | } |
41 | return($newvalue); // parts |
42 | } else { // there wasn't anything encoded, return the original string |
43 | return($_value); |
b73f27d9 |
44 | } |
b73f27d9 |
45 | } |
46 | ?> |