koi8_u.php 5.8 KB

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