| 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) { |
| 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 | $newvalue=$result1.$result2.$result3; |
| 24 | } |
| 25 | if (eregi('=\?(.*)\?B\?.*\?=',$_value,$charset)) { // base64 decoding |
| 26 | $result1=eregi_replace('(.*)=\?.*\?B\?(.*)\?=(.*)','\1',$_value); |
| 27 | $result2=eregi_replace('(.*)=\?.*\?B\?(.*)\?=(.*)','\2',$_value); |
| 28 | $result3=eregi_replace('(.*)=\?.*\?B\?(.*)\?=(.*)','\3',$_value); |
| 29 | $result2=base64_decode($result2); |
| 30 | if ($charset[1] == "UTF-8") |
| 31 | $result2 = utf8_decode($result2); |
| 32 | $newvalue=$result1.$result2.$result3; |
| 33 | } |
| 34 | if (!isset($newvalue)) // nothing of the above, must be an unknown encoding... |
| 35 | $newvalue=$_value; |
| 36 | else |
| 37 | $newvalue=headerDecode($newvalue); // maybe there are more encoded |
| 38 | return($newvalue); // parts |
| 39 | } else { // there wasn't anything encoded, return the original string |
| 40 | return($_value); |
| 41 | } |
| 42 | } |
| 43 | ?> |