patch-squirrelmail-1.4.0-1.patch by Victor Ustugov diff -urN functions.orig/i18n.php functions/i18n.php --- functions.orig/i18n.php 2003-03-27 00:00:00.000000000 +0200 +++ functions/i18n.php 2003-05-14 00:00:00.000000000 +0300 @@ -56,9 +56,11 @@ } } else if ($charset == 'ns_4551-1') { $ret = charset_decode_ns_4551_1 ($string); - } else if ($charset == 'koi8-r') { +// } else if ($charset == 'koi8-r') { + } else if (($charset == 'koi8-r') or ($charset == 'koi8r') or ($charset == 'koi8') or ($charset == 'cskoi8r')) { $ret = charset_decode_koi8r ($string); - } else if ($charset == 'windows-1251') { +// } else if ($charset == 'windows-1251') { + } else if (($charset == 'windows-1251') or ($charset == 'cp1251')) { $ret = charset_decode_windows_1251 ($string); } else if ($charset == 'windows-1253') { $ret = charset_decode_windows_1253 ($string); @@ -68,6 +70,11 @@ $ret = charset_decode_windows_1257 ($string); } else if ($charset == 'utf-8') { $ret = charset_decode_utf8 ($string); + } else if (($charset == '866') or ($charset == 'cp866') or ($charset == 'cp-866') or + ($charset == 'x-cp866') or ($charset == 'csibm866') or ($charset == 'ibm866')) { + $ret = charset_decode_cp866 ($string); + } else if (($charset == 'x-mac-cyrillic') or ($charset == 'maccyrillic') or ($charset == 'mac-cyrillic')) { + $ret = charset_decode_mac ($string); } else { $ret = $string; } @@ -1102,6 +1109,20 @@ return charset_decode_koi8r($string); } +/* cp-866 is DOS Cyrillic encoding */ +function charset_decode_cp866 ($string) { + // Convert to KOI8-R, then return this decoded. + $string = convert_cyr_string($string, 'a', 'k'); + return charset_decode_koi8r($string); +} + +/* x-mac-cyrillic is Macithosh Cyrillic encoding */ +function charset_decode_mac ($string) { + // Convert to KOI8-R, then return this decoded. + $string = convert_cyr_string($string, 'm', 'k'); + return charset_decode_koi8r($string); +} + /* @@ -1142,6 +1163,7 @@ isset($languages[$sm_notAlias]['CHARSET']) ) { bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' ); textdomain( 'squirrelmail' ); + if (function_exists('bind_textdomain_codeset')) bind_textdomain_codeset('squirrelmail', $languages[$sm_notAlias]['CHARSET']); if ( !ini_get('safe_mode') && getenv( 'LC_ALL' ) != $sm_notAlias ) { putenv( "LC_ALL=$sm_notAlias" ); diff -urN functions.orig/imap_mailbox.php functions/imap_mailbox.php --- functions.orig/imap_mailbox.php 2003-05-13 00:00:00.000000000 +0300 +++ functions/imap_mailbox.php 2003-05-13 00:00:00.000000000 +0300 @@ -302,7 +302,7 @@ $p = 'unformatted'; foreach ($boxesall as $box) { - if (substr($box[$p], 0, $l) == $old_name . $delimiter) { + if ((substr($box[$p], 0, $l) == $old_name . $delimiter) and ($box[$p] != $old_name)) { $new_sub = $new_name . $delimiter . substr($box[$p], $l); if ($imap_server_type == 'cyrus') { $cmd = 'RENAME "' . $box[$p] . '" "' . $new_sub . '"'; diff -urN functions.orig/imap_utf7_local.php functions/imap_utf7_local.php --- functions.orig/imap_utf7_local.php 2003-05-13 00:00:00.000000000 +0300 +++ functions/imap_utf7_local.php 2003-05-13 00:00:00.000000000 +0300 @@ -1,176 +1,17 @@ = 0x20) and ($ord_c <= 0x25)) or - (($ord_c >= 0x27) and ($ord_c <= 0x7e))) { - if ($b64_s) { - $utf7_s = $utf7_s . '&' . encodeBASE64($b64_s) .'-'; - $b64_s = ''; - } - $utf7_s = $utf7_s . $c; - } elseif ($ord_c == 0x26) { - if ($b64_s) { - $utf7_s = $utf7_s . '&' . encodeBASE64($b64_s) . '-'; - $b64_s = ''; - } - $utf7_s = $utf7_s . '&-'; - } else { - $b64_s = $b64_s . chr(0) . $c; - } - } - // - // flush buffer - // - if ($b64_s) { - $utf7_s = $utf7_s . '&' . encodeBASE64($b64_s) . '-'; - $b64_s = ''; - } - return $utf7_s; -} +include_once('lib_utf7imap_decode.inc.php'); function imap_utf7_decode_local($s) { global $languages, $squirrelmail_language; - - if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && - function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { - return $languages[$squirrelmail_language]['XTRA_CODE']('utf7-imap_decode', $s); - } - - $b64_s = ''; - $iso_8859_1_s = ''; - for ($i = 0, $len = strlen($s); $i < $len; $i++) { - $c = $s[$i]; - if (strlen($b64_s) > 0) { - if ($c == '-') { - if ($b64_s == '&') { - $iso_8859_1_s = $iso_8859_1_s . '&'; - } else { - $iso_8859_1_s = $iso_8859_1_s . - decodeBASE64(substr($b64_s, 1)); - } - $b64_s = ''; - } else { - $b64_s = $b64_s . $c; - } - } else { - if ($c == '&') { - $b64_s = '&'; - } else { - $iso_8859_1_s = $iso_8859_1_s . $c; - } - } - } - return $iso_8859_1_s; + return(imap_utf7_decode_loc($s, $languages[$squirrelmail_language]['CHARSET'])); } -function encodeBASE64($s) { - $B64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,'; - $p = 0; // phase: 1 / 2 / 3 / 1 / 2 / 3... - $e = ''; // base64-encoded string - //foreach($s as $c) { - for ($i = 0; $i < strlen($s); $i++) { - $c = $s[$i]; - if ($p == 0) { - $e = $e . substr($B64Chars, ((ord($c) & 252) >> 2), 1); - $t = (ord($c) & 3); - $p = 1; - } elseif ($p == 1) { - $e = $e . $B64Chars[($t << 4) + ((ord($c) & 240) >> 4)]; - $t = (ord($c) & 15); - $p = 2; - } elseif ($p == 2) { - $e = $e . $B64Chars[($t << 2) + ((ord($c) & 192) >> 6)]; - $e = $e . $B64Chars[ord($c) & 63]; - $p = 0; - } - } - // - // flush buffer - // - if ($p == 1) { - $e = $e . $B64Chars[$t << 4]; - } elseif ($p == 2) { - $e = $e . $B64Chars[$t << 2]; - } - return $e; -} +include_once('lib_utf7imap_encode.inc.php'); -function decodeBASE64($s) { - $B64Values = array( - 'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, - 'G' => 6, 'H' => 7, 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, - 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, 'Q' => 16, 'R' => 17, - 'S' => 18, 'T' => 19, 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23, - 'Y' => 24, 'Z' => 25, - 'a' => 26, 'b' => 27, 'c' => 28, 'd' => 29, 'e' => 30, 'f' => 31, - 'g' => 32, 'h' => 33, 'i' => 34, 'j' => 35, 'k' => 36, 'l' => 37, - 'm' => 38, 'n' => 39, 'o' => 40, 'p' => 41, 'q' => 42, 'r' => 43, - 's' => 44, 't' => 45, 'u' => 46, 'v' => 47, 'w' => 48, 'x' => 49, - 'y' => 50, 'z' => 51, - '0' => 52, '1' => 53, '2' => 54, '3' => 55, '4' => 56, '5' => 57, - '6' => 58, '7' => 59, '8' => 60, '9' => 61, '+' => 62, ',' => 63 - ); - $p = 0; - $d = ''; - $unicodeNullByteToggle = 0; - for ($i = 0, $len = strlen($s); $i < $len; $i++) { - $c = $s[$i]; - if ($p == 0) { - $t = $B64Values[$c]; - $p = 1; - } elseif ($p == 1) { - if ($unicodeNullByteToggle) { - $d = $d . chr(($t << 2) + (($B64Values[$c] & 48) >> 4)); - $unicodeNullByteToggle = 0; - } else { - $unicodeNullByteToggle = 1; - } - $t = ($B64Values[$c] & 15); - $p = 2; - } elseif ($p == 2) { - if ($unicodeNullByteToggle) { - $d = $d . chr(($t << 4) + (($B64Values[$c] & 60) >> 2)); - $unicodeNullByteToggle = 0; - } else { - $unicodeNullByteToggle = 1; - } - $t = ($B64Values[$c] & 3); - $p = 3; - } elseif ($p == 3) { - if ($unicodeNullByteToggle) { - $d = $d . chr(($t << 6) + $B64Values[$c]); - $unicodeNullByteToggle = 0; - } else { - $unicodeNullByteToggle = 1; - } - $t = ($B64Values[$c] & 3); - $p = 0; - } - } - return $d; +function imap_utf7_encode_local($s) { + global $languages, $squirrelmail_language; + return(imap_utf7_encode_loc($s, $languages[$squirrelmail_language]['CHARSET'])); } -?> \ No newline at end of file +?> diff -urN functions.orig/lib_utf7imap_decode.inc.php functions/lib_utf7imap_decode.inc.php --- functions.orig/lib_utf7imap_decode.inc.php 1970-01-01 03:00:00.000000000 +0300 +++ functions/lib_utf7imap_decode.inc.php 2003-11-11 00:00:00.000000000 +0200 @@ -0,0 +1,62 @@ + 0) { + if ($c == '-') { + if ($b64_s == '&') { + $iso_8859_1_s = $iso_8859_1_s . '&'; + } else { + $iso_8859_1_s = $iso_8859_1_s . + decodeBASE64($b64_s.'-', $charset); + } + $b64_s = ''; + } else { + $b64_s = $b64_s . $c; + } + } else { + if ($c == '&') { + $b64_s = '&'; + } else { + $iso_8859_1_s = $iso_8859_1_s . $c; + } + } + } + return $iso_8859_1_s; +} + +?> diff -urN functions.orig/lib_utf7imap_encode.inc.php functions/lib_utf7imap_encode.inc.php --- functions.orig/lib_utf7imap_encode.inc.php 1970-01-01 03:00:00.000000000 +0300 +++ functions/lib_utf7imap_encode.inc.php 2003-05-06 00:00:00.000000000 +0300 @@ -0,0 +1,72 @@ += 0x20) and ($ord_c <= 0x25)) or + (($ord_c >= 0x27) and ($ord_c <= 0x7e))) { + if ($b64_s) { + $utf7_s = $utf7_s . encodeBASE64($b64_s, $charset); + $b64_s = ''; + } + $utf7_s = $utf7_s . $c; + } elseif ($ord_c == 0x26) { + if ($b64_s) { + $utf7_s = $utf7_s . encodeBASE64($b64_s, $charset); + $b64_s = ''; + } + $utf7_s = $utf7_s . '&-'; + } else { +// $b64_s = $b64_s . chr(0) . $c; + $b64_s = $b64_s . $c; + } + } + // + // flush buffer + // + if ($b64_s) { + $utf7_s = $utf7_s . encodeBASE64($b64_s, $charset); + $b64_s = ''; + } + return $utf7_s; +} + +?> diff -urN functions.orig/tree.php functions/tree.php --- functions.orig/tree.php 2003-05-13 00:00:00.000000000 +0300 +++ functions/tree.php 2003-05-14 00:00:00.000000000 +0300 @@ -89,32 +89,46 @@ } -function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) { +//function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) { +function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree, $lastIndex = -1) { +//echo("execute walkTreeInPreOrderDeleteFolders, lastindex = '$lastIndex'
\n"); if ($tree[$index]['doIHaveChildren']) { for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) { - walkTreeInPreOrderDeleteFolders($tree[$index]['subNodes'][$j], $imap_stream, $tree); + walkTreeInPreOrderDeleteFolders($tree[$index]['subNodes'][$j], $imap_stream, $tree, $index); } + if (($lastIndex == -1) or ($tree[$lastIndex]['value'] != $tree[$index]['value'])) sqimap_mailbox_delete($imap_stream, $tree[$index]['value']); } else { + if (($lastIndex == -1) or ($tree[$lastIndex]['value'] != $tree[$index]['value'])) sqimap_mailbox_delete($imap_stream, $tree[$index]['value']); } } -function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName) { +//function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName) { +function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName, $lastSubFolderName = '') { global $trash_folder, $delimiter; - $position = strrpos($topFolderName, $delimiter) + 1; +// $position = strrpos($topFolderName, $delimiter) + 1; + $position = strrpos($topFolderName, $delimiter); + if ($position == false) { + $position = 0; + } else { + $position += 1; + } $subFolderName = substr($tree[$index]['value'], $position); if ($tree[$index]['doIHaveChildren']) { + if ($subFolderName != $lastSubFolderName) sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, ""); $mbx_response = sqimap_mailbox_select($imap_stream, $tree[$index]['value']); $messageCount = $mbx_response['EXISTS']; if ($messageCount > 0) sqimap_messages_copy($imap_stream, 1, '*', $trash_folder . $delimiter . $subFolderName); for ($j = 0;$j < count($tree[$index]['subNodes']); $j++) - walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree, $topFolderName); +// walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree, $topFolderName); + walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree, $topFolderName, $subFolderName); } else { + if ($subFolderName != $lastSubFolderName) sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, ''); $mbx_response = sqimap_mailbox_select($imap_stream, $tree[$index]['value']); $messageCount = $mbx_response['EXISTS']; diff -urN src.orig/compose.php src/compose.php --- src.orig/compose.php 2003-03-27 00:00:00.000000000 +0200 +++ src/compose.php 2003-06-01 00:00:00.000000000 +0300 @@ -188,23 +188,29 @@ foreach($display as $key => $val) { $display[$key] = $key .': '. str_pad('', $maxsize - $val); } - $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false); +// $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false); + $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),true,false); $from = str_replace(' ',' ',$from); - $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false); +// $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false); + $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),true,false); $to = str_replace(' ',' ',$to); - $subject = decodeHeader($orig_header->subject,false,false); +// $subject = decodeHeader($orig_header->subject,false,false); + $subject = decodeHeader($orig_header->subject,true,false); $subject = str_replace(' ',' ',$subject); - $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH) . +// $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH) . + $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -12,'-',STR_PAD_BOTH) . "\n". $display[_("Subject")] . $subject . "\n" . $display[_("From")] . $from . "\n" . $display[_("Date")] . getLongDateString( $orig_header->date ). "\n" . $display[_("To")] . $to . "\n"; if ($orig_header->cc != array() && $orig_header->cc !='') { - $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false); +// $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false); + $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),true,false); $cc = str_replace(' ',' ',$cc); $bodyTop .= $display[_("Cc")] .$cc . "\n"; } - $bodyTop .= str_pad('', $editor_size -2 , '-') . +// $bodyTop .= str_pad('', $editor_size -2 , '-') . + $bodyTop .= str_pad('', $editor_size -12 , '-') . "\n\n"; return $bodyTop; } @@ -596,8 +602,9 @@ $type0 = $message->type0; $type1 = $message->type1; foreach ($entities as $ent) { - $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); +// $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); $body_part_entity = $message->getEntity($ent); + $unencoded_bodypart = charset_decode($body_part_entity->header->getParameter('charset'), mime_fetch_body($imapConnection, $passed_id, $ent)); $bodypart = decodeBody($unencoded_bodypart, $body_part_entity->header->encoding); if ($type1 == 'html') { @@ -683,14 +690,15 @@ break; case ('forward'): $send_to = ''; - $subject = decodeHeader($orig_header->subject,false,true); +// $subject = decodeHeader($orig_header->subject,false,true); + $subject = decodeHeader($orig_header->subject,true,true); if ((substr(strtolower($subject), 0, 4) != 'fwd:') && (substr(strtolower($subject), 0, 5) != '[fwd:') && (substr(strtolower($subject), 0, 6) != '[ fwd:')) { $subject = '[Fwd: ' . $subject . ']'; } $body = getforwardHeader($orig_header) . $body; - sqUnWordWrap($body); +// sqUnWordWrap($body); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); $body = "\n" . $body; break; @@ -700,7 +708,8 @@ break; case ('reply_all'): $send_to_cc = replyAllString($orig_header); - $send_to_cc = decodeHeader($send_to_cc,false,true); +// $send_to_cc = decodeHeader($send_to_cc,false,true); + $send_to_cc = htmlspecialchars(decodeHeader($send_to_cc,true,false)); case ('reply'): $send_to = $orig_header->reply_to; if (is_array($send_to) && count($send_to)) { @@ -710,8 +719,10 @@ } else { $send_to = $orig_header->getAddr_s('from'); } - $send_to = decodeHeader($send_to,false,true); - $subject = decodeHeader($orig_header->subject,false,true); +// $send_to = decodeHeader($send_to,false,true); + $send_to = decodeHeader($send_to,true,true); +// $subject = decodeHeader($orig_header->subject,false,true); + $subject = decodeHeader($orig_header->subject,true,true); $subject = str_replace('"', "'", $subject); $subject = trim($subject); if (substr(strtolower($subject), 0, 3) != 're:') { diff -urN src.orig/folders.php src/folders.php --- src.orig/folders.php 2003-05-13 00:00:00.000000000 +0300 +++ src/folders.php 2003-05-13 00:00:00.000000000 +0300 @@ -105,6 +105,7 @@ $skip_folders=0; $server_type = strtolower($imap_server_type); if ( $server_type == 'courier' ) { +//if( ( $server_type == 'courier' ) or ( $server_type == 'dovecot' )) { $show_selected = array('inbox'); $skip_folders = array('inbox.trash'); if ( $default_folder_prefix == 'INBOX.' ) { @@ -137,7 +138,7 @@ /** count special folders **/ $count_special_folders = 0; $num_max = 1; -if (strtolower($imap_server_type) == "courier" || $move_to_trash) { +if (strtolower($imap_server_type) == "courier" || $move_to_trash || $imap_server_type == "dovecot") { $num_max++; } if ($move_to_sent) { @@ -149,7 +150,7 @@ for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++) { if (strtolower($boxes[$p]['unformatted']) == 'inbox') $count_special_folders++; - else if (strtolower($imap_server_type) == 'courier' && + else if (((strtolower($imap_server_type) == 'courier') || (strtolower($imap_server_type) == 'dovecot')) && strtolower($boxes[$p]['unformatted']) == 'inbox.trash') $count_special_folders++; else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder) diff -urN src.orig/folders_rename_getname.php src/folders_rename_getname.php --- src.orig/folders_rename_getname.php 2003-05-13 00:00:00.000000000 +0300 +++ src/folders_rename_getname.php 2003-05-13 00:00:00.000000000 +0300 @@ -66,7 +66,7 @@ html_tag( 'td', '', 'center', $color[4] ) . '
'. _("New name:"). - "
$old_parent $delimiter
\n"; + "
$old_parent ".($old_parent ? $delimiter : '')."
\n"; if ( $isfolder ) { echo ''; } diff -urN src.orig/left_main.php src/left_main.php --- src.orig/left_main.php 2003-03-11 00:00:00.000000000 +0200 +++ src/left_main.php 2003-05-14 00:00:00.000000000 +0300 @@ -37,6 +37,11 @@ $use_special_folder_color; $real_box = $box_array['unformatted']; $mailbox = str_replace(' ','',$box_array['formatted']); + global $imap_server_type; + if ($imap_server_type == 'uw') { +// $mailbox = ereg_replace('^'.$folder_prefix, '', substr($real_box, 0, strrpos($real_box, sqimap_get_delimiter($imapConnection)) + 1)) . $mailbox; + $mailbox = ereg_replace('^'.$folder_prefix, '', imap_utf7_decode_local($real_box)); + } $mailboxURL = urlencode($real_box); /* Strip down the mailbox name. */ @@ -906,6 +911,7 @@ } else { $prefix = str_replace(' ',' ',$prefix); } + if ($imap_server_type == 'uw') $prefix = ''; $line = "$prefix"; /* Add the folder name and link. */