old header were to complicated for nothin. drop class Header, and treat it from Post
authorx2000habouzit <x2000habouzit>
Sun, 2 Jan 2005 19:53:01 +0000 (19:53 +0000)
committerx2000habouzit <x2000habouzit>
Sun, 2 Jan 2005 19:53:01 +0000 (19:53 +0000)
article.php
include/post.inc.php
include/spool.inc.php
install.d/config.inc.php
install.d/format.inc.php
install.d/profile.inc.php
post.php
thread.php

index 2c7faeb..d21a290 100644 (file)
@@ -81,9 +81,9 @@ summary="<?php echo _b_('Contenu du message'); ?>">
   </tr>
 <?php
 foreach ($news['headdisp'] as $nick) {
-  if (isset($post->headers->$nick)) 
+  if (isset($post->headers[$nick])) 
     echo "<tr><td class=\"{$css['bicoltitre']}\">".header_translate($nick)."</td>"
-    ."<td>".formatdisplayheader($nick,$post->headers->$nick,$spool)
+    ."<td>".formatdisplayheader($nick,$post->headers[$nick],$spool)
     ."</td></tr>\n";
 }
 ?>
index 155570a..2e8d8f9 100644 (file)
  */
 
 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);
     }
 }
 
index 431fb96..d7579ce 100644 (file)
@@ -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
  */
index 2375e73..885d2e9 100644 (file)
@@ -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'
+        );
 ?>
index 7c28242..cfd7d6c 100644 (file)
@@ -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 '<img src="xface.php?face='.base64_encode($_text)
             .'"  alt="x-face" />';
         
index 5d96652..5f5951b 100644 (file)
@@ -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
index 4dfbf06..5d0dddf 100644 (file)
--- 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();
index ba1efe0..39c83ff 100644 (file)
@@ -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']));