Masato
authorphilippe_mingo <philippe_mingo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 22 Aug 2002 09:33:09 +0000 (09:33 +0000)
committerphilippe_mingo <philippe_mingo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 22 Aug 2002 09:33:09 +0000 (09:33 +0000)
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
functions/imap_search.php
functions/mailbox_display.php
functions/mime.php
functions/smtp.php
plugins/administrator/defines.php
src/compose.php
src/download.php
src/printer_friendly_bottom.php
src/read_body.php

index 47b3fdc0407208a058167dc349c7f24db128b3d8..29530c1b0e035247b0f1ae4cfc9ea3737e454806 100644 (file)
@@ -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;
index fb9e95b53b1115e462ca796696863ad59e247431..463d69089485857e47a8c0f2d2b4690d017247d0 100644 (file)
@@ -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 . ' ';
         }
index 29368b89630af63d6d2aebb37d6280604f10be0d..38d459c2928e2531a6acb9cd908e83e9287d2329 100644 (file)
@@ -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) . '...';
 }
 
index ea36c5a077a17a7071f0dc39e881ada150c30b3a..b307e56025316998fd45f149ef768551adab4568 100644 (file)
@@ -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\8e´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 <christian@ostenfeld.dk>  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  );
index 5c9f7f0ef875b687e48fe6e8f75c2a5e9468b036..5155e67bfc90e794e791392cf8bfc3efde4a9aa9 100644 (file)
@@ -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);
index c747fb0ff4cd95e64009406fba0384a2c678c56a..e86d7079ef9e42e8ec43aa7336ca9318cc7316bd 100644 (file)
@@ -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 ),
index f09a75172aef6e14e81d602e362e41b3539030e5..fbb238801c777ccf70752128a1b5ed373bcf9d8d 100644 (file)
@@ -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);
     }
index 34ed8fd0d733c706a538e5db768b6393ff49a717..60f388bb4d1b070edbdc638233780b1c795fa038 100644 (file)
@@ -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) {
index eb839ecde23fde397e61f3402e85281b55472f6e..88fdaf90fce5e0dc1255b75a6dfed1b3f2644db5 100644 (file)
@@ -91,24 +91,24 @@ echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"
      html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0"' ) .
      html_tag( 'tr',
          html_tag( 'td', _("From").'&nbsp;', 'left' ,'','valign="top"') .
-         html_tag( 'td', htmlentities($from), 'left' )
+         html_tag( 'td', htmlspecialchars($from), 'left' )
      ) . "\n" .
      html_tag( 'tr',
          html_tag( 'td', _("Subject").'&nbsp;', 'left','','valign="top"' ) .
-         html_tag( 'td', htmlentities($subject), 'left' )
+         html_tag( 'td', htmlspecialchars($subject), 'left' )
      ) . "\n" .
      html_tag( 'tr',
          html_tag( 'td', _("Date").'&nbsp;', 'left' ) .
-         html_tag( 'td', htmlentities($date), 'left' )
+         html_tag( 'td', htmlspecialchars($date), 'left' )
      ) . "\n" .
      html_tag( 'tr',
          html_tag( 'td', _("To").'&nbsp;', 'left','','valign="top"' ) .
-         html_tag( 'td', htmlentities($to), 'left' )
+         html_tag( 'td', htmlspecialchars($to), 'left' )
      ) . "\n";
     if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */
          echo html_tag( 'tr',
              html_tag( 'td', _("CC").'&nbsp;', 'left','','valign="top"' ) .
-             html_tag( 'td', htmlentities($cc), 'left' )
+             html_tag( 'td', htmlspecialchars($cc), 'left' )
          );
      }
      /* body */
index 5e1ae71c09f048281c6589277995336251743a74..273d6a3686c16fd13f36b56d565d594b8240c2cd 100644 (file)
@@ -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) {