cvs: php-news-web / article.php

From: Date: Wed, 23 Jan 2002 22:44:08 +0000
Subject: cvs: php-news-web / article.php
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-8289@lists.php.net to get a copy of this message
jimw Wed Jan 23 17:44:08 2002 EDT Modified files: /php-news-web article.php Log: handle folded headers, charset encoding Index: php-news-web/article.php diff -u php-news-web/article.php:1.11 php-news-web/article.php:1.12 --- php-news-web/article.php:1.11 Sun Jul 8 16:38:55 2001 +++ php-news-web/article.php Wed Jan 23 17:44:08 2002 @@ -16,6 +16,8 @@ or die("failed to get article $article"); $inheaders = 1; $headers = array(); +$charset = ""; +$lk = ''; while (!feof($s)) { $line = fgets($s, 4096); if ($line == ".\r\n") break; @@ -23,19 +25,29 @@ $inheaders = 0; head("$group: ".format_subject($headers[subject])); start_article($group,$headers); + if ($headers['content-type'] + && preg_match("/charset=(\"|'|)(.+)\\1/s", $headers['content-type'], $m)) { + $charset = trim($m[2]); + } continue; } # fix lines that started with a period and got escaped if (substr($line,0,2) == "..") $line = substr($line,1); if ($inheaders) { list($k,$v) = explode(": ", $line, 2); - $headers[strtolower($k)] = $v; + if ($k && $v) { + $headers[strtolower($k)] = $v; + $lk = strtolower($k); + } + else { + $headers[$lk] .= $line; + } } else { # this is some amazingly simplistic code to color quotes/signatures # differently, and turn links into real links. it actually appears # to work fairly well, but could easily be made more sophistimicated. - $line = htmlspecialchars($line); + $line = htmlentities($line,ENT_NOQUOTES,$charset); $line = preg_replace("/((mailto|http|ftp|nntp|news):.+?)(&gt;|\\s|\\)|\\.\\s|$)/","<a href=\"\\1\">\\1</a>\\3",$line); if (!$insig && $line == "-- \r\n") { echo "<span class=\"signature\">";

« previous php.mirrors (#8289) next »