/[suikacvs]/messaging/newsportal/newsportal.php
Suika

Diff of /messaging/newsportal/newsportal.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by wakaba, Sat Dec 1 13:02:01 2001 UTC revision 1.26 by wakaba, Sun Dec 2 00:08:29 2001 UTC
# Line 448  function headerDecode($value) { Line 448  function headerDecode($value) {
448        $newvalue=headerDecode($newvalue);  // maybe there are more encoded        $newvalue=headerDecode($newvalue);  // maybe there are more encoded
449      return(mb_convert_encoding($newvalue, "EUC-JP", "auto"));      // parts      return(mb_convert_encoding($newvalue, "EUC-JP", "auto"));      // parts
450    } else {    } else {
451      if (eregi('".*"',$value)) {  // quoted-pair      return(mb_convert_encoding(decode_structured_body($value), "EUC-JP", "auto"));
       $newvalue=ereg_replace('(.*)"(.*)"(.*)',"\\1".decode_quoted_pair("\\2")."\\3",$value);  
       return(mb_convert_encoding($newvalue, "EUC-JP", "auto"));  
     } else {   // there wasn't anything encoded, return the original string  
       return(mb_convert_encoding($value, "EUC-JP", "auto"));  
     }  
452    }    }
453  }  }
454    
 function decode_quoted_pair($value) {  
       return(ereg_replace('\\\\(.)',"\\1",$value));  
 }  
   
455  function getTimestamp($value) {  function getTimestamp($value) {
456    $months=array("Jan"=>1,"Feb"=>2,"Mar"=>3,"Apr"=>4,"May"=>5,"Jun"=>6,"Jul"=>7,"Aug"=>8,"Sep"=>9,"Oct"=>10,"Nov"=>11,"Dec"=>12);    $months=array("Jan"=>1,"Feb"=>2,"Mar"=>3,"Apr"=>4,"May"=>5,"Jun"=>6,"Jul"=>7,"Aug"=>8,"Sep"=>9,"Oct"=>10,"Nov"=>11,"Dec"=>12);
457    $value=str_replace("  "," ",$value);    $value=str_replace("  "," ",$value);
# Line 506  function parse_header($hdr,$number="") { Line 497  function parse_header($hdr,$number="") {
497            $header->id=$value;            $header->id=$value;
498            break;            break;
499          case "subject:":          case "subject:":
500            $header->subject=headerDecode($value);            $header->subject = decode_unstructured_body($value);
501            break;            break;
502          case "newsgroups:":          case "newsgroups:":
503            $header->newsgroups=$value;            $header->newsgroups=$value;
# Line 559  function parse_header($hdr,$number="") { Line 550  function parse_header($hdr,$number="") {
550          case "x-newsreader:":          case "x-newsreader:":
551          case "x-mailer:":          case "x-mailer:":
552          case "user-agent:":          case "user-agent:":
553            $header->user_agent=trim(headerDecode($value));            $header->user_agent=trim(decode_structured_body($value));
554            break;            break;
555          case "x-face:":          case "x-face:":
556  //          echo "<p>-".base64_decode($value)."-</p>";  //          echo "<p>-".base64_decode($value)."-</p>";
# Line 574  function parse_header($hdr,$number="") { Line 565  function parse_header($hdr,$number="") {
565    return $header;    return $header;
566  }  }
567    
568    function decode_unstructured_body ($body) {
569      $patterns = array (
570          "/(=\\?[^\\x00-\\x20()<>@,;:\\\\\"/\\[\\]?.=\\x7F]+\\?[BQ]\\?[^\\x00-\\x20\\x3F\\x7F]*\\?=)/ei",
571      );
572      $replace = array (
573          "mb_decode_mimeheader('\\1')",
574      );
575      return preg_replace ($patterns, $replace, $body);
576    }
577    
578    function decode_structured_body ($body) {
579      $patterns = array (
580          "/\"((?:[^\"\\\\]+|\\\\.)*)\"/e",
581          "/\(((?:[^()\\\\]+|\\\\.|(?:\((?:[^()\\\\]+|\\\\.|(?:\((?:[^)\\\\]+|\\\\.\
582    )*\)))*\)))*)\)/e",
583      );
584      $replace = array (
585          "mb_convert_encoding(decode_quoted_pair('\\1'), 'EUC-JP', 'auto')",
586          "'('.mb_convert_encoding(decode_quoted_pair('\\1'), 'EUC-JP', 'auto').')'",
587      );
588      return preg_replace ($patterns, $replace, $body);
589    }
590    
591    function decode_quoted_pair($value) {
592      $value = ereg_replace('\\\\(\\\\")', "\\1", $value);
593      return ereg_replace('\\\\(.)', "\\1", $value);
594    }
595    
596  function decode_body($body,$encoding) {  function decode_body($body,$encoding) {
597    $bodyzeile="";    $bodyzeile="";
598    switch ($encoding) {    switch ($encoding) {
# Line 691  function parse_message($rawmessage) { Line 710  function parse_message($rawmessage) {
710  //      if ($body=="") $body=" ";  //      if ($body=="") $body=" ";
711  //    }  //    }
712      $body=decode_body($body,$message->header->content_transfer_encoding);      $body=decode_body($body,$message->header->content_transfer_encoding);
713      $message->body[0]=$body;      $message->body[0] = mb_convert_encoding($body, "EUC-JP", "auto");
714    }    }
715      if (!isset($message->header->content_type_charset))      if (!isset($message->header->content_type_charset))
716        $message->header->content_type_charset=array("ISO-8859-1");        $message->header->content_type_charset=array("ISO-8859-1");

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.26

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24