Adding decoding support for two DOSCyr charsets and several x-mac-* charsets.
[squirrelmail.git] / functions / decode / cp866.php
1 <?php
2 /*
3 * decode/cp866.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 cp866 decoding function that is needed to read
10 * cp866 encoded mails in non-cp866 locale.
11 *
12 * Original data taken from:
13 * ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/
14
15 Name: cp866_DOSCyrillicRussian to Unicode table
16 Unicode version: 2.0
17 Table version: 2.00
18 Table format: Format A
19 Date: 04/24/96
20 Authors: Lori Brownell <loribr@microsoft.com>
21 K.D. Chang <a-kchang@microsoft.com>
22 The entries are in cp866_DOSCyrillicRussian order
23 */
24
25
26 function charset_decode_cp866 ($string) {
27 global $default_charset;
28
29 if (strtolower($default_charset) == 'ibm866')
30 return $string;
31
32 /* Only do the slow convert if there are 8-bit characters */
33 /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
34 if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string) )
35 return $string;
36
37 $cp866 = array(
38 "\x80" => '&#1040;',
39 "\x81" => '&#1041;',
40 "\x82" => '&#1042;',
41 "\x83" => '&#1043;',
42 "\x84" => '&#1044;',
43 "\x85" => '&#1045;',
44 "\x86" => '&#1046;',
45 "\x87" => '&#1047;',
46 "\x88" => '&#1048;',
47 "\x89" => '&#1049;',
48 "\x8a" => '&#1050;',
49 "\x8b" => '&#1051;',
50 "\x8c" => '&#1052;',
51 "\x8d" => '&#1053;',
52 "\x8e" => '&#1054;',
53 "\x8f" => '&#1055;',
54 "\x90" => '&#1056;',
55 "\x91" => '&#1057;',
56 "\x92" => '&#1058;',
57 "\x93" => '&#1059;',
58 "\x94" => '&#1060;',
59 "\x95" => '&#1061;',
60 "\x96" => '&#1062;',
61 "\x97" => '&#1063;',
62 "\x98" => '&#1064;',
63 "\x99" => '&#1065;',
64 "\x9a" => '&#1066;',
65 "\x9b" => '&#1067;',
66 "\x9c" => '&#1068;',
67 "\x9d" => '&#1069;',
68 "\x9e" => '&#1070;',
69 "\x9f" => '&#1071;',
70 "\xa0" => '&#1072;',
71 "\xa1" => '&#1073;',
72 "\xa2" => '&#1074;',
73 "\xa3" => '&#1075;',
74 "\xa4" => '&#1076;',
75 "\xa5" => '&#1077;',
76 "\xa6" => '&#1078;',
77 "\xa7" => '&#1079;',
78 "\xa8" => '&#1080;',
79 "\xa9" => '&#1081;',
80 "\xaa" => '&#1082;',
81 "\xab" => '&#1083;',
82 "\xac" => '&#1084;',
83 "\xad" => '&#1085;',
84 "\xae" => '&#1086;',
85 "\xaf" => '&#1087;',
86 "\xb0" => '&#9617;',
87 "\xb1" => '&#9618;',
88 "\xb2" => '&#9619;',
89 "\xb3" => '&#9474;',
90 "\xb4" => '&#9508;',
91 "\xb5" => '&#9569;',
92 "\xb6" => '&#9570;',
93 "\xb7" => '&#9558;',
94 "\xb8" => '&#9557;',
95 "\xb9" => '&#9571;',
96 "\xba" => '&#9553;',
97 "\xbb" => '&#9559;',
98 "\xbc" => '&#9565;',
99 "\xbd" => '&#9564;',
100 "\xbe" => '&#9563;',
101 "\xbf" => '&#9488;',
102 "\xc0" => '&#9492;',
103 "\xc1" => '&#9524;',
104 "\xc2" => '&#9516;',
105 "\xc3" => '&#9500;',
106 "\xc4" => '&#9472;',
107 "\xc5" => '&#9532;',
108 "\xc6" => '&#9566;',
109 "\xc7" => '&#9567;',
110 "\xc8" => '&#9562;',
111 "\xc9" => '&#9556;',
112 "\xca" => '&#9577;',
113 "\xcb" => '&#9574;',
114 "\xcc" => '&#9568;',
115 "\xcd" => '&#9552;',
116 "\xce" => '&#9580;',
117 "\xcf" => '&#9575;',
118 "\xd0" => '&#9576;',
119 "\xd1" => '&#9572;',
120 "\xd2" => '&#9573;',
121 "\xd3" => '&#9561;',
122 "\xd4" => '&#9560;',
123 "\xd5" => '&#9554;',
124 "\xd6" => '&#9555;',
125 "\xd7" => '&#9579;',
126 "\xd8" => '&#9578;',
127 "\xd9" => '&#9496;',
128 "\xda" => '&#9484;',
129 "\xdb" => '&#9608;',
130 "\xdc" => '&#9604;',
131 "\xdd" => '&#9612;',
132 "\xde" => '&#9616;',
133 "\xdf" => '&#9600;',
134 "\xe0" => '&#1088;',
135 "\xe1" => '&#1089;',
136 "\xe2" => '&#1090;',
137 "\xe3" => '&#1091;',
138 "\xe4" => '&#1092;',
139 "\xe5" => '&#1093;',
140 "\xe6" => '&#1094;',
141 "\xe7" => '&#1095;',
142 "\xe8" => '&#1096;',
143 "\xe9" => '&#1097;',
144 "\xea" => '&#1098;',
145 "\xeb" => '&#1099;',
146 "\xec" => '&#1100;',
147 "\xed" => '&#1101;',
148 "\xee" => '&#1102;',
149 "\xef" => '&#1103;',
150 "\xf0" => '&#1025;',
151 "\xf1" => '&#1105;',
152 "\xf2" => '&#1028;',
153 "\xf3" => '&#1108;',
154 "\xf4" => '&#1031;',
155 "\xf5" => '&#1111;',
156 "\xf6" => '&#1038;',
157 "\xf7" => '&#1118;',
158 "\xf8" => '&#176;',
159 "\xf9" => '&#8729;',
160 "\xfa" => '&#183;',
161 "\xfb" => '&#8730;',
162 "\xfc" => '&#8470;',
163 "\xfd" => '&#164;',
164 "\xfe" => '&#9632;',
165 "\xff" => '&#160;'
166 );
167
168 $string = str_replace(array_keys($cp866), array_values($cp866), $string);
169
170 return $string;
171 }