From 83be314a29726be91884b222e4c136f9abade9de Mon Sep 17 00:00:00 2001 From: philippe_mingo Date: Thu, 22 Aug 2002 09:33:09 +0000 Subject: [PATCH] Masato Japanes patch git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3404 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_parse.php | 7 ++++ functions/imap_search.php | 6 ++++ functions/mailbox_display.php | 5 +++ functions/mime.php | 19 +++++++++-- functions/smtp.php | 54 ++++++++++++++++++++++++------- plugins/administrator/defines.php | 3 +- src/compose.php | 12 +++++-- src/download.php | 11 ++++++- src/printer_friendly_bottom.php | 10 +++--- src/read_body.php | 8 +++-- 10 files changed, 109 insertions(+), 26 deletions(-) diff --git a/functions/imap_parse.php b/functions/imap_parse.php index 47b3fdc0..29530c1b 100644 --- a/functions/imap_parse.php +++ b/functions/imap_parse.php @@ -221,6 +221,13 @@ function sqimap_parse_RFC822Header ($read, $hdr) { } $i++; break; + case 'u': + /* User-Agent */ + if (strtolower(substr($line,0,10)) == 'user-agent') { + $hdr->xmailer = trim(substr($line, 10)); + } + $i++; + break; default: $i++; break; diff --git a/functions/imap_search.php b/functions/imap_search.php index fb9e95b5..463d6908 100644 --- a/functions/imap_search.php +++ b/functions/imap_search.php @@ -45,11 +45,17 @@ function sqimap_search($imapConnection, $search_where, $search_what, $mailbox, if ($imap_server_type == 'macosx') { foreach ($multi_search as $multi_search_part) { + if (strtoupper($languages[$squirrelmail_language]['CHARSET']) == 'ISO-2022-JP') { + $multi_search_part = mb_convert_encoding($multi_search_part, 'JIS', 'auto'); + } $search_string .= $search_where . ' ' .$multi_search_part . ' '; } } else { foreach ($multi_search as $multi_search_part) { + if (strtoupper($languages[$squirrelmail_language]['CHARSET']) == 'ISO-2022-JP') { + $multi_search_part = mb_convert_encoding($multi_search_part, 'JIS', 'auto'); + } $search_string .= $search_where . ' {' . strlen($multi_search_part) . "}\r\n" . $multi_search_part . ' '; } diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 29368b89..38d459c2 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -1171,6 +1171,7 @@ function get_paginator_str($box, $start_msg, $end_msg, $num_msgs, } function processSubject($subject) { + global $squirrelmail_language; /* Shouldn't ever happen -- caught too many times in the IMAP functions */ if ($subject == '') return _("(no subject)"); @@ -1198,6 +1199,10 @@ function processSubject($subject) { return $subject; } + if ($squirrelmail_language == 'ja_JP' && function_exists('mb_strimwidth')) { + return mb_strimwidth($subject, 0, $trim_val, '...'); + } + return substr($subject, 0, $trim_val) . '...'; } diff --git a/functions/mime.php b/functions/mime.php index ea36c5a0..b307e560 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -154,7 +154,7 @@ function mime_print_body_lines ($imap_stream, $id, $ent_id, $encoding) { // Don't kill the connection if the browser is over a dialup // and it would take over 30 seconds to download it. - // don´t call set_time_limit in safe mode. + // donŽ´t call set_time_limit in safe mode. if (!ini_get("safe_mode")) { set_time_limit(0); } @@ -348,6 +348,7 @@ function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $ma // If there are other types that shouldn't be formatted, add // them here if ($body_message->header->type1 == 'html') { + $body = charset_decode_japanese($body); if ( $show_html_default <> 1 ) { $body = strip_tags( $body ); translateText($body, $wrap_at, @@ -490,6 +491,7 @@ function formatAttachments($message, $exclude_id, $mailbox, $id) { /** this function decodes the body depending on the encoding type. **/ function decodeBody($body, $encoding) { + $body = str_replace("\r\n", "\n", $body); $encoding = strtolower($encoding); @@ -516,9 +518,18 @@ function decodeBody($body, $encoding) { * Patched by Christian Schmidt 23/03/2002 */ function decodeHeader ($string, $utfencode=true) { + global $squirrelmail_language; if (is_array($string)) { $string = implode("\n", $string); } + + if ($squirrelmail_language == 'ja_JP' && function_exists('mb_convert_encoding')) { + $string = str_replace("\t", "", $string); + if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $string)) + $string = mb_decode_mimeheader($string); + return @mb_convert_encoding($string, 'EUC-JP', 'AUTO'); + } + $i = 0; while (preg_match('/^(.{' . $i . '})(.*)=\?([^?]*)\?(Q|B)\?([^?]*)\?=/Ui', $string, $res)) { @@ -552,7 +563,11 @@ function decodeHeader ($string, $utfencode=true) { * be encoded. */ function encodeHeader ($string) { - global $default_charset; + global $default_charset, $squirrelmail_language; + + if ($squirrelmail_language == 'ja_JP' && function_exists('mb_encode_mimeheader')) { + return mb_encode_mimeheader($string); + } // Encode only if the string contains 8-bit characters or =? $j = strlen( $string ); diff --git a/functions/smtp.php b/functions/smtp.php index 5c9f7f0e..5155e67b 100644 --- a/functions/smtp.php +++ b/functions/smtp.php @@ -130,9 +130,9 @@ function attachFiles ($fp, $session, $rn="\r\n") { if ( isset($info['remotefilename']) && $info['remotefilename'] != '') { $header .= "Content-Type: $filetype; name=\"" . - $info['remotefilename'] . "\"$rn"; + encodeHeader(charset_encode_japanese($info['remotefilename'])) . "\"$rn"; $header .= "Content-Disposition: attachment; filename=\"" - . $info['remotefilename'] . "\"$rn"; + . encodeHeader(charset_encode_japanese($info['remotefilename'])) . "\"$rn"; } else { $header .= "Content-Type: $filetype$rn"; } @@ -248,7 +248,7 @@ function timezone () { } /* Print all the needed RFC822 headers */ -function write822Header ($fp, $t, $c, $b, $subject, $more_headers, $session, $rn="\r\n") { +function write822Header ($fp, $t, $c, $b, $subject, $body, $more_headers, $session, $rn="\r\n") { global $REMOTE_ADDR, $SERVER_NAME, $REMOTE_PORT; global $data_dir, $username, $popuser, $domain, $version, $useSendmail; global $default_charset, $HTTP_VIA, $HTTP_X_FORWARDED_FOR; @@ -376,9 +376,19 @@ function write822Header ($fp, $t, $c, $b, $subject, $more_headers, $session, $rn $header .= mimeBoundary(); $header .= "\"$rn"; } else { + if (strtolower($default_charset) == 'iso-2022-jp') { + if (mb_detect_encoding($body) == 'ASCII') { + $header .= 'Content-Type: text/plain; US-ASCII' . $rn; + $header .= "Content-Transfer-Encoding: 8bit" . $rn; + } else { + $header .= 'Content-Type: '.$contentType . $rn; + $header .= "Content-Transfer-Encoding: 7bit" . $rn; + } + } else { $header .= 'Content-Type: ' . $contentType . $rn; $header .= "Content-Transfer-Encoding: 8bit" . $rn; } + } $header .= $rn; // One blank line to separate header and body $headerlength = strlen($header); @@ -413,9 +423,21 @@ function writeBody ($fp, $passedBody, $session, $rn="\r\n") { $body .= "Content-Type: text/plain" . $rn; } - $body .= "Content-Transfer-Encoding: 8bit" . $rn . $rn; - $body .= $passedBody . $rn . $rn; - if ($fp) fputs ($fp, $body); + if (strtolower($default_charset) == 'iso-2022-jp') { + if (mb_detect_encoding($passedBody) == 'ASCII') { + $body .= "Content-Transfer-Encoding: 8bit" . $rn . $rn . + $passedBody . $rn . $rn; + } else { + $body .= "Content-Transfer-Encoding: 7bit\r\n\r\n" . + mb_convert_encoding($passedBody, 'JIS') . "\r\n\r\n"; + } + } else { + $body .= "Content-Transfer-Encoding: 8bit" . $rn . $rn . + $passedBody . $rn . $rn; + } + if ($fp) { + fputs ($fp, $body); + } $attachmentlength = attachFiles($fp, $session, $rn); @@ -425,10 +447,18 @@ function writeBody ($fp, $passedBody, $session, $rn="\r\n") { $postbody .= $rn . "--" . mimeBoundary() . "--" . $rn . $rn; if ($fp) fputs ($fp, $postbody); } else { - $body = $passedBody . $rn; - if ($fp) fputs ($fp, $body); + if (strtolower($default_charset) == 'iso-2022-jp') { + $body = mb_convert_encoding($passedBody, 'JIS') . $rn; + } else { + $body = $passedBody . $rn; + } + if ($fp) { + fputs ($fp, $body); + } $postbody = $rn; - if ($fp) fputs ($fp, $postbody); + if ($fp) { + fputs ($fp, $postbody); + } } return (strlen($body) + strlen($postbody) + $attachmentlength); @@ -458,7 +488,7 @@ function sendSendmail($t, $c, $b, $subject, $body, $more_headers, $session) { $fp = popen (escapeshellcmd("$sendmail_path -t -f$envelopefrom"), "w"); } - $headerlength = write822Header ($fp, $t, $c, $b, $subject, + $headerlength = write822Header ($fp, $t, $c, $b, $subject, $body, $more_headers, $session, "\n"); $bodylength = writeBody($fp, $body, $session, "\n"); @@ -616,7 +646,7 @@ function sendSMTP($t, $c, $b, $subject, $body, $more_headers, $session) { /* Send the message */ $headerlength = write822Header ($smtpConnection, $t, $c, $b, - $subject, $more_headers, $session); + $subject, $body, $more_headers, $session); $bodylength = writeBody($smtpConnection, $body, $session); fputs($smtpConnection, ".\r\n"); /* end the DATA part */ @@ -879,7 +909,7 @@ function sendMessage($t, $c, $b, $subject, $body, $reply_id, $MDN, $length = $headerlength + $bodylength; sqimap_append ($imap_stream, $sent_folder, $length); - write822Header ($imap_stream, $t, $c, $b, $subject, $more_headers, + write822Header ($imap_stream, $t, $c, $b, $subject, $body, $more_headers, $session); writeBody ($imap_stream, $body, $session); sqimap_append_done ($imap_stream); diff --git a/plugins/administrator/defines.php b/plugins/administrator/defines.php index c747fb0f..e86d7079 100644 --- a/plugins/administrator/defines.php +++ b/plugins/administrator/defines.php @@ -185,7 +185,8 @@ $defcfg = array( '$config_version' => array( 'name' => _("Config File Version"), 'ns_4551_1' => 'ns_4551_1', 'koi8-r' => 'koi8-r', 'euc-KR' => 'euc-KR', - 'windows-1251' => 'windows-1251' ) ), + 'windows-1251' => 'windows-1251' + 'ISO-2022-JP' => 'ISO-2022-JP' ) ), '$data_dir' => array( 'name' => _("Data Directory"), 'type' => SMOPT_TYPE_STRING, 'size' => 40 ), diff --git a/src/compose.php b/src/compose.php index f09a7517..fbb23880 100644 --- a/src/compose.php +++ b/src/compose.php @@ -549,7 +549,7 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se (substr(strtolower($subject), 0, 6) != '[ fwd:')) { $subject = '[Fwd: ' . $subject . ']'; } - $body = getforwardHeader($orig_header) . $body; + $body = getforwardHeader($orig_header) . charset_decode_japanese($body); sqUnWordWrap($body); getAttachments($message, $session, $passed_id, $entities, $imapConnection); break; @@ -573,7 +573,7 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se $subject = 'Re: ' . $subject; } /* this corrects some wrapping/quoting problems on replies */ - $rewrap_body = explode("\n", $body); + $rewrap_body = explode("\n", charset_decode_japanese($body)); $body = getReplyCitation($orig_header->from->personal); $cnt = count($rewrap_body); for ($i=0;$i<$cnt;$i++) { @@ -838,14 +838,22 @@ function showInputForm ($session, $values=false) { } if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) { if ($sig_first == '1') { + if ($charset == 'iso-2022-jp') { + echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP'); + } else { echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature); + } echo "\n\n".htmlspecialchars($body); } else { echo "\n\n".htmlspecialchars($body); + if ($charset == 'iso-2022-jp') { + echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP'); + }else{ echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature); } } + } else { echo htmlspecialchars($body); } diff --git a/src/download.php b/src/download.php index 34ed8fd0..60f388bb 100644 --- a/src/download.php +++ b/src/download.php @@ -151,7 +151,7 @@ mime_print_body_lines ($imapConnection, $passed_id, $ent_id, $encoding); * version of IE. I don't know if it works with Opera, but it should now. */ function DumpHeaders($type0, $type1, $filename, $force) { - global $HTTP_USER_AGENT; + global $HTTP_USER_AGENT, $squirrelmail_language; $isIE = 0; if (strstr($HTTP_USER_AGENT, 'compatible; MSIE ') !== false && @@ -164,7 +164,16 @@ function DumpHeaders($type0, $type1, $filename, $force) { $isIE6 = 1; } + if ($squirrelmail_language == 'ja_JP') { + if (strstr($HTTP_USER_AGENT, 'Windows') !== false || + strstr($HTTP_USER_AGENT, 'Mac_') !== false) { + $filename = mb_convert_encoding($filename, 'SJIS', 'AUTO'); + } else { + $filename = mb_convert_encoding($filename, 'EUC-JP', 'AUTO'); + } + } else { $filename = ereg_replace('[^-a-zA-Z0-9\.]', '_', $filename); + } // A Pox on Microsoft and it's Office! if (! $force) { diff --git a/src/printer_friendly_bottom.php b/src/printer_friendly_bottom.php index eb839ecd..88fdaf90 100644 --- a/src/printer_friendly_bottom.php +++ b/src/printer_friendly_bottom.php @@ -91,24 +91,24 @@ echo " 0 ) { /* only show CC: if it's there... */ echo html_tag( 'tr', html_tag( 'td', _("CC").' ', 'left','','valign="top"' ) . - html_tag( 'td', htmlentities($cc), 'left' ) + html_tag( 'td', htmlspecialchars($cc), 'left' ) ); } /* body */ diff --git a/src/read_body.php b/src/read_body.php index 5e1ae71c..273d6a36 100644 --- a/src/read_body.php +++ b/src/read_body.php @@ -186,6 +186,8 @@ function SendMDN ( $mailbox, $passed_id, $sender, $message) { "\r\n" . sprintf( _("Was displayed on %s"), $now ); + $body = charset_encode_japanese($body); + // part2 (RFC2298) $original_recipient = $to; $original_message_id = $header->message_id; @@ -310,7 +312,7 @@ function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $header = $message->rfc822_header; $env = array(); - $env[_("Subject")] = htmlspecialchars($header->subject); + $env[_("Subject")] = htmlspecialchars(decodeHeader($header->subject)); $from_name = $header->getAddr_s('from'); if (!$from_name) { $from_name = $header->getAddr_s('sender'); @@ -318,7 +320,7 @@ function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $from_name = _("Unknown sender"); } } - $env[_("From")] = htmlspecialchars($from_name); + $env[_("From")] = htmlspecialchars(decodeHeader($from_name)); $env[_("Date")] = getLongDateString($header->date); $env[_("To")] = formatRecipientString($header->to, "to"); $env[_("Cc")] = formatRecipientString($header->cc, "cc"); @@ -327,7 +329,7 @@ function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $env[_("Priority")] = getPriorityStr($header->priority); } if ($show_xmailer_default) { - $env[_("Mailer")] = $header->xmailer; + $env[_("Mailer")] = decodeHeader($header->xmailer); } if ($default_use_mdn) { if ($mdn_user_support) { -- 2.25.1