adding other five charsets needed for some translations
authortokul <tokul@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 10 Sep 2004 16:19:45 +0000 (16:19 +0000)
committertokul <tokul@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 10 Sep 2004 16:19:45 +0000 (16:19 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@8050 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/encode/cp1251.php [new file with mode: 0644]
functions/encode/cp1255.php [new file with mode: 0644]
functions/encode/cp1256.php [new file with mode: 0644]
functions/encode/koi8_r.php [new file with mode: 0644]
functions/encode/koi8_u.php [new file with mode: 0644]

diff --git a/functions/encode/cp1251.php b/functions/encode/cp1251.php
new file mode 100644 (file)
index 0000000..7755d1c
--- /dev/null
@@ -0,0 +1,177 @@
+<?php
+/**
+ * cp1251 encoding functions
+ *
+ * takes a string of unicode entities and converts it to a cp1251 encoded string
+ * Unsupported characters are replaced with ?.
+ *
+ * @version $Id$
+ * @copyright Copyright &copy; SquirrelMail Development Team, 2004
+ * @package squirrelmail
+ * @subpackage encode
+ */
+
+/**
+ * Converts string to cp1251
+ * @param string $string text with numeric unicode entities
+ * @return string cp1251 encoded text
+ */
+function charset_encode_cp1251 ($string) {
+   // don't run encoding function, if there is no encoded characters
+   if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
+
+    $string=preg_replace("/&#([0-9]+);/e","unicodetocp1251('\\1')",$string);
+    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetocp1251(hexdec('\\1'))",$string);
+    
+    return $string;
+}
+
+/**
+ * Return cp1251 symbol when unicode character number is provided
+ * 
+ * This function is used internally by charset_encode_cp1251 
+ * function. It might be unavailable to other squirrelmail functions.
+ * Don't use it or make sure, that functions/encode/cp1251.php is 
+ * included. 
+ *
+ * @param int $var decimal unicode value
+ * @return string cp1251 character
+ */
+function unicodetocp1251($var) {
+
+    $cp1251chars=array('160' => "\xA0",
+                       '164' => "\xA4",
+                       '166' => "\xA6",
+                       '167' => "\xA7",
+                       '169' => "\xA9",
+                       '171' => "\xAB",
+                       '172' => "\xAC",
+                       '173' => "\xAD",
+                       '174' => "\xAE",
+                       '176' => "\xB0",
+                       '177' => "\xB1",
+                       '181' => "\xB5",
+                       '182' => "\xB6",
+                       '183' => "\xB7",
+                       '187' => "\xBB",
+                       '1025' => "\xA8",
+                       '1026' => "\x80",
+                       '1027' => "\x81",
+                       '1028' => "\xAA",
+                       '1029' => "\xBD",
+                       '1030' => "\xB2",
+                       '1031' => "\xAF",
+                       '1032' => "\xA3",
+                       '1033' => "\x8A",
+                       '1034' => "\x8C",
+                       '1035' => "\x8E",
+                       '1036' => "\x8D",
+                       '1038' => "\xA1",
+                       '1039' => "\x8F",
+                       '1040' => "\xC0",
+                       '1041' => "\xC1",
+                       '1042' => "\xC2",
+                       '1043' => "\xC3",
+                       '1044' => "\xC4",
+                       '1045' => "\xC5",
+                       '1046' => "\xC6",
+                       '1047' => "\xC7",
+                       '1048' => "\xC8",
+                       '1049' => "\xC9",
+                       '1050' => "\xCA",
+                       '1051' => "\xCB",
+                       '1052' => "\xCC",
+                       '1053' => "\xCD",
+                       '1054' => "\xCE",
+                       '1055' => "\xCF",
+                       '1056' => "\xD0",
+                       '1057' => "\xD1",
+                       '1058' => "\xD2",
+                       '1059' => "\xD3",
+                       '1060' => "\xD4",
+                       '1061' => "\xD5",
+                       '1062' => "\xD6",
+                       '1063' => "\xD7",
+                       '1064' => "\xD8",
+                       '1065' => "\xD9",
+                       '1066' => "\xDA",
+                       '1067' => "\xDB",
+                       '1068' => "\xDC",
+                       '1069' => "\xDD",
+                       '1070' => "\xDE",
+                       '1071' => "\xDF",
+                       '1072' => "\xE0",
+                       '1073' => "\xE1",
+                       '1074' => "\xE2",
+                       '1075' => "\xE3",
+                       '1076' => "\xE4",
+                       '1077' => "\xE5",
+                       '1078' => "\xE6",
+                       '1079' => "\xE7",
+                       '1080' => "\xE8",
+                       '1081' => "\xE9",
+                       '1082' => "\xEA",
+                       '1083' => "\xEB",
+                       '1084' => "\xEC",
+                       '1085' => "\xED",
+                       '1086' => "\xEE",
+                       '1087' => "\xEF",
+                       '1088' => "\xF0",
+                       '1089' => "\xF1",
+                       '1090' => "\xF2",
+                       '1091' => "\xF3",
+                       '1092' => "\xF4",
+                       '1093' => "\xF5",
+                       '1094' => "\xF6",
+                       '1095' => "\xF7",
+                       '1096' => "\xF8",
+                       '1097' => "\xF9",
+                       '1098' => "\xFA",
+                       '1099' => "\xFB",
+                       '1100' => "\xFC",
+                       '1101' => "\xFD",
+                       '1102' => "\xFE",
+                       '1103' => "\xFF",
+                       '1105' => "\xB8",
+                       '1106' => "\x90",
+                       '1107' => "\x83",
+                       '1108' => "\xBA",
+                       '1109' => "\xBE",
+                       '1110' => "\xB3",
+                       '1111' => "\xBF",
+                       '1112' => "\xBC",
+                       '1113' => "\x9A",
+                       '1114' => "\x9C",
+                       '1115' => "\x9E",
+                       '1116' => "\x9D",
+                       '1118' => "\xA2",
+                       '1119' => "\x9F",
+                       '1168' => "\xA5",
+                       '1169' => "\xB4",
+                       '8211' => "\x96",
+                       '8212' => "\x97",
+                       '8216' => "\x91",
+                       '8217' => "\x92",
+                       '8218' => "\x82",
+                       '8220' => "\x93",
+                       '8221' => "\x94",
+                       '8222' => "\x84",
+                       '8224' => "\x86",
+                       '8225' => "\x87",
+                       '8226' => "\x95",
+                       '8230' => "\x85",
+                       '8240' => "\x89",
+                       '8249' => "\x8B",
+                       '8250' => "\x9B",
+                       '8364' => "\x88",
+                       '8470' => "\xB9",
+                       '8482' => "\x99");
+
+    if (array_key_exists($var,$cp1251chars)) {
+        $ret=$cp1251chars[$var];
+    } else {
+        $ret='?';
+    }
+    return $ret;
+}
+?>
\ No newline at end of file
diff --git a/functions/encode/cp1255.php b/functions/encode/cp1255.php
new file mode 100644 (file)
index 0000000..06ef050
--- /dev/null
@@ -0,0 +1,155 @@
+<?php
+/**
+ * cp1255 encoding functions
+ *
+ * takes a string of unicode entities and converts it to a cp1255 encoded string
+ * Unsupported characters are replaced with ?.
+ *
+ * @version $Id$
+ * @copyright Copyright &copy; SquirrelMail Development Team, 2004
+ * @package squirrelmail
+ * @subpackage encode
+ */
+
+/**
+ * Converts string to cp1255
+ * @param string $string text with numeric unicode entities
+ * @return string cp1255 encoded text
+ */
+function charset_encode_cp1255 ($string) {
+   // don't run encoding function, if there is no encoded characters
+   if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
+
+    $string=preg_replace("/&#([0-9]+);/e","unicodetocp1255('\\1')",$string);
+    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetocp1255(hexdec('\\1'))",$string);
+    
+    return $string;
+}
+
+/**
+ * Return cp1255 symbol when unicode character number is provided
+ * 
+ * This function is used internally by charset_encode_cp1255 
+ * function. It might be unavailable to other squirrelmail functions.
+ * Don't use it or make sure, that functions/encode/cp1255.php is 
+ * included. 
+ *
+ * @param int $var decimal unicode value
+ * @return string cp1255 character
+ */
+function unicodetocp1255($var) {
+
+    $cp1255chars=array('160' => "\xA0",
+                       '161' => "\xA1",
+                       '162' => "\xA2",
+                       '163' => "\xA3",
+                       '165' => "\xA5",
+                       '166' => "\xA6",
+                       '167' => "\xA7",
+                       '168' => "\xA8",
+                       '169' => "\xA9",
+                       '171' => "\xAB",
+                       '172' => "\xAC",
+                       '173' => "\xAD",
+                       '174' => "\xAE",
+                       '175' => "\xAF",
+                       '176' => "\xB0",
+                       '177' => "\xB1",
+                       '178' => "\xB2",
+                       '179' => "\xB3",
+                       '180' => "\xB4",
+                       '181' => "\xB5",
+                       '182' => "\xB6",
+                       '183' => "\xB7",
+                       '184' => "\xB8",
+                       '185' => "\xB9",
+                       '187' => "\xBB",
+                       '188' => "\xBC",
+                       '189' => "\xBD",
+                       '190' => "\xBE",
+                       '191' => "\xBF",
+                       '215' => "\xAA",
+                       '247' => "\xBA",
+                       '402' => "\x83",
+                       '710' => "\x88",
+                       '732' => "\x98",
+                       '1456' => "\xC0",
+                       '1457' => "\xC1",
+                       '1458' => "\xC2",
+                       '1459' => "\xC3",
+                       '1460' => "\xC4",
+                       '1461' => "\xC5",
+                       '1462' => "\xC6",
+                       '1463' => "\xC7",
+                       '1464' => "\xC8",
+                       '1465' => "\xC9",
+                       '1467' => "\xCB",
+                       '1468' => "\xCC",
+                       '1469' => "\xCD",
+                       '1470' => "\xCE",
+                       '1471' => "\xCF",
+                       '1472' => "\xD0",
+                       '1473' => "\xD1",
+                       '1474' => "\xD2",
+                       '1475' => "\xD3",
+                       '1488' => "\xE0",
+                       '1489' => "\xE1",
+                       '1490' => "\xE2",
+                       '1491' => "\xE3",
+                       '1492' => "\xE4",
+                       '1493' => "\xE5",
+                       '1494' => "\xE6",
+                       '1495' => "\xE7",
+                       '1496' => "\xE8",
+                       '1497' => "\xE9",
+                       '1498' => "\xEA",
+                       '1499' => "\xEB",
+                       '1500' => "\xEC",
+                       '1501' => "\xED",
+                       '1502' => "\xEE",
+                       '1503' => "\xEF",
+                       '1504' => "\xF0",
+                       '1505' => "\xF1",
+                       '1506' => "\xF2",
+                       '1507' => "\xF3",
+                       '1508' => "\xF4",
+                       '1509' => "\xF5",
+                       '1510' => "\xF6",
+                       '1511' => "\xF7",
+                       '1512' => "\xF8",
+                       '1513' => "\xF9",
+                       '1514' => "\xFA",
+                       '1520' => "\xD4",
+                       '1521' => "\xD5",
+                       '1522' => "\xD6",
+                       '1523' => "\xD7",
+                       '1524' => "\xD8",
+                       '8206' => "\xFD",
+                       '8207' => "\xFE",
+                       '8211' => "\x96",
+                       '8212' => "\x97",
+                       '8216' => "\x91",
+                       '8217' => "\x92",
+                       '8218' => "\x82",
+                       '8220' => "\x93",
+                       '8221' => "\x94",
+                       '8222' => "\x84",
+                       '8224' => "\x86",
+                       '8225' => "\x87",
+                       '8226' => "\x95",
+                       '8230' => "\x85",
+                       '8240' => "\x89",
+                       '8249' => "\x8B",
+                       '8250' => "\x9B",
+                       '8362' => "\xA4",
+                       '8364' => "\x80",
+                       '8482' => "\x99");
+
+    if (array_key_exists($var,$cp1255chars)) {
+        $ret=$cp1255chars[$var];
+    } else {
+        $ret='?';
+    }
+    return $ret;
+}
+?>
\ No newline at end of file
diff --git a/functions/encode/cp1256.php b/functions/encode/cp1256.php
new file mode 100644 (file)
index 0000000..cfeac38
--- /dev/null
@@ -0,0 +1,178 @@
+<?php
+/**
+ * cp1256 encoding functions
+ *
+ * takes a string of unicode entities and converts it to a cp1256 encoded string
+ * Unsupported characters are replaced with ?.
+ *
+ * @version $Id$
+ * @copyright Copyright &copy; SquirrelMail Development Team, 2004
+ * @package squirrelmail
+ * @subpackage encode
+ */
+
+/**
+ * Converts string to cp1256
+ * @param string $string text with numeric unicode entities
+ * @return string cp1256 encoded text
+ */
+function charset_encode_cp1256 ($string) {
+   // don't run encoding function, if there is no encoded characters
+   if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
+
+    $string=preg_replace("/&#([0-9]+);/e","unicodetocp1256('\\1')",$string);
+    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetocp1256(hexdec('\\1'))",$string);
+    
+    return $string;
+}
+
+/**
+ * Return cp1256 symbol when unicode character number is provided
+ * 
+ * This function is used internally by charset_encode_cp1256 
+ * function. It might be unavailable to other squirrelmail functions.
+ * Don't use it or make sure, that functions/encode/cp1256.php is 
+ * included. 
+ *
+ * @param int $var decimal unicode value
+ * @return string cp1256 character
+ */
+function unicodetocp1256($var) {
+
+    $cp1256chars=array('160' => "\xA0",
+                       '162' => "\xA2",
+                       '163' => "\xA3",
+                       '164' => "\xA4",
+                       '165' => "\xA5",
+                       '166' => "\xA6",
+                       '167' => "\xA7",
+                       '168' => "\xA8",
+                       '169' => "\xA9",
+                       '171' => "\xAB",
+                       '172' => "\xAC",
+                       '173' => "\xAD",
+                       '174' => "\xAE",
+                       '175' => "\xAF",
+                       '176' => "\xB0",
+                       '177' => "\xB1",
+                       '178' => "\xB2",
+                       '179' => "\xB3",
+                       '180' => "\xB4",
+                       '181' => "\xB5",
+                       '182' => "\xB6",
+                       '183' => "\xB7",
+                       '184' => "\xB8",
+                       '185' => "\xB9",
+                       '187' => "\xBB",
+                       '188' => "\xBC",
+                       '189' => "\xBD",
+                       '190' => "\xBE",
+                       '215' => "\xD7",
+                       '224' => "\xE0",
+                       '226' => "\xE2",
+                       '231' => "\xE7",
+                       '232' => "\xE8",
+                       '233' => "\xE9",
+                       '234' => "\xEA",
+                       '235' => "\xEB",
+                       '238' => "\xEE",
+                       '239' => "\xEF",
+                       '244' => "\xF4",
+                       '247' => "\xF7",
+                       '249' => "\xF9",
+                       '251' => "\xFB",
+                       '252' => "\xFC",
+                       '338' => "\x8C",
+                       '339' => "\x9C",
+                       '402' => "\x83",
+                       '710' => "\x88",
+                       '1548' => "\xA1",
+                       '1563' => "\xBA",
+                       '1567' => "\xBF",
+                       '1569' => "\xC1",
+                       '1570' => "\xC2",
+                       '1571' => "\xC3",
+                       '1572' => "\xC4",
+                       '1573' => "\xC5",
+                       '1574' => "\xC6",
+                       '1575' => "\xC7",
+                       '1576' => "\xC8",
+                       '1577' => "\xC9",
+                       '1578' => "\xCA",
+                       '1579' => "\xCB",
+                       '1580' => "\xCC",
+                       '1581' => "\xCD",
+                       '1582' => "\xCE",
+                       '1583' => "\xCF",
+                       '1584' => "\xD0",
+                       '1585' => "\xD1",
+                       '1586' => "\xD2",
+                       '1587' => "\xD3",
+                       '1588' => "\xD4",
+                       '1589' => "\xD5",
+                       '1590' => "\xD6",
+                       '1591' => "\xD8",
+                       '1592' => "\xD9",
+                       '1593' => "\xDA",
+                       '1594' => "\xDB",
+                       '1600' => "\xDC",
+                       '1601' => "\xDD",
+                       '1602' => "\xDE",
+                       '1603' => "\xDF",
+                       '1604' => "\xE1",
+                       '1605' => "\xE3",
+                       '1606' => "\xE4",
+                       '1607' => "\xE5",
+                       '1608' => "\xE6",
+                       '1609' => "\xEC",
+                       '1610' => "\xED",
+                       '1611' => "\xF0",
+                       '1612' => "\xF1",
+                       '1613' => "\xF2",
+                       '1614' => "\xF3",
+                       '1615' => "\xF5",
+                       '1616' => "\xF6",
+                       '1617' => "\xF8",
+                       '1618' => "\xFA",
+                       '1657' => "\x8A",
+                       '1662' => "\x81",
+                       '1670' => "\x8D",
+                       '1672' => "\x8F",
+                       '1681' => "\x9A",
+                       '1688' => "\x8E",
+                       '1705' => "\x98",
+                       '1711' => "\x90",
+                       '1722' => "\x9F",
+                       '1726' => "\xAA",
+                       '1729' => "\xC0",
+                       '1746' => "\xFF",
+                       '8204' => "\x9D",
+                       '8205' => "\x9E",
+                       '8206' => "\xFD",
+                       '8207' => "\xFE",
+                       '8211' => "\x96",
+                       '8212' => "\x97",
+                       '8216' => "\x91",
+                       '8217' => "\x92",
+                       '8218' => "\x82",
+                       '8220' => "\x93",
+                       '8221' => "\x94",
+                       '8222' => "\x84",
+                       '8224' => "\x86",
+                       '8225' => "\x87",
+                       '8226' => "\x95",
+                       '8230' => "\x85",
+                       '8240' => "\x89",
+                       '8249' => "\x8B",
+                       '8250' => "\x9B",
+                       '8364' => "\x80",
+                       '8482' => "\x99");
+
+    if (array_key_exists($var,$cp1256chars)) {
+        $ret=$cp1256chars[$var];
+    } else {
+        $ret='?';
+    }
+    return $ret;
+}
+?>
\ No newline at end of file
diff --git a/functions/encode/koi8_r.php b/functions/encode/koi8_r.php
new file mode 100644 (file)
index 0000000..78075ea
--- /dev/null
@@ -0,0 +1,178 @@
+<?php
+/**
+ * koi8-r encoding functions
+ *
+ * takes a string of unicode entities and converts it to a koi8-r encoded string
+ * Unsupported characters are replaced with ?.
+ *
+ * @version $Id$
+ * @copyright Copyright &copy; SquirrelMail Development Team, 2004
+ * @package squirrelmail
+ * @subpackage encode
+ */
+
+/**
+ * Converts string to koi8-r
+ * @param string $string text with numeric unicode entities
+ * @return string koi8-r encoded text
+ */
+function charset_encode_koi8_r ($string) {
+   // don't run encoding function, if there is no encoded characters
+   if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
+
+    $string=preg_replace("/&#([0-9]+);/e","unicodetokoi8r('\\1')",$string);
+    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetokoi8r(hexdec('\\1'))",$string);
+    
+    return $string;
+}
+
+/**
+ * Return koi8-r symbol when unicode character number is provided
+ * 
+ * This function is used internally by charset_encode_koi8_r 
+ * function. It might be unavailable to other squirrelmail functions.
+ * Don't use it or make sure, that functions/encode/koi8_r.php is 
+ * included. 
+ *
+ * @param int $var decimal unicode value
+ * @return string koi8-r character
+ */
+function unicodetokoi8r($var) {
+
+    $koi8rchars=array('160' => "\x9A",
+                      '169' => "\xBF",
+                      '176' => "\x9C",
+                      '178' => "\x9D",
+                      '183' => "\x9E",
+                      '247' => "\x9F",
+                      '1025' => "\xB3",
+                      '1040' => "\xE1",
+                      '1041' => "\xE2",
+                      '1042' => "\xF7",
+                      '1043' => "\xE7",
+                      '1044' => "\xE4",
+                      '1045' => "\xE5",
+                      '1046' => "\xF6",
+                      '1047' => "\xFA",
+                      '1048' => "\xE9",
+                      '1049' => "\xEA",
+                      '1050' => "\xEB",
+                      '1051' => "\xEC",
+                      '1052' => "\xED",
+                      '1053' => "\xEE",
+                      '1054' => "\xEF",
+                      '1055' => "\xF0",
+                      '1056' => "\xF2",
+                      '1057' => "\xF3",
+                      '1058' => "\xF4",
+                      '1059' => "\xF5",
+                      '1060' => "\xE6",
+                      '1061' => "\xE8",
+                      '1062' => "\xE3",
+                      '1063' => "\xFE",
+                      '1064' => "\xFB",
+                      '1065' => "\xFD",
+                      '1066' => "\xFF",
+                      '1067' => "\xF9",
+                      '1068' => "\xF8",
+                      '1069' => "\xFC",
+                      '1070' => "\xE0",
+                      '1071' => "\xF1",
+                      '1072' => "\xC1",
+                      '1073' => "\xC2",
+                      '1074' => "\xD7",
+                      '1075' => "\xC7",
+                      '1076' => "\xC4",
+                      '1077' => "\xC5",
+                      '1078' => "\xD6",
+                      '1079' => "\xDA",
+                      '1080' => "\xC9",
+                      '1081' => "\xCA",
+                      '1082' => "\xCB",
+                      '1083' => "\xCC",
+                      '1084' => "\xCD",
+                      '1085' => "\xCE",
+                      '1086' => "\xCF",
+                      '1087' => "\xD0",
+                      '1088' => "\xD2",
+                      '1089' => "\xD3",
+                      '1090' => "\xD4",
+                      '1091' => "\xD5",
+                      '1092' => "\xC6",
+                      '1093' => "\xC8",
+                      '1094' => "\xC3",
+                      '1095' => "\xDE",
+                      '1096' => "\xDB",
+                      '1097' => "\xDD",
+                      '1098' => "\xDF",
+                      '1099' => "\xD9",
+                      '1100' => "\xD8",
+                      '1101' => "\xDC",
+                      '1102' => "\xC0",
+                      '1103' => "\xD1",
+                      '1105' => "\xA3",
+                      '8729' => "\x95",
+                      '8730' => "\x96",
+                      '8776' => "\x97",
+                      '8804' => "\x98",
+                      '8805' => "\x99",
+                      '8992' => "\x93",
+                      '8993' => "\x9B",
+                      '9472' => "\x80",
+                      '9474' => "\x81",
+                      '9484' => "\x82",
+                      '9488' => "\x83",
+                      '9492' => "\x84",
+                      '9496' => "\x85",
+                      '9500' => "\x86",
+                      '9508' => "\x87",
+                      '9516' => "\x88",
+                      '9524' => "\x89",
+                      '9532' => "\x8A",
+                      '9552' => "\xA0",
+                      '9553' => "\xA1",
+                      '9554' => "\xA2",
+                      '9555' => "\xA4",
+                      '9556' => "\xA5",
+                      '9557' => "\xA6",
+                      '9558' => "\xA7",
+                      '9559' => "\xA8",
+                      '9560' => "\xA9",
+                      '9561' => "\xAA",
+                      '9562' => "\xAB",
+                      '9563' => "\xAC",
+                      '9564' => "\xAD",
+                      '9565' => "\xAE",
+                      '9566' => "\xAF",
+                      '9567' => "\xB0",
+                      '9568' => "\xB1",
+                      '9569' => "\xB2",
+                      '9570' => "\xB4",
+                      '9571' => "\xB5",
+                      '9572' => "\xB6",
+                      '9573' => "\xB7",
+                      '9574' => "\xB8",
+                      '9575' => "\xB9",
+                      '9576' => "\xBA",
+                      '9577' => "\xBB",
+                      '9578' => "\xBC",
+                      '9579' => "\xBD",
+                      '9580' => "\xBE",
+                      '9600' => "\x8B",
+                      '9604' => "\x8C",
+                      '9608' => "\x8D",
+                      '9612' => "\x8E",
+                      '9616' => "\x8F",
+                      '9617' => "\x90",
+                      '9618' => "\x91",
+                      '9619' => "\x92",
+                      '9632' => "\x94");
+
+    if (array_key_exists($var,$koi8rchars)) {
+        $ret=$koi8rchars[$var];
+    } else {
+        $ret='?';
+    }
+    return $ret;
+}
+?>
\ No newline at end of file
diff --git a/functions/encode/koi8_u.php b/functions/encode/koi8_u.php
new file mode 100644 (file)
index 0000000..882a519
--- /dev/null
@@ -0,0 +1,178 @@
+<?php
+/**
+ * koi8-u encoding functions
+ *
+ * takes a string of unicode entities and converts it to a koi8-u encoded string
+ * Unsupported characters are replaced with ?.
+ *
+ * @version $Id$
+ * @copyright Copyright &copy; SquirrelMail Development Team, 2004
+ * @package squirrelmail
+ * @subpackage encode
+ */
+
+/**
+ * Converts string to koi8-u
+ * @param string $string text with numeric unicode entities
+ * @return string koi8-u encoded text
+ */
+function charset_encode_koi8_u ($string) {
+   // don't run encoding function, if there is no encoded characters
+   if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
+
+    $string=preg_replace("/&#([0-9]+);/e","unicodetokoi8u('\\1')",$string);
+    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetokoi8u(hexdec('\\1'))",$string);
+    
+    return $string;
+}
+
+/**
+ * Return koi8-u symbol when unicode character number is provided
+ * 
+ * This function is used internally by charset_encode_koi8_u 
+ * function. It might be unavailable to other squirrelmail functions.
+ * Don't use it or make sure, that functions/encode/koi8_u.php is 
+ * included. 
+ *
+ * @param int $var decimal unicode value
+ * @return string koi8-u character
+ */
+function unicodetokoi8u($var) {
+
+    $koi8uchars=array('160' => "\x9A",
+                      '169' => "\xBF",
+                      '176' => "\x9C",
+                      '178' => "\x9D",
+                      '183' => "\x9E",
+                      '247' => "\x9F",
+                      '1025' => "\xB3",
+                      '1028' => "\xB4",
+                      '1030' => "\xB6",
+                      '1031' => "\xB7",
+                      '1040' => "\xE1",
+                      '1041' => "\xE2",
+                      '1042' => "\xF7",
+                      '1043' => "\xE7",
+                      '1044' => "\xE4",
+                      '1045' => "\xE5",
+                      '1046' => "\xF6",
+                      '1047' => "\xFA",
+                      '1048' => "\xE9",
+                      '1049' => "\xEA",
+                      '1050' => "\xEB",
+                      '1051' => "\xEC",
+                      '1052' => "\xED",
+                      '1053' => "\xEE",
+                      '1054' => "\xEF",
+                      '1055' => "\xF0",
+                      '1056' => "\xF2",
+                      '1057' => "\xF3",
+                      '1058' => "\xF4",
+                      '1059' => "\xF5",
+                      '1060' => "\xE6",
+                      '1061' => "\xE8",
+                      '1062' => "\xE3",
+                      '1063' => "\xFE",
+                      '1064' => "\xFB",
+                      '1065' => "\xFD",
+                      '1066' => "\xFF",
+                      '1067' => "\xF9",
+                      '1068' => "\xF8",
+                      '1069' => "\xFC",
+                      '1070' => "\xE0",
+                      '1071' => "\xF1",
+                      '1072' => "\xC1",
+                      '1073' => "\xC2",
+                      '1074' => "\xD7",
+                      '1075' => "\xC7",
+                      '1076' => "\xC4",
+                      '1077' => "\xC5",
+                      '1078' => "\xD6",
+                      '1079' => "\xDA",
+                      '1080' => "\xC9",
+                      '1081' => "\xCA",
+                      '1082' => "\xCB",
+                      '1083' => "\xCC",
+                      '1084' => "\xCD",
+                      '1085' => "\xCE",
+                      '1086' => "\xCF",
+                      '1087' => "\xD0",
+                      '1088' => "\xD2",
+                      '1089' => "\xD3",
+                      '1090' => "\xD4",
+                      '1091' => "\xD5",
+                      '1092' => "\xC6",
+                      '1093' => "\xC8",
+                      '1094' => "\xC3",
+                      '1095' => "\xDE",
+                      '1096' => "\xDB",
+                      '1097' => "\xDD",
+                      '1098' => "\xDF",
+                      '1099' => "\xD9",
+                      '1100' => "\xD8",
+                      '1101' => "\xDC",
+                      '1102' => "\xC0",
+                      '1103' => "\xD1",
+                      '1105' => "\xA3",
+                      '1108' => "\xA4",
+                      '1110' => "\xA6",
+                      '1111' => "\xA7",
+                      '1168' => "\xBD",
+                      '1169' => "\xAD",
+                      '8729' => "\x95",
+                      '8730' => "\x96",
+                      '8776' => "\x97",
+                      '8804' => "\x98",
+                      '8805' => "\x99",
+                      '8992' => "\x93",
+                      '8993' => "\x9B",
+                      '9472' => "\x80",
+                      '9474' => "\x81",
+                      '9484' => "\x82",
+                      '9488' => "\x83",
+                      '9492' => "\x84",
+                      '9496' => "\x85",
+                      '9500' => "\x86",
+                      '9508' => "\x87",
+                      '9516' => "\x88",
+                      '9524' => "\x89",
+                      '9532' => "\x8A",
+                      '9552' => "\xA0",
+                      '9553' => "\xA1",
+                      '9554' => "\xA2",
+                      '9556' => "\xA5",
+                      '9559' => "\xA8",
+                      '9560' => "\xA9",
+                      '9561' => "\xAA",
+                      '9562' => "\xAB",
+                      '9563' => "\xAC",
+                      '9565' => "\xAE",
+                      '9566' => "\xAF",
+                      '9567' => "\xB0",
+                      '9568' => "\xB1",
+                      '9569' => "\xB2",
+                      '9571' => "\xB5",
+                      '9574' => "\xB8",
+                      '9575' => "\xB9",
+                      '9576' => "\xBA",
+                      '9577' => "\xBB",
+                      '9578' => "\xBC",
+                      '9580' => "\xBE",
+                      '9600' => "\x8B",
+                      '9604' => "\x8C",
+                      '9608' => "\x8D",
+                      '9612' => "\x8E",
+                      '9616' => "\x8F",
+                      '9617' => "\x90",
+                      '9618' => "\x91",
+                      '9619' => "\x92",
+                      '9632' => "\x94");
+
+    if (array_key_exists($var,$koi8uchars)) {
+        $ret=$koi8uchars[$var];
+    } else {
+        $ret='?';
+    }
+    return $ret;
+}
+?>
\ No newline at end of file