/[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.20 by wakaba, Sat Dec 1 13:04:57 2001 UTC revision 1.34 by wakaba, Mon Feb 11 13:27:21 2002 UTC
# Line 44  class headerType { Line 44  class headerType {
44    var $newsgroups;  // the Newsgroups where the article belongs to    var $newsgroups;  // the Newsgroups where the article belongs to
45    var $followup;    var $followup;
46    var $date;    var $date;
   var $organization;  
47    var $references;    var $references;
48    var $content_transfer_encoding;    var $content_transfer_encoding;
49    var $mime_version;    var $mime_version;
# Line 56  class headerType { Line 55  class headerType {
55    var $answers;    var $answers;
56    var $isAnswer;    var $isAnswer;
57    var $username;    var $username;
58    var $user_agent;    var $field;
59    var $isReply;    var $isReply;
60  }  }
61    
# Line 397  function showgroups($gruppen) { Line 396  function showgroups($gruppen) {
396      echo '<a ';      echo '<a ';
397      if ((isset($frame_threadframeset)) && ($frame_threadframeset != ""))      if ((isset($frame_threadframeset)) && ($frame_threadframeset != ""))
398        echo 'target="'.$frame_threadframeset.'" ';        echo 'target="'.$frame_threadframeset.'" ';
399      echo 'href="'.$file_thread.'/'.urlencode($g->name).'/index.html">'.$g->name."</a></td>\n";      echo 'href="'.$file_thread.'/'.encode_newsgroup ($g->name).'/index">'.$g->name."</a></td>\n";
400      echo "<td>$g->description</td></tr>\n";      echo "<td>$g->description</td></tr>\n";
401      flush();      flush();
402    }    }
403    echo "</table>\n";    echo "</table>\n";
404  }  }
405    
406    function encode_newsgroup ($groupname) {
407      return urlencode (str_replace ('.', ':', $groupname));
408    }
409    
410  /*  /*
411   * gets a list of aviable articles in the group $groupname   * gets a list of aviable articles in the group $groupname
412   */   */
# Line 448  function headerDecode($value) { Line 451  function headerDecode($value) {
451        $newvalue=headerDecode($newvalue);  // maybe there are more encoded        $newvalue=headerDecode($newvalue);  // maybe there are more encoded
452      return(mb_convert_encoding($newvalue, "EUC-JP", "auto"));      // parts      return(mb_convert_encoding($newvalue, "EUC-JP", "auto"));      // parts
453    } else {    } else {
454      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"));  
     }  
455    }    }
456  }  }
457    
 function decode_quoted_pair($value) {  
       return(ereg_replace('\\\\(.)',"\\1",$value));  
 }  
   
 function getTimestamp($value) {  
   $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);  
   $value=str_replace("  "," ",$value);  
   $d=split(" ",$value,5);  
   if (strcmp(substr($d[0],strlen($d[0])-1,1),",") == 0) {  
     $date[0]=$d[1];  // day  
     $date[1]=$d[2];  // month  
     $date[2]=$d[3];  // year  
     $date[3]=$d[4];  // hours:minutes:seconds  
   } else {  
     $date[0]=$d[0];  // day  
     $date[1]=$d[1];  // month  
     $date[2]=$d[2];  // year  
     $date[3]=$d[3];  // hours:minutes:seconds  
   }  
   $time=split(":",$date[3]);  
   $timestamp=mktime($time[0],$time[1],$time[2],$months[$date[1]],$date[0],$date[2]);  
   return $timestamp;  
 }  
458    
459  function parse_header($hdr,$number="") {  function parse_header($hdr,$number="") {
460    for ($i=count($hdr)-1; $i>0; $i--)    for ($i=count($hdr)-1; $i>0; $i--)
# Line 488  function parse_header($hdr,$number="") { Line 463  function parse_header($hdr,$number="") {
463    $header = new headerType;    $header = new headerType;
464    $header->isAnswer=false;    $header->isAnswer=false;
465    for ($count=0;$count<count($hdr);$count++) {    for ($count=0;$count<count($hdr);$count++) {
466      $variable=substr($hdr[$count],0,strpos($hdr[$count]," "));      $variable=substr($hdr[$count],0,strpos($hdr[$count],":"));
467      $value=trim(substr($hdr[$count],strpos($hdr[$count]," ")+1));      $value=trim(substr($hdr[$count],strpos($hdr[$count],":")+1));
468        $header->field[strtolower($variable)][] = $value;
469        switch (strtolower($variable)) {        switch (strtolower($variable)) {
470          case "from:":          case "from":
471            $fromline=address_decode(headerDecode($value),"nirgendwo");            $fromline=address_decode(headerDecode($value),"nirgendwo");
472            if (!isset($fromline[0]["host"])) $fromline[0]["host"]="";            if (!isset($fromline[0]["host"])) $fromline[0]["host"]="";
473            $header->from=$fromline[0]["mailbox"]."@".$fromline[0]["host"];            $header->from=$fromline[0]["mailbox"]."@".$fromline[0]["host"];
# Line 502  function parse_header($hdr,$number="") { Line 478  function parse_header($hdr,$number="") {
478              $header->name=$fromline[0]["personal"];              $header->name=$fromline[0]["personal"];
479            }            }
480            break;            break;
481          case "message-id:":          case "message-id":
482            $header->id=$value;            $header->id=$value;
483            break;            break;
484          case "subject:":          case "subject":
485            $header->subject=headerDecode($value);            $header->subject = decode_unstructured_body($value);
486            break;            break;
487          case "newsgroups:":          case "newsgroups":
488            $header->newsgroups=$value;            $header->newsgroups=$value;
489            break;            break;
490          case "organization:":          case "content-transfer-encoding":
           $header->organization=$value;  
           break;  
         case "content-transfer-encoding:":  
491            $header->content_transfer_encoding=trim(strtolower($value));            $header->content_transfer_encoding=trim(strtolower($value));
492            break;            break;
493          case "content-type:":          case "content-type":
494            $header->content_type=array();            $header->content_type=array();
495            $subheader=split(";",$value);            $subheader=split(";",$value);
496            $header->content_type[0]=strtolower(trim($subheader[0]));            $header->content_type[0]=strtolower(trim($subheader[0]));
# Line 542  function parse_header($hdr,$number="") { Line 515  function parse_header($hdr,$number="") {
515              }              }
516            }            }
517            break;            break;
518          case "references:":          case "references":
519            $ref=ereg_replace("> *<", "> <", trim($value));            $ref=ereg_replace("> *<", "> <", trim($value));
520            while (strpos($ref,"> <") != false) {            while (strpos($ref,"> <") != false) {
521              $header->references[]=substr($ref,0,strpos($ref," "));              $header->references[]=substr($ref,0,strpos($ref," "));
# Line 550  function parse_header($hdr,$number="") { Line 523  function parse_header($hdr,$number="") {
523            }            }
524            $header->references[]=trim($ref);            $header->references[]=trim($ref);
525            break;            break;
526          case "date:":          case "date":
527            $header->date=getTimestamp(trim($value));            $header->date = strtotime(trim($value));
528            break;            break;
529          case "followup-to:":          case "followup-to":
530            $header->followup=trim($value);            $header->followup=trim($value);
531            break;            break;
532          case "x-newsreader:":  /*
533          case "x-mailer:":          case "x-newsreader":
534          case "user-agent:":          case "x-mailer":
535            $header->user_agent=trim(headerDecode($value));          case "user-agent":
536            break;            $header->user_agent= decode_structured_body($value);
         case "x-face:":  
 //          echo "<p>-".base64_decode($value)."-</p>";  
537            break;            break;
538    */
539        }        }
540    }    }
541    if (!isset($header->content_type[0]))    if (!isset($header->content_type[0]))
# Line 574  function parse_header($hdr,$number="") { Line 546  function parse_header($hdr,$number="") {
546    return $header;    return $header;
547  }  }
548    
549    function decode_unstructured_body ($body) {
550      $patterns = array (
551          "/(=\\?[^\\x00-\\x20()<>@,;:\\\"\\/\\[\\]?.=\\x7F]+\\?[BQ]\\?[^\\x00-\\x20\\x3F\\x7F]*\\?=)/ei",
552      );
553      $replace = array (
554          "mb_decode_mimeheader('\\1')",
555      );
556      return preg_replace ($patterns, $replace,
557                           mb_convert_encoding(fake_jisx0213($body), "EUC-JP", "auto"));
558    }
559    
560    function decode_structured_body ($body) {
561      $patterns = array (
562          "/\"((?:[^\"\\\\]+|\\\\.)*)\"/e",
563          "/\(((?:[^()\\\\]+|\\\\.|(?:\((?:[^()\\\\]+|\\\\.|(?:\((?:[^)\\\\]+|\\\\.\
564    )*\)))*\)))*)\)/e",
565      );
566      $replace = array (
567        "mb_convert_encoding(fake_jisx0213(decode_quoted_pair('\\1')),'EUC-JP','auto')",
568        "'('.mb_convert_encoding(fake_jisx0213(decode_quoted_pair('\\1')),
569                                 'EUC-JP','auto').')'",
570      );
571      return preg_replace ($patterns, $replace, $body);
572    }
573    
574    function decode_quoted_pair($value) {
575      $value = ereg_replace('\\\\(\\\\")', "\\1", $value);
576      return ereg_replace('\\\\(.)', "\\1", $value);
577    }
578    
579    function fake_jisx0213 ($value) {
580      $value = preg_replace ("/\\x1B\\\$\\(O/", "\x1B\\\$B", $value);
581      $value = preg_replace ("/\\x1B\\\$\\(P/", "\x1B\\\$(D", $value);
582      return $value;
583    }
584    
585  function decode_body($body,$encoding) {  function decode_body($body,$encoding) {
586    $bodyzeile="";    $bodyzeile="";
587    switch ($encoding) {    switch ($encoding) {
# Line 691  function parse_message($rawmessage) { Line 699  function parse_message($rawmessage) {
699  //      if ($body=="") $body=" ";  //      if ($body=="") $body=" ";
700  //    }  //    }
701      $body=decode_body($body,$message->header->content_transfer_encoding);      $body=decode_body($body,$message->header->content_transfer_encoding);
702      $message->body[0]=$body;      $message->body[0] = mb_convert_encoding($body, "EUC-JP", "auto");
703    }    }
704      if (!isset($message->header->content_type_charset))      if (!isset($message->header->content_type_charset))
705        $message->header->content_type_charset=array("ISO-8859-1");        $message->header->content_type_charset=array("ISO-8859-1");
# Line 852  function html_parse($comment, $group = " Line 860  function html_parse($comment, $group = "
860    return($comment);    return($comment);
861  }  }
862    
863    function uri_to_link($comment, $group = "", $msgidregex = "") {
864      global $frame_externallink;
865      global $file_article;
866      $comment = preg_replace (
867         '"((?:https?|mailto|urn|news|ftp|irc|mid|data|nntp|gother)):((?:[-_.!~*\'()A-Z0-9:;@=+$,%?/]+|&amp;)+)(#(?:[-_.!~*\'()A-Z0-9;/?:@&=+$,%]+|&amp;)+)?"ie',
868         'uri_to_link_uri("\1", "\2", "\3")',
869      $comment);
870      return($comment);
871    }
872    
873    function uri_to_link_uri ($scheme, $body, $fragment) {
874      global $file_article;
875      switch (strtolower($scheme)) {
876        case "urn":
877        case "data":
878          $uri = '/uri-res/N2L?'.urlencode($scheme.':'.$body);
879          break;
880        case "news":
881          if (!preg_match('"^//"', $body)) {
882            $uri = "../../".addslashes($file_article).'/junk/%3C'.$nbody.'%3E';
883          } else {
884            $uri = $scheme.':'.$body;
885          }
886          break;
887        case "mid":
888          $nbody = preg_replace('"/.*$"', "", $body);
889          $uri = "../../".addslashes($file_article).'/junk/%3C'.$nbody.'%3E';
890          break;
891        default:
892          $uri = $scheme.':'.$body;
893          break;
894      }
895      $uri = $uri . $fragment;
896      if (!empty($uri)) {
897        $uri = '<a href="'.$uri.'">'.$scheme.':'.$body.$fragment.'</a>';
898      }
899      return $uri;
900    }
901    
902    
903    
# Line 915  function interpretOverviewLine($zeile,$o Line 961  function interpretOverviewLine($zeile,$o
961        $article->subject=$subject;        $article->subject=$subject;
962      }      }
963      if ($overviewfmt[$i]=="Date:") {      if ($overviewfmt[$i]=="Date:") {
964        $article->date=getTimestamp($over[$i+1]);        $article->date = strtotime($over[$i+1]);
965      }      }
966      if ($overviewfmt[$i]=="From:") {      if ($overviewfmt[$i]=="From:") {
967        $fromline=address_decode(headerDecode($over[$i+1]),"nirgendwo");        $fromline=address_decode(headerDecode($over[$i+1]),"nirgendwo");
# Line 1481  function show_header($head,$group) { Line 1527  function show_header($head,$group) {
1527      echo $text_header["newsgroups"].htmlspecialchars(str_replace(',',', ',$head->newsgroups))."<br>\n";      echo $text_header["newsgroups"].htmlspecialchars(str_replace(',',', ',$head->newsgroups))."<br>\n";
1528    if (isset($head->followup) && ($article_show["Followup"]) && ($head->followup != ""))    if (isset($head->followup) && ($article_show["Followup"]) && ($head->followup != ""))
1529      echo $text_header["followup"].htmlspecialchars($head->followup)."<br>\n";      echo $text_header["followup"].htmlspecialchars($head->followup)."<br>\n";
   if ((isset($head->organization)) && ($article_show["Organization"]) &&  
      ($head->organization != ""))  
     echo $text_header["organization"].  
          html_parse(htmlspecialchars($head->organization))."<br>\n";  
1530    if ($article_show["Date"])    if ($article_show["Date"])
1531      echo $text_header["date"].date($text_header["date_format"],$head->date)."<br>\n";      echo $text_header["date"].date($text_header["date_format"],$head->date)."<br>\n";
1532    if ($article_show["Message-ID"])    if ($article_show["Message-ID"])
# Line 1499  function show_header($head,$group) { Line 1541  function show_header($head,$group) {
1541      }      }
1542      echo "<br>";      echo "<br>";
1543    }    }
1544    if (isset($head->user_agent)) {    $fields = array ("x-moe", "x-brother", "x-syster", "x-wife",
1545      if ((isset($article_show["User-Agent"])) &&                     "x-daughter", "x-respect",
1546         ($article_show["User-Agent"])) {                     "user-agent", "x-mailer", "x-newsreader",
1547        echo $text_header["user-agent"].htmlspecialchars($head->user_agent)."<br>\n";                     "list-id", "x-uri", "x-mail-count", "keywords");
1548      } else {    for ($i = 0; $i < count($fields); $i++) {
1549        echo "<!-- User-Agent: ".htmlspecialchars($head->user_agent)." -->\n";      if (count($head->field[$fields[$i]])) {
1550          if ((isset($article_show[$fields[$i]])) && ($article_show[$fields[$i]])) {
1551            echo "<div class=\"field ".$fields[$i]."\"><span class=\"name\">"
1552                .$text_header[$fields[$i]]."</span> <span class=\"body\">"
1553                .uri_to_link(htmlspecialchars(decode_structured_body(
1554                                    join(', ', $head->field[$fields[$i]]))))
1555                ."</span></div>\n";
1556          }
1557        }
1558      }
1559      $fields = array ("x-weather", "x-copyright", "comments", "organization");
1560      for ($i = 0; $i < count($fields); $i++) {
1561        if (count($head->field[$fields[$i]])) {
1562          if ((isset($article_show[$fields[$i]])) && ($article_show[$fields[$i]])) {
1563            for ($j = 0; $j > count($head->field[$fields[$i]]); $j++) {
1564              echo "<div class=\"field ".$fields[$i]."\"><span class=\"name\">"
1565                  .$text_header[$fields[$i]]."</span> <span class=\"body\">"
1566                  .uri_to_link(htmlspecialchars(decode_unstructured_body(
1567                                               $head->field[$fields[$i]][$j])))
1568                  ."</span></div>\n";
1569            }
1570          }
1571      }      }
1572    }    }
1573    if ((isset($attachment_show)) && ($attachment_show==true) &&    if ((isset($attachment_show)) && ($attachment_show==true) &&
# Line 1573  function show_article($group,$id,$attach Line 1636  function show_article($group,$id,$attach
1636  //        }  //        }
1637  //      echo $body[$i]."\n";  //      echo $body[$i]."\n";
1638          $b=$body[$i];          $b=$body[$i];
1639          echo html_parse(htmlspecialchars($b)."\n", $group, $msgidregex);          echo uri_to_link(htmlspecialchars($b)."\n", $group, $msgidregex);
1640        }        }
1641        echo "\n</pre>\n";        echo "\n</pre>\n";
1642      } else {      } else {
# Line 1676  function quoted_printable_encode($line) Line 1739  function quoted_printable_encode($line)
1739   * $body: The article itself   * $body: The article itself
1740   */   */
1741  function verschicken($subject,$from,$newsgroups,$ref,$body) {  function verschicken($subject,$from,$newsgroups,$ref,$body) {
1742    global $server,$port,$send_poster_host,$organization,$text_error;    global $server,$port,$send_poster_host,$organization,$text_error,$text_ua;
1743    global $file_footer;    global $file_footer;
1744    flush();    flush();
1745    $ns=OpenNNTPconnection($server,$port);    $ns=OpenNNTPconnection($server,$port);

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.34

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24