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