From 01681efdcbe6e290915919d1c03ab6e0a44ba21f Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Sun, 2 Jan 2005 19:53:01 +0000 Subject: [PATCH] old header were to complicated for nothin. drop class Header, and treat it from Post --- article.php | 4 +- include/post.inc.php | 103 ++++++++++++++-------------------------------- include/spool.inc.php | 2 + install.d/config.inc.php | 99 ++++++++++++++++++++------------------------ install.d/format.inc.php | 4 +- install.d/profile.inc.php | 2 +- post.php | 53 ++++++++++++------------ thread.php | 4 +- 8 files changed, 111 insertions(+), 160 deletions(-) diff --git a/article.php b/article.php index 2c7faeb..d21a290 100644 --- a/article.php +++ b/article.php @@ -81,9 +81,9 @@ summary=""> headers->$nick)) + if (isset($post->headers[$nick])) echo "".header_translate($nick)."" - ."".formatdisplayheader($nick,$post->headers->$nick,$spool) + ."".formatdisplayheader($nick,$post->headers[$nick],$spool) ."\n"; } ?> diff --git a/include/post.inc.php b/include/post.inc.php index 155570a..2e8d8f9 100644 --- a/include/post.inc.php +++ b/include/post.inc.php @@ -11,111 +11,72 @@ */ class NNTPPost { + var $nb; /** headers */ var $headers; /** body */ var $body; + /** poster name */ + var $name; /** constructor * @param $_nntp RESOURCE handle to NNTP socket * @param $_id STRING MSGNUM or MSGID (a group should be selected in this case) */ function NNTPPost(&$_nntp, $_id) { - $this->headers = new headers($_nntp, $_id); - if (!$this->headers) { - $this = null; - return false; - } + $this->nb = $_id; + $this->_header($_nntp); + $this->body = join("\n", $_nntp->body($_id)); - if (isset($this->headers->contentencoding) && preg_match("/base64/", $this->headers->contentencoding)) { - $this->body = base64_decode($this->body); - } - if (isset($this->headers->contentencoding) && preg_match("/quoted-printable/", $this->headers->contentencoding)) { - $this->body = quoted_printable_decode($this->body); + + if (isset($this->headers['content-transfer-encoding'])) { + if (preg_match("/base64/", $this->headers['content-transfer-encoding'])) { + $this->body = base64_decode($this->body); + } elseif (preg_match("/quoted-printable/", $this->headers['content-transfer-encoding'])) { + $this->body = quoted_printable_decode($this->body); + } } - if (preg_match('!charset=([^;]*);!', $this->headers->contenttype, $matches)) { + + if (preg_match('!charset=([^;]*);!', $this->headers['content-type'], $matches)) { $this->body = iconv($matches[1], 'iso-8859-1', $this->body); } } -} - -/** class for headers - */ -class Headers { - /** MSGNUM : *local* spool id */ - var $nb; // numéro du post - /** MSGID : Message-ID */ - var $msgid; // Message-ID - /** From header */ - var $from; // From - /** Name (if present in From header) */ - var $name; - /** Mail (in From header) */ - var $mail; - /** Subject header */ - var $subject; // Subject - /** Newsgroup¨ header */ - var $newsgroups; // Newsgroups - /** Followup-To header */ - var $followup; - /** Content-Type header */ - var $contenttype; - /** Content-Transfer-Encoding header */ - var $contentencoding; - /** Date header */ - var $date; - /** Organization header */ - var $organization; - /** References header */ - var $references; - - /** constructor - * @param $_nntp RESOURCE handle to NNTP socket - * @param $_id STRING MSGNUM or MSGID - */ - - function headers(&$_nntp, $_id) { + function _header(&$_nntp) + { global $news; - $hdrs = $_nntp->head($_id); + $hdrs = $_nntp->head($this->nb); if (!$hdrs) { $this = null; return false; } + + $this->nb = $_id; // parse headers foreach ($hdrs as $line) { if (preg_match("/^[\t\r ]+/", $line)) { - $line = ($lasthdr=="X-Face"?"":" ").ltrim($line); - if (in_array($lasthdr, array_keys($news['head']))) { - $this->{$news['head'][$lasthdr]} .= $line; + $line = ($hdr=="X-Face"?"":" ").ltrim($line); + if (in_array($hdr, $news['head'])) { + $this->headers[$hdr] .= $line; } } else { list($hdr, $val) = split(":[ \t\r]*", $line, 2); - if (in_array($hdr, array_keys($news['head']))) { - $this->{$news['head'][$hdr]} = $val; + $hdr = strtolower($hdr); + if (in_array($hdr, $news['head'])) { + $this->headers[$hdr] = $val; } - $lasthdr = $hdr; } } // decode headers foreach ($news['hdecode'] as $hdr) { - if (isset($this->$hdr)) { - $this->$hdr = headerDecode($this->$hdr); + if (isset($this->headers[$hdr])) { + $this->headers[$hdr] = headerDecode($this->headers[$hdr]); } } - // sets name and mail - $this->name = $this->from; - $this->mail = $this->from; - if (preg_match("/(.*)<(.*)@(.*)>/", $val, $match)) { - $this->name = str_replace("\"", "", trim($match[1])); - $this->mail = $match[2]."@".$match[3]; - } - if (preg_match("/([\w\.]+)@([\w\.]+) \((.*)\)/", $val, $match)) { - $this->name = trim($match[3]); - $this->mail = $match[1]."@".$match[2]; - } - $this->nb = $_id; - $retour->numerr = 0; + + $this->name = $this->headers['from']; + $this->name = preg_replace('/<[^ ]*>/', '', $this->name); + $this->name = trim($this->name); } } diff --git a/include/spool.inc.php b/include/spool.inc.php index 431fb96..d7579ce 100644 --- a/include/spool.inc.php +++ b/include/spool.inc.php @@ -19,6 +19,8 @@ if(!function_exists('_file_put_contents')) { } } +function spoolcompare($a,$b) { return ($b->date>=$a->date); } + /** Class spoolhead * class used in thread overviews */ diff --git a/install.d/config.inc.php b/install.d/config.inc.php index 2375e73..885d2e9 100644 --- a/install.d/config.inc.php +++ b/install.d/config.inc.php @@ -7,17 +7,6 @@ * Copyright: See COPYING files that comes with this distribution ********************************************************************************/ -/** comparison function for the overview - * @param $a OBJECT spoolhead - * @param $b OBJECT spoolhead - * @return - */ - -function spoolcompare($a,$b) { - global $news; - return ($b->date>=$a->date); -} - // spool config in spool.inc.php $news['maxspool'] = 3000; @@ -26,28 +15,28 @@ $news['hdecode'] = array('from','name','organization','subject'); // headers in article.php $news['head'] = array( - 'From' => 'from', - 'Subject' => 'subject', - 'Newsgroups' => 'newsgroups', - 'Followup-To' => 'followup', - 'Date' => 'date', - 'Message-ID' => 'msgid', - 'Organization' => 'organization', - 'References' => 'references', - 'X-Face' => 'xface', - ); + 'From' => 'from', + 'Subject' => 'subject', + 'Newsgroups' => 'newsgroups', + 'Followup-To' => 'followup', + 'Date' => 'date', + 'Message-ID' => 'msgid', + 'Organization' => 'organization', + 'References' => 'references', + 'X-Face' => 'xface', +); // headers in article.php $news['headdisp']=array( - 'from', - 'subject', - 'newsgroups', - 'followup', - 'date', - 'organization', - 'references', - 'xface' -); + 'from', + 'subject', + 'newsgroups', + 'followup', + 'date', + 'organization', + 'references', + 'xface' + ); // overview configuration in article.php $news['threadtop'] = 5; @@ -61,31 +50,31 @@ $news['max'] = 50; // custom headers in post.php $news['customhdr'] = "Content-Type: text/plain; charset=iso-8859-15\n" - ."Mime-Version: 1.0\n" - ."Content-Transfer-Encoding: 8bit\n" - ."HTTP-Posting-Host: ".gethostbyname($_SERVER['REMOTE_ADDR'])."\n" - ."User-Agent: Banana 0.7.1\n"; +."Mime-Version: 1.0\n" +."Content-Transfer-Encoding: 8bit\n" +."HTTP-Posting-Host: ".gethostbyname($_SERVER['REMOTE_ADDR'])."\n" +."User-Agent: Banana 0.7.1\n"; $css = array( - 'bananashortcuts' => 'bananashortcuts', - 'bicol' => 'bicol', - 'bicoltitre' => 'bicoltitre', - 'bicolvpadd' => 'bicolvpadd', - 'pair' => 'pair', - 'impair' => 'impair', - 'bouton' => 'bouton', - 'error' => 'error', - 'normal' => 'normal', - 'total' => 'total', - 'unread' => 'unread', - 'group' => 'group', - 'description' => 'description', - 'date' => 'date', - 'subject' => 'subject', - 'from' => 'from', - 'author' => 'author', - 'nopadd' => 'nopadd', - 'overview' => 'overview', - 'tree' => 'tree' -); + 'bananashortcuts' => 'bananashortcuts', + 'bicol' => 'bicol', + 'bicoltitre' => 'bicoltitre', + 'bicolvpadd' => 'bicolvpadd', + 'pair' => 'pair', + 'impair' => 'impair', + 'bouton' => 'bouton', + 'error' => 'error', + 'normal' => 'normal', + 'total' => 'total', + 'unread' => 'unread', + 'group' => 'group', + 'description' => 'description', + 'date' => 'date', + 'subject' => 'subject', + 'from' => 'from', + 'author' => 'author', + 'nopadd' => 'nopadd', + 'overview' => 'overview', + 'tree' => 'tree' + ); ?> diff --git a/install.d/format.inc.php b/install.d/format.inc.php index 7c28242..cfd7d6c 100644 --- a/install.d/format.inc.php +++ b/install.d/format.inc.php @@ -19,7 +19,7 @@ function formatDisplayHeader($_header,$_text,$_spool) { case "date": return formatDate($_text); - case "followup": + case "followup-to": case "newsgroups": $res = ""; $groups = preg_split("/(\t| )*,(\t| )*/",$_text); @@ -47,7 +47,7 @@ function formatDisplayHeader($_header,$_text,$_spool) { } return $rsl; - case "xface": + case "x-face": return 'x-face'; diff --git a/install.d/profile.inc.php b/install.d/profile.inc.php index 5d96652..5f5951b 100644 --- a/install.d/profile.inc.php +++ b/install.d/profile.inc.php @@ -12,7 +12,7 @@ * @return BOOLEAN true if user has right to cancel message */ function checkcancel($_headers) { - return ($_headers->from == $_SESSION['name']." <".$_SESSION['mail'].">"); + return ($_headers['from'] == $_SESSION['name']." <".$_SESSION['mail'].">"); } /** getprofile : sets profile variables diff --git a/post.php b/post.php index 4dfbf06..5d0dddf 100644 --- a/post.php +++ b/post.php @@ -21,46 +21,45 @@ require_once("include/error.inc.php"); $profile = getprofile(); require_once("include/header.inc.php"); if (isset($_REQUEST['group'])) { - $group=htmlentities(strtolower($_REQUEST['group'])); + $group=htmlentities(strtolower($_REQUEST['group'])); } if (isset($_REQUEST['id'])) { - $id=htmlentities(strtolower($_REQUEST['id'])); + $id=htmlentities(strtolower($_REQUEST['id'])); } if (isset($group)) { - $target = $group; + $target = $group; } $nntp = new nntp($news['server']); if (!$nntp) error("nntpsock"); if ($news['user']!="anonymous") { - $result = $nntp->authinfo($news["user"],$news["pass"]); - if (!$result) error("nntpauth"); + $result = $nntp->authinfo($news["user"],$news["pass"]); + if (!$result) error("nntpauth"); } if (isset($group) && isset($id) && isset($_REQUEST['type']) && - ($_REQUEST['type']=='followup')) { - $rq=$nntp->group($group); - $post = new NNTPPost($nntp,$id); - if ($post) { - $subject = (preg_match("/^re:/i",$post->headers->subject)?"":"Re: ") - .$post->headers->subject; - if ($profile['dropsig']) { - $cutoff=strpos($post->body,"\n-- \n"); - if ($cutoff) { - $quotetext = substr($post->body,0,strpos($post->body,"\n-- \n")); - } else { - $quotetext = $post->body; - } - } else { - $quotetext = $post->body; - } - $body = $post->headers->name." wrote :\n".wrap($quotetext, "> "); - if (isset($post->headers->followup)) - $target=$post->headers->followup; - else - $target=$post->headers->newsgroups; - } + ($_REQUEST['type']=='followup')) { + $rq=$nntp->group($group); + $post = new NNTPPost($nntp,$id); + if ($post) { + $subject = (preg_match("/^re:/i",$post->headers['subject'])?"":"Re: ").$post->headers['subject']; + if ($profile['dropsig']) { + $cutoff=strpos($post->body,"\n-- \n"); + if ($cutoff) { + $quotetext = substr($post->body,0,strpos($post->body,"\n-- \n")); + } else { + $quotetext = $post->body; + } + } else { + $quotetext = $post->body; + } + $body = $post->name." wrote :\n".wrap($quotetext, "> "); + if (isset($post->headers['followup-to'])) + $target = $post->headers['followup-to']; + else + $target = $post->headers['newsgroups']; + } } $nntp->quit(); diff --git a/thread.php b/thread.php index ba1efe0..39c83ff 100644 --- a/thread.php +++ b/thread.php @@ -99,8 +99,8 @@ if (isset($_REQUEST['action']) && (isset($_REQUEST['type'])) && $rq=$nntp->group($group); $post = new NNTPPost($nntp,$id); if ($post) { - $refs = (isset($post->headers->references)? - $post->headers->references." ":"").$post->headers->msgid; + $refs = (isset($post->headers['references'])? + $post->headers['references']." ":"").$post->headers['message-id']; } $body = preg_replace("/\n\.[ \t\r]*\n/m","\n..\n",stripslashes($_REQUEST['body'])); -- 2.1.4