From 17ce84673639e19c0d01cd6b59caea1732b1433f Mon Sep 17 00:00:00 2001 From: gustavf Date: Wed, 22 Mar 2000 13:59:07 +0000 Subject: [PATCH] Added limited support for Cyrillic (only KOI8-R yet) and made it possible to select default charset. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@318 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- config/config_default.php | 81 ++++++++++---------- functions/i18n.php | 150 ++++++++++++++++++++++++++++++++++++++ functions/mime.php | 6 +- functions/page_header.php | 3 +- functions/smtp.php | 15 +++- functions/strings.php | 9 ++- 6 files changed, 220 insertions(+), 44 deletions(-) diff --git a/config/config_default.php b/config/config_default.php index f3bd10fa..5d9deed5 100644 --- a/config/config_default.php +++ b/config/config_default.php @@ -31,43 +31,6 @@ // This is displayed right after they log in $motd = "You are using SquirrelMail's web-based email client. If you run into any bugs or have suggestions, please report them to our mailing list"; -// Themes -// You can define your own theme and put it in this directory. You must -// call it as the example below. You can name the theme whatever you -// want. For an example of a theme, see the ones included in the config -// directory. -// -// You can download themes from http://squirrelmail.sourceforge.net/index.php3?page=10 -// -// To add a new theme to the options that users can choose from, just add -// a new number to the array at the bottom, and follow the pattern. - - // The first one HAS to be here, and is your system's default theme. - // It can be any theme you want - $theme[0]["PATH"] = "../config/default_theme.php"; - $theme[0]["NAME"] = "Default"; - - $theme[1]["PATH"] = "../config/sandstorm_theme.php"; - $theme[1]["NAME"] = "Sand Storm"; - - $theme[2]["PATH"] = "../config/deepocean_theme.php"; - $theme[2]["NAME"] = "Deep Ocean"; - - $theme[3]["PATH"] = "../config/slashdot_theme.php"; - $theme[3]["NAME"] = "Slashdot"; - - $theme[4]["PATH"] = "../config/purple_theme.php"; - $theme[4]["NAME"] = "Purple"; - - $theme[5]["PATH"] = "../config/forest_theme.php"; - $theme[5]["NAME"] = "Forest"; - - $theme[6]["PATH"] = "../config/ice_theme.php"; - $theme[6]["NAME"] = "Ice"; - - $theme[7]["PATH"] = "../config/seaspray_theme.php"; - $theme[7]["NAME"] = "Sea Spray"; - // Whether or not to use a special color for special folders. If not, special // folders will be the same color as the other folders $use_special_folder_color = true; @@ -125,6 +88,12 @@ $show_contain_subfolders_option = false; +// This option controls what character set is used when sending mail +// and when sending HTMl to the browser. Do not set this to US-ASCII, +// use ISO-8859-1 instead. For cyrillic it is best to use KOI8-R, +// since this implementation is faster than the alternatives. + $default_charset = "iso-8859-1"; + // Whether or not to use META tags and automatically forward after an // action has been completed. $auto_forward = true; @@ -163,4 +132,42 @@ // but you can set it to whatever you wish. $default_left_size = 200; + +// Themes +// You can define your own theme and put it in this directory. You must +// call it as the example below. You can name the theme whatever you +// want. For an example of a theme, see the ones included in the config +// directory. +// +// You can download themes from http://squirrelmail.sourceforge.net/index.php3?page=10 +// +// To add a new theme to the options that users can choose from, just add +// a new number to the array at the bottom, and follow the pattern. + + // The first one HAS to be here, and is your system's default theme. + // It can be any theme you want + $theme[0]["PATH"] = "../config/default_theme.php"; + $theme[0]["NAME"] = "Default"; + + $theme[1]["PATH"] = "../config/sandstorm_theme.php"; + $theme[1]["NAME"] = "Sand Storm"; + + $theme[2]["PATH"] = "../config/deepocean_theme.php"; + $theme[2]["NAME"] = "Deep Ocean"; + + $theme[3]["PATH"] = "../config/slashdot_theme.php"; + $theme[3]["NAME"] = "Slashdot"; + + $theme[4]["PATH"] = "../config/purple_theme.php"; + $theme[4]["NAME"] = "Purple"; + + $theme[5]["PATH"] = "../config/forest_theme.php"; + $theme[5]["NAME"] = "Forest"; + + $theme[6]["PATH"] = "../config/ice_theme.php"; + $theme[6]["NAME"] = "Ice"; + + $theme[7]["PATH"] = "../config/seaspray_theme.php"; + $theme[7]["NAME"] = "Sea Spray"; + ?> diff --git a/functions/i18n.php b/functions/i18n.php index 6d8b555b..a7640d42 100644 --- a/functions/i18n.php +++ b/functions/i18n.php @@ -39,6 +39,8 @@ return charset_decode_iso_8859_default ($string); } else if ($charset == "ns_4551-1") { return charset_decode_ns_4551_1 ($string); + } else if ($charset == "koi8-r") { + return charset_decode_koi8r ($string); } else return $string; } @@ -126,6 +128,11 @@ return ($string); } + // ISO-8859-15 is Cyrillic + function charset_decode_iso_8859_5 ($string) { + // Not yet implemented. + } + // Remove all 8 bit characters from all other ISO-8859 character sets function charset_decode_iso_8859_default ($string) { return (strtr($string, "\240\241\242\243\244\245\246\247". @@ -158,4 +165,147 @@ return strtr ($string, "[\\]{|}", "ÆØÅæøå"); } + // KOI8-R is used to encode Russian mail (Cyrrilic). Defined in RFC + // 1489. + function charset_decode_koi8r ($string) { + global $default_charset; + + if ($default_charset == "koi8-r") { + return $string; + } else { + // Convert to Unicode HTML entities. + // This code is rather ineffective. + $string = ereg_replace("\200", "─", $string); + $string = ereg_replace("\201", "│", $string); + $string = ereg_replace("\202", "┌", $string); + $string = ereg_replace("\203", "┐", $string); + $string = ereg_replace("\204", "└", $string); + $string = ereg_replace("\205", "┘", $string); + $string = ereg_replace("\206", "├", $string); + $string = ereg_replace("\207", "┤", $string); + $string = ereg_replace("\210", "┬", $string); + $string = ereg_replace("\211", "┴", $string); + $string = ereg_replace("\212", "┼", $string); + $string = ereg_replace("\213", "▀", $string); + $string = ereg_replace("\214", "▄", $string); + $string = ereg_replace("\215", "█", $string); + $string = ereg_replace("\216", "▌", $string); + $string = ereg_replace("\217", "▐", $string); + $string = ereg_replace("\220", "░", $string); + $string = ereg_replace("\221", "▒", $string); + $string = ereg_replace("\222", "▓", $string); + $string = ereg_replace("\223", "⌠", $string); + $string = ereg_replace("\224", "■", $string); + $string = ereg_replace("\225", "∙", $string); + $string = ereg_replace("\226", "√", $string); + $string = ereg_replace("\227", "≈", $string); + $string = ereg_replace("\230", "≤", $string); + $string = ereg_replace("\231", "≥", $string); + $string = ereg_replace("\232", " ", $string); + $string = ereg_replace("\233", "⌡", $string); + $string = ereg_replace("\234", "°", $string); + $string = ereg_replace("\235", "²", $string); + $string = ereg_replace("\236", "·", $string); + $string = ereg_replace("\237", "÷", $string); + $string = ereg_replace("\240", "═", $string); + $string = ereg_replace("\241", "║", $string); + $string = ereg_replace("\242", "╒", $string); + $string = ereg_replace("\243", "ё", $string); + $string = ereg_replace("\244", "╓", $string); + $string = ereg_replace("\245", "╔", $string); + $string = ereg_replace("\246", "╕", $string); + $string = ereg_replace("\247", "╖", $string); + $string = ereg_replace("\250", "╗", $string); + $string = ereg_replace("\251", "╘", $string); + $string = ereg_replace("\252", "╙", $string); + $string = ereg_replace("\253", "╚", $string); + $string = ereg_replace("\254", "╛", $string); + $string = ereg_replace("\255", "╜", $string); + $string = ereg_replace("\256", "╝", $string); + $string = ereg_replace("\257", "╞", $string); + $string = ereg_replace("\260", "╟", $string); + $string = ereg_replace("\261", "╠", $string); + $string = ereg_replace("\262", "╡", $string); + $string = ereg_replace("\263", "Ё", $string); + $string = ereg_replace("\264", "╢", $string); + $string = ereg_replace("\265", "╣", $string); + $string = ereg_replace("\266", "╤", $string); + $string = ereg_replace("\267", "╥", $string); + $string = ereg_replace("\270", "╦", $string); + $string = ereg_replace("\271", "╧", $string); + $string = ereg_replace("\272", "╨", $string); + $string = ereg_replace("\273", "╩", $string); + $string = ereg_replace("\274", "╪", $string); + $string = ereg_replace("\275", "╫", $string); + $string = ereg_replace("\276", "╬", $string); + $string = ereg_replace("\277", "©", $string); + $string = ereg_replace("\300", "ю", $string); + $string = ereg_replace("\301", "а", $string); + $string = ereg_replace("\302", "б", $string); + $string = ereg_replace("\303", "ц", $string); + $string = ereg_replace("\304", "д", $string); + $string = ereg_replace("\305", "е", $string); + $string = ereg_replace("\306", "ф", $string); + $string = ereg_replace("\307", "г", $string); + $string = ereg_replace("\310", "х", $string); + $string = ereg_replace("\311", "и", $string); + $string = ereg_replace("\312", "й", $string); + $string = ereg_replace("\313", "к", $string); + $string = ereg_replace("\314", "л", $string); + $string = ereg_replace("\315", "м", $string); + $string = ereg_replace("\316", "н", $string); + $string = ereg_replace("\317", "о", $string); + $string = ereg_replace("\320", "п", $string); + $string = ereg_replace("\321", "я", $string); + $string = ereg_replace("\322", "р", $string); + $string = ereg_replace("\323", "с", $string); + $string = ereg_replace("\324", "т", $string); + $string = ereg_replace("\325", "у", $string); + $string = ereg_replace("\326", "ж", $string); + $string = ereg_replace("\327", "в", $string); + $string = ereg_replace("\330", "ь", $string); + $string = ereg_replace("\331", "ы", $string); + $string = ereg_replace("\332", "з", $string); + $string = ereg_replace("\333", "ш", $string); + $string = ereg_replace("\334", "э", $string); + $string = ereg_replace("\335", "щ", $string); + $string = ereg_replace("\336", "ч", $string); + $string = ereg_replace("\337", "ъ", $string); + $string = ereg_replace("\340", "Ю", $string); + $string = ereg_replace("\341", "А", $string); + $string = ereg_replace("\342", "Б", $string); + $string = ereg_replace("\343", "Ц", $string); + $string = ereg_replace("\344", "Д", $string); + $string = ereg_replace("\345", "Е", $string); + $string = ereg_replace("\346", "Ф", $string); + $string = ereg_replace("\347", "Г", $string); + $string = ereg_replace("\350", "Х", $string); + $string = ereg_replace("\351", "И", $string); + $string = ereg_replace("\352", "Й", $string); + $string = ereg_replace("\353", "К", $string); + $string = ereg_replace("\354", "Л", $string); + $string = ereg_replace("\355", "М", $string); + $string = ereg_replace("\356", "Н", $string); + $string = ereg_replace("\357", "О", $string); + $string = ereg_replace("\360", "П", $string); + $string = ereg_replace("\361", "Я", $string); + $string = ereg_replace("\362", "Р", $string); + $string = ereg_replace("\363", "С", $string); + $string = ereg_replace("\364", "Т", $string); + $string = ereg_replace("\365", "У", $string); + $string = ereg_replace("\366", "Ж", $string); + $string = ereg_replace("\367", "В", $string); + $string = ereg_replace("\370", "Ь", $string); + $string = ereg_replace("\371", "Ы", $string); + $string = ereg_replace("\372", "З", $string); + $string = ereg_replace("\373", "Ш", $string); + $string = ereg_replace("\374", "Э", $string); + $string = ereg_replace("\375", "Щ", $string); + $string = ereg_replace("\376", "Ч", $string); + $string = ereg_replace("\377", "Ъ", $string); + + return $string; + } + } + ?> diff --git a/functions/mime.php b/functions/mime.php index 8b364a37..cbc7d205 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -138,23 +138,27 @@ if (containsType($message, "text", "html", $ent_num)) { $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]); + $charset = $message["ENTITIES"][$ent_num]["CHARSET"]; } else if (containsType($message, "text", "plain", $ent_num)) { $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]); + $charset = $message["ENTITIES"][$ent_num]["CHARSET"]; } // add other primary displaying message types here else { // find any type that's displayable if (containsType($message, "text", "any_type", $ent_num)) { $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]); + $charset = $message["ENTITIES"][$ent_num]["CHARSET"]; } else if (containsType($message, "message", "any_type", $ent_num)) { $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]); + $charset = $message["ENTITIES"][$ent_num]["CHARSET"]; } } /** If there are other types that shouldn't be formatted, add them here **/ if ($message["ENTITIES"][$ent_num]["TYPE1"] != "html") - $body = translateText($body, $wrap_at); + $body = translateText($body, $wrap_at, $charset); $body .= "
". _("Download this as a file") ."

"; diff --git a/functions/page_header.php b/functions/page_header.php index 030a6070..fb92f887 100644 --- a/functions/page_header.php +++ b/functions/page_header.php @@ -13,7 +13,8 @@ // This is done to ensure that the character set is correct when // receiving input from HTTP forms - header ("Content-Type: text/html; charset=iso-8859-1"); + if ($default_charset != "") + header ("Content-Type: text/html; charset=$default_charset"); // Check to see if gettext is installed if (function_exists("_")) { diff --git a/functions/smtp.php b/functions/smtp.php index 28a2204a..5e39ad40 100644 --- a/functions/smtp.php +++ b/functions/smtp.php @@ -109,6 +109,7 @@ function write822Header ($fp, $t, $c, $b, $subject) { global $REMOTE_ADDR, $SERVER_NAME, $REMOTE_PORT; global $data_dir, $username, $domain, $version, $useSendmail; + global $default_charset; // Storing the header to make sure the header is the same // everytime the header is printed. @@ -176,7 +177,10 @@ $header .= mimeBoundary(); $header .= "\"\r\n"; } else { - $header .= "Content-Type: text/plain; charset=ISO-8859-1\r\n"; + if ($default_charset != "") + $header .= "Content-Type: text/plain; charset=$default_charset\r\n"; + else + $header .= "Content-Type: text/plain;\r\n"; $header .= "Content-Transfer-Encoding: 8bit\r\n"; } $header .= "\r\n"; // One blank line to separate header and body @@ -192,11 +196,18 @@ // Send the body function writeBody ($fp, $passedBody) { + global $default_charset; + $attachmentlength = 0; if (isMultipart()) { $body = "--".mimeBoundary()."\r\n"; - $body .= "Content-Type: text/plain; charset=iso-8859-1\r\n"; + + if ($default_charset != "") + $body .= "Content-Type: text/plain; charset=$default_charset\r\n"; + else + $body .= "Content-Type: text/plain\r\n"; + $body .= "Content-Transfer-Encoding: 8bit\r\n\r\n"; $body .= stripslashes($passedBody) . "\r\n"; fputs ($fp, $body); diff --git a/functions/strings.php b/functions/strings.php index 8d5385b9..c0f23a85 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -91,7 +91,7 @@ return $to_line; } - function translateText($body, $wrap_at) { + function translateText($body, $wrap_at, $charset) { /** Add any parsing you want to in here */ $body = trim($body); $body_ary = explode("\n", $body); @@ -100,12 +100,15 @@ $line = $body_ary[$i]; $line = "^^$line"; - $line = str_replace(">", ">", $line); - $line = str_replace("<", "<", $line); + //$line = str_replace(">", ">", $line); + //$line = str_replace("<", "<", $line); + //$line = htmlspecialchars($line); if (strlen($line) >= $wrap_at) // -2 because of the ^^ at the beginning $line = wordWrap($line, $wrap_at); + $line = charset_decode($charset, $line); + $line = str_replace(" ", " ", $line); $line = str_replace("\t", "        ", $line); $line = nl2br($line); -- 2.25.1