Makes managing decoding easier. Mac decoding moved to separate cvs module
[squirrelmail.git] / functions / decode / koi8_u.php
1 <?php
2 /**
3 * decode/koi8-u.php
4 * $Id$
5 *
6 * Copyright (c) 2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file contains koi8-u decoding function that is needed to read
10 * koi8-u encoded mails in non-koi8-u locale.
11 *
12 * Original data taken from rfc2319
13 *
14 * Original copyright:
15 *
16 * Copyright (C) The Internet Society (1998). All Rights Reserved.
17 *
18 * This document and translations of it may be copied and furnished to
19 * others, and derivative works that comment on or otherwise explain it
20 * or assist in its implementation may be prepared, copied, published
21 * and distributed, in whole or in part, without restriction of any
22 * kind, provided that the above copyright notice and this paragraph are
23 * included on all such copies and derivative works. However, this
24 * document itself may not be modified in any way, such as by removing
25 * the copyright notice or references to the Internet Society or other
26 * Internet organizations, except as needed for the purpose of
27 * developing Internet standards in which case the procedures for
28 * copyrights defined in the Internet Standards process must be
29 * followed, or as required to translate it into languages other than
30 * English.
31 *
32 * The limited permissions granted above are perpetual and will not be
33 * revoked by the Internet Society or its successors or assigns.
34 *
35 * This document and the information contained herein is provided on an
36 * "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
37 * TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
38 * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
39 * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
40 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
41 *
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 global $default_charset;
53
54 if (strtolower($default_charset) == 'koi8-u')
55 return $string;
56
57 /* Only do the slow convert if there are 8-bit characters */
58 /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
59 if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string) )
60 return $string;
61
62 $koi8u = array(
63 "\x80" => '&#9472;',
64 "\x81" => '&#9474;',
65 "\x82" => '&#9484;',
66 "\x83" => '&#9488;',
67 "\x84" => '&#9492;',
68 "\x85" => '&#9496;',
69 "\x86" => '&#9500;',
70 "\x87" => '&#9508;',
71 "\x88" => '&#9516;',
72 "\x89" => '&#9524;',
73 "\x8A" => '&#9532;',
74 "\x8B" => '&#9600;',
75 "\x8C" => '&#9604;',
76 "\x8D" => '&#9608;',
77 "\x8E" => '&#9612;',
78 "\x8F" => '&#9616;',
79 "\x90" => '&#9617;',
80 "\x91" => '&#9618;',
81 "\x92" => '&#9619;',
82 "\x93" => '&#8992;',
83 "\x94" => '&#9632;',
84 "\x95" => '&#8729;',
85 "\x96" => '&#8730;',
86 "\x97" => '&#8776;',
87 "\x98" => '&#8804;',
88 "\x99" => '&#8805;',
89 "\x9A" => '&#160;',
90 "\x9B" => '&#8993;',
91 "\x9C" => '&#176;',
92 "\x9D" => '&#178;',
93 "\x9E" => '&#183;',
94 "\x9F" => '&#247;',
95 "\xA0" => '&#9552;',
96 "\xA1" => '&#9553;',
97 "\xA2" => '&#9554;',
98 "\xA3" => '&#1105;',
99 "\xA4" => '&#1108;',
100 "\xA5" => '&#9556;',
101 "\xA6" => '&#1110;',
102 "\xA7" => '&#1111;',
103 "\xA8" => '&#9559;',
104 "\xA9" => '&#9560;',
105 "\xAA" => '&#9561;',
106 "\xAB" => '&#9562;',
107 "\xAC" => '&#9563;',
108 "\xAD" => '&#1169;',
109 "\xAE" => '&#9565;',
110 "\xAF" => '&#9566;',
111 "\xB0" => '&#9567;',
112 "\xB1" => '&#9568;',
113 "\xB2" => '&#9569;',
114 "\xB3" => '&#1025;',
115 "\xB4" => '&#1027;',
116 "\xB5" => '&#9571;',
117 "\xB6" => '&#1030;',
118 "\xB7" => '&#1031;',
119 "\xB8" => '&#9574;',
120 "\xB9" => '&#9575;',
121 "\xBA" => '&#9576;',
122 "\xBB" => '&#9577;',
123 "\xBC" => '&#9578;',
124 "\xBD" => '&#1168;',
125 "\xBE" => '&#9580;',
126 "\xBF" => '&#169;',
127 "\xC0" => '&#1102;',
128 "\xC1" => '&#1072;',
129 "\xC2" => '&#1073;',
130 "\xC3" => '&#1094;',
131 "\xC4" => '&#1076;',
132 "\xC5" => '&#1077;',
133 "\xC6" => '&#1092;',
134 "\xC7" => '&#1075;',
135 "\xC8" => '&#1093;',
136 "\xC9" => '&#1080;',
137 "\xCA" => '&#1081;',
138 "\xCB" => '&#1082;',
139 "\xCC" => '&#1083;',
140 "\xCD" => '&#1084;',
141 "\xCE" => '&#1085;',
142 "\xCF" => '&#1086;',
143 "\xD0" => '&#1087;',
144 "\xD1" => '&#1103;',
145 "\xD2" => '&#1088;',
146 "\xD3" => '&#1089;',
147 "\xD4" => '&#1090;',
148 "\xD5" => '&#1091;',
149 "\xD6" => '&#1078;',
150 "\xD7" => '&#1074;',
151 "\xD8" => '&#1100;',
152 "\xD9" => '&#1099;',
153 "\xDA" => '&#1079;',
154 "\xDB" => '&#1096;',
155 "\xDC" => '&#1101;',
156 "\xDD" => '&#1097;',
157 "\xDE" => '&#1095;',
158 "\xDF" => '&#1098;',
159 "\xE0" => '&#1070;',
160 "\xE1" => '&#1040;',
161 "\xE2" => '&#1041;',
162 "\xE3" => '&#1062;',
163 "\xE4" => '&#1044;',
164 "\xE5" => '&#1045;',
165 "\xE6" => '&#1060;',
166 "\xE7" => '&#1043;',
167 "\xE8" => '&#1061;',
168 "\xE9" => '&#1048;',
169 "\xEA" => '&#1049;',
170 "\xEB" => '&#1050;',
171 "\xEC" => '&#1051;',
172 "\xED" => '&#1052;',
173 "\xEE" => '&#1053;',
174 "\xEF" => '&#1054;',
175 "\xF0" => '&#1055;',
176 "\xF1" => '&#1071;',
177 "\xF2" => '&#1056;',
178 "\xF3" => '&#1057;',
179 "\xF4" => '&#1058;',
180 "\xF5" => '&#1059;',
181 "\xF6" => '&#1046;',
182 "\xF7" => '&#1042;',
183 "\xF8" => '&#1068;',
184 "\xF9" => '&#1067;',
185 "\xFA" => '&#1047;',
186 "\xFB" => '&#1064;',
187 "\xFC" => '&#1069;',
188 "\xFD" => '&#1065;',
189 "\xFE" => '&#1063;',
190 "\xFF" => '&#1066;'
191 );
192
193 $string = str_replace(array_keys($koi8u), array_values($koi8u), $string);
194
195 return $string;
196 }
197
198 ?>