Added subfoldering from an idea/patch by Thomas Pohl xraven at users.sourceforge...
[squirrelmail.git] / functions / decode / cp10017.php
1 <?php
2 /**
3 * decode/cp10017.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 cp10017 (MacUkrainian) decoding function that
10 * is needed to read cp10017 encoded mails in non-cp10017 locale.
11 *
12 * Apple states [2] that x-mac-ukrainian differs from x-mac-cyrillic [1]
13 * only in two places. According to [3] these symbols are:
14 * 0x92 - U+1168 - CYRILLIC CAPITAL LETTER GHE WITH UPTURN
15 * 0xD6 - U+1169 - CYRILLIC SMALL LETTER GHE WITH UPTURN
16 *
17 * References:
18 * 1. ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/MAC/CYRILLIC.TXT
19 * 2. http://developer.apple.com/documentation/macos8/TextIntlSvcs/TextEncodingConversionManager/TEC1.5/TEC.b0.html
20 * 3. http://shlimazl.nm.ru/rus/cptable.htm (page in Russian)
21 * @package squirrelmail
22 * @subpackage decode
23 */
24
25 /**
26 * Decode a cp10017 (MacUkrainian) string
27 * @param string $string Encoded string
28 * @return string $string Decoded string
29 */
30 function charset_decode_cp10017 ($string) {
31 global $default_charset;
32
33 if (strtolower($default_charset) == 'x-mac-ukrainian')
34 return $string;
35
36 /* Only do the slow convert if there are 8-bit characters */
37 /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
38 if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string) )
39 return $string;
40
41 $cp10017 = array(
42 "\x80" => '&#1040;',
43 "\x81" => '&#1041;',
44 "\x82" => '&#1042;',
45 "\x83" => '&#1043;',
46 "\x84" => '&#1044;',
47 "\x85" => '&#1045;',
48 "\x86" => '&#1046;',
49 "\x87" => '&#1047;',
50 "\x88" => '&#1048;',
51 "\x89" => '&#1049;',
52 "\x8A" => '&#1050;',
53 "\x8B" => '&#1051;',
54 "\x8C" => '&#1052;',
55 "\x8D" => '&#1053;',
56 "\x8E" => '&#1054;',
57 "\x8F" => '&#1055;',
58 "\x90" => '&#1056;',
59 "\x91" => '&#1057;',
60 "\x92" => '&#1168;',
61 "\x93" => '&#1059;',
62 "\x94" => '&#1060;',
63 "\x95" => '&#1061;',
64 "\x96" => '&#1062;',
65 "\x97" => '&#1063;',
66 "\x98" => '&#1064;',
67 "\x99" => '&#1065;',
68 "\x9A" => '&#1066;',
69 "\x9B" => '&#1067;',
70 "\x9C" => '&#1068;',
71 "\x9D" => '&#1069;',
72 "\x9E" => '&#1070;',
73 "\x9F" => '&#1071;',
74 "\xA0" => '&#8224;',
75 "\xA1" => '&#176;',
76 "\xA2" => '&#162;',
77 "\xA3" => '&#163;',
78 "\xA4" => '&#167;',
79 "\xA5" => '&#8226;',
80 "\xA6" => '&#182;',
81 "\xA7" => '&#1030;',
82 "\xA8" => '&#174;',
83 "\xA9" => '&#169;',
84 "\xAA" => '&#8482;',
85 "\xAB" => '&#1026;',
86 "\xAC" => '&#1106;',
87 "\xAD" => '&#8800;',
88 "\xAE" => '&#1027;',
89 "\xAF" => '&#1107;',
90 "\xB0" => '&#8734;',
91 "\xB1" => '&#177;',
92 "\xB2" => '&#8804;',
93 "\xB3" => '&#8805;',
94 "\xB4" => '&#1110;',
95 "\xB5" => '&#181;',
96 "\xB6" => '&#8706;',
97 "\xB7" => '&#1032;',
98 "\xB8" => '&#1028;',
99 "\xB9" => '&#1108;',
100 "\xBA" => '&#1031;',
101 "\xBB" => '&#1111;',
102 "\xBC" => '&#1033;',
103 "\xBD" => '&#1113;',
104 "\xBE" => '&#1034;',
105 "\xBF" => '&#1114;',
106 "\xC0" => '&#1112;',
107 "\xC1" => '&#1029;',
108 "\xC2" => '&#172;',
109 "\xC3" => '&#8730;',
110 "\xC4" => '&#402;',
111 "\xC5" => '&#8776;',
112 "\xC6" => '&#8710;',
113 "\xC7" => '&#171;',
114 "\xC8" => '&#187;',
115 "\xC9" => '&#8230;',
116 "\xCA" => '&#160;',
117 "\xCB" => '&#1035;',
118 "\xCC" => '&#1115;',
119 "\xCD" => '&#1036;',
120 "\xCE" => '&#1116;',
121 "\xCF" => '&#1109;',
122 "\xD0" => '&#8211;',
123 "\xD1" => '&#8212;',
124 "\xD2" => '&#8220;',
125 "\xD3" => '&#8221;',
126 "\xD4" => '&#8216;',
127 "\xD5" => '&#8217;',
128 "\xD6" => '&#1169;',
129 "\xD7" => '&#8222;',
130 "\xD8" => '&#1038;',
131 "\xD9" => '&#1118;',
132 "\xDA" => '&#1039;',
133 "\xDB" => '&#1119;',
134 "\xDC" => '&#8470;',
135 "\xDD" => '&#1025;',
136 "\xDE" => '&#1105;',
137 "\xDF" => '&#1103;',
138 "\xE0" => '&#1072;',
139 "\xE1" => '&#1073;',
140 "\xE2" => '&#1074;',
141 "\xE3" => '&#1075;',
142 "\xE4" => '&#1076;',
143 "\xE5" => '&#1077;',
144 "\xE6" => '&#1078;',
145 "\xE7" => '&#1079;',
146 "\xE8" => '&#1080;',
147 "\xE9" => '&#1081;',
148 "\xEA" => '&#1082;',
149 "\xEB" => '&#1083;',
150 "\xEC" => '&#1084;',
151 "\xED" => '&#1085;',
152 "\xEE" => '&#1086;',
153 "\xEF" => '&#1087;',
154 "\xF0" => '&#1088;',
155 "\xF1" => '&#1089;',
156 "\xF2" => '&#1090;',
157 "\xF3" => '&#1091;',
158 "\xF4" => '&#1092;',
159 "\xF5" => '&#1093;',
160 "\xF6" => '&#1094;',
161 "\xF7" => '&#1095;',
162 "\xF8" => '&#1096;',
163 "\xF9" => '&#1097;',
164 "\xFA" => '&#1098;',
165 "\xFB" => '&#1099;',
166 "\xFC" => '&#1100;',
167 "\xFD" => '&#1101;',
168 "\xFE" => '&#1102;',
169 "\xFF" => '&#164;'
170 );
171
172 $string = str_replace(array_keys($cp10017), array_values($cp10017), $string);
173
174 return $string;
175 }
176 ?>