| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * decode/koi8-u.php |
| 5 | * |
| 6 | * This file contains koi8-u decoding function that is needed to read |
| 7 | * koi8-u encoded mails in non-koi8-u locale. |
| 8 | * |
| 9 | * Original data taken from rfc2319 |
| 10 | * |
| 11 | * Original copyright: |
| 12 | * |
| 13 | * Copyright (C) The Internet Society (1998). All Rights Reserved. |
| 14 | * |
| 15 | * This document and translations of it may be copied and furnished to |
| 16 | * others, and derivative works that comment on or otherwise explain it |
| 17 | * or assist in its implementation may be prepared, copied, published |
| 18 | * and distributed, in whole or in part, without restriction of any |
| 19 | * kind, provided that the above copyright notice and this paragraph are |
| 20 | * included on all such copies and derivative works. However, this |
| 21 | * document itself may not be modified in any way, such as by removing |
| 22 | * the copyright notice or references to the Internet Society or other |
| 23 | * Internet organizations, except as needed for the purpose of |
| 24 | * developing Internet standards in which case the procedures for |
| 25 | * copyrights defined in the Internet Standards process must be |
| 26 | * followed, or as required to translate it into languages other than |
| 27 | * English. |
| 28 | * |
| 29 | * The limited permissions granted above are perpetual and will not be |
| 30 | * revoked by the Internet Society or its successors or assigns. |
| 31 | * |
| 32 | * This document and the information contained herein is provided on an |
| 33 | * "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING |
| 34 | * TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING |
| 35 | * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION |
| 36 | * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF |
| 37 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. |
| 38 | * |
| 39 | * @copyright 2003-2018 The SquirrelMail Project Team |
| 40 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 41 | * @version $Id$ |
| 42 | * @package squirrelmail |
| 43 | * @subpackage decode |
| 44 | */ |
| 45 | |
| 46 | /** |
| 47 | * Decode koi8-u encoded strings |
| 48 | * @param string $string Encoded string |
| 49 | * @return string Decoded string |
| 50 | */ |
| 51 | function charset_decode_koi8_u ($string) { |
| 52 | // don't do decoding when there are no 8bit symbols |
| 53 | if (! sq_is8bit($string,'koi8-u')) |
| 54 | return $string; |
| 55 | |
| 56 | $koi8u = array( |
| 57 | "\x80" => '─', |
| 58 | "\x81" => '│', |
| 59 | "\x82" => '┌', |
| 60 | "\x83" => '┐', |
| 61 | "\x84" => '└', |
| 62 | "\x85" => '┘', |
| 63 | "\x86" => '├', |
| 64 | "\x87" => '┤', |
| 65 | "\x88" => '┬', |
| 66 | "\x89" => '┴', |
| 67 | "\x8A" => '┼', |
| 68 | "\x8B" => '▀', |
| 69 | "\x8C" => '▄', |
| 70 | "\x8D" => '█', |
| 71 | "\x8E" => '▌', |
| 72 | "\x8F" => '▐', |
| 73 | "\x90" => '░', |
| 74 | "\x91" => '▒', |
| 75 | "\x92" => '▓', |
| 76 | "\x93" => '⌠', |
| 77 | "\x94" => '■', |
| 78 | "\x95" => '∙', |
| 79 | "\x96" => '√', |
| 80 | "\x97" => '≈', |
| 81 | "\x98" => '≤', |
| 82 | "\x99" => '≥', |
| 83 | "\x9A" => ' ', |
| 84 | "\x9B" => '⌡', |
| 85 | "\x9C" => '°', |
| 86 | "\x9D" => '²', |
| 87 | "\x9E" => '·', |
| 88 | "\x9F" => '÷', |
| 89 | "\xA0" => '═', |
| 90 | "\xA1" => '║', |
| 91 | "\xA2" => '╒', |
| 92 | "\xA3" => 'ё', |
| 93 | "\xA4" => 'є', |
| 94 | "\xA5" => '╔', |
| 95 | "\xA6" => 'і', |
| 96 | "\xA7" => 'ї', |
| 97 | "\xA8" => '╗', |
| 98 | "\xA9" => '╘', |
| 99 | "\xAA" => '╙', |
| 100 | "\xAB" => '╚', |
| 101 | "\xAC" => '╛', |
| 102 | "\xAD" => 'ґ', |
| 103 | "\xAE" => '╝', |
| 104 | "\xAF" => '╞', |
| 105 | "\xB0" => '╟', |
| 106 | "\xB1" => '╠', |
| 107 | "\xB2" => '╡', |
| 108 | "\xB3" => 'Ё', |
| 109 | "\xB4" => 'Ѓ', |
| 110 | "\xB5" => '╣', |
| 111 | "\xB6" => 'І', |
| 112 | "\xB7" => 'Ї', |
| 113 | "\xB8" => '╦', |
| 114 | "\xB9" => '╧', |
| 115 | "\xBA" => '╨', |
| 116 | "\xBB" => '╩', |
| 117 | "\xBC" => '╪', |
| 118 | "\xBD" => 'Ґ', |
| 119 | "\xBE" => '╬', |
| 120 | "\xBF" => '©', |
| 121 | "\xC0" => 'ю', |
| 122 | "\xC1" => 'а', |
| 123 | "\xC2" => 'б', |
| 124 | "\xC3" => 'ц', |
| 125 | "\xC4" => 'д', |
| 126 | "\xC5" => 'е', |
| 127 | "\xC6" => 'ф', |
| 128 | "\xC7" => 'г', |
| 129 | "\xC8" => 'х', |
| 130 | "\xC9" => 'и', |
| 131 | "\xCA" => 'й', |
| 132 | "\xCB" => 'к', |
| 133 | "\xCC" => 'л', |
| 134 | "\xCD" => 'м', |
| 135 | "\xCE" => 'н', |
| 136 | "\xCF" => 'о', |
| 137 | "\xD0" => 'п', |
| 138 | "\xD1" => 'я', |
| 139 | "\xD2" => 'р', |
| 140 | "\xD3" => 'с', |
| 141 | "\xD4" => 'т', |
| 142 | "\xD5" => 'у', |
| 143 | "\xD6" => 'ж', |
| 144 | "\xD7" => 'в', |
| 145 | "\xD8" => 'ь', |
| 146 | "\xD9" => 'ы', |
| 147 | "\xDA" => 'з', |
| 148 | "\xDB" => 'ш', |
| 149 | "\xDC" => 'э', |
| 150 | "\xDD" => 'щ', |
| 151 | "\xDE" => 'ч', |
| 152 | "\xDF" => 'ъ', |
| 153 | "\xE0" => 'Ю', |
| 154 | "\xE1" => 'А', |
| 155 | "\xE2" => 'Б', |
| 156 | "\xE3" => 'Ц', |
| 157 | "\xE4" => 'Д', |
| 158 | "\xE5" => 'Е', |
| 159 | "\xE6" => 'Ф', |
| 160 | "\xE7" => 'Г', |
| 161 | "\xE8" => 'Х', |
| 162 | "\xE9" => 'И', |
| 163 | "\xEA" => 'Й', |
| 164 | "\xEB" => 'К', |
| 165 | "\xEC" => 'Л', |
| 166 | "\xED" => 'М', |
| 167 | "\xEE" => 'Н', |
| 168 | "\xEF" => 'О', |
| 169 | "\xF0" => 'П', |
| 170 | "\xF1" => 'Я', |
| 171 | "\xF2" => 'Р', |
| 172 | "\xF3" => 'С', |
| 173 | "\xF4" => 'Т', |
| 174 | "\xF5" => 'У', |
| 175 | "\xF6" => 'Ж', |
| 176 | "\xF7" => 'В', |
| 177 | "\xF8" => 'Ь', |
| 178 | "\xF9" => 'Ы', |
| 179 | "\xFA" => 'З', |
| 180 | "\xFB" => 'Ш', |
| 181 | "\xFC" => 'Э', |
| 182 | "\xFD" => 'Щ', |
| 183 | "\xFE" => 'Ч', |
| 184 | "\xFF" => 'Ъ' |
| 185 | ); |
| 186 | |
| 187 | $string = str_replace(array_keys($koi8u), array_values($koi8u), $string); |
| 188 | |
| 189 | return $string; |
| 190 | } |