Convert sources to UTF-8
[banana.git] / banana / nntp.inc.php
index f1dde9d..37a354f 100644 (file)
@@ -14,7 +14,6 @@ require_once dirname(__FILE__) . '/protocoleinterface.inc.php';
 
 class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
 {
-    private $groupname = null;
     private $description = null;
     private $ingroup = null;
 
@@ -23,9 +22,9 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
 
     /** Build a protocole handler plugged on the given box
      */
-    public function __construct($box = null)
+    public function __construct()
     {
-        $url = parse_url(Banana::$host);
+        $url = parse_url(Banana::$nntp_host);
         if ($url['scheme'] == 'nntps' || $url['scheme'] == 'snntp') {
             $url['host'] = 'ssl://' . $url['host'];
         }
@@ -38,7 +37,6 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
             parent::__construct($url['host'], $url['port'], 120, false);
             $this->authinfo($url['user'], $url['pass']);
         }      
-        $this->groupname = $box;
     }
 
     /** Return the descript;ion of the current box
@@ -48,9 +46,9 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
         if ($this->description) {
             return $this->description;
         }
-        $descs = $this->xgtitle($this->groupname);
-        if (isset($descs[$this->groupname])) {
-            $this->description = $descs[$this->groupname];
+        $descs = $this->xgtitle(Banana::$group);
+        if (isset($descs[Banana::$group])) {
+            $this->description = $descs[Banana::$group];
         }
         return $this->description;
     }
@@ -101,16 +99,14 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
 
     /** Return a message
      * @param id Id of the emssage (can be either an Message-id or a message index)
-     * @param msg_headers Headers to process
-     * @param is_msgid If is set, $id is en Message-Id
      * @return A BananaMessage or null if the given id can't be retreived
      */
-    public function getMessage($id, array $msg_headers = array(), $is_msgid = false)
+    public function &getMessage($id)
     {
-        if (!$is_msgid && $this->groupname != $this->ingroup) {
+        if (is_numeric($id) && Banana::$group != $this->ingroup) {
             if (is_null(Banana::$spool)) {
-                $this->group($this->groupname);
-                $this->ingroup = $this->groupname;
+                $this->group(Banana::$group);
+                $this->ingroup = Banana::$group;
             } else {
                 $id = array_search($id, Banana::$spool->ids);
             }
@@ -119,7 +115,28 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
         if ($data !== false) {
             return new BananaMessage($data);
         }
-        return null;
+        $data = null;
+        return $data;
+    }
+
+    /** Return the sources of the message
+     */
+    public function getMessageSource($id)
+    {
+        if (is_numeric($id) && Banana::$group != $this->ingroup) {
+            if (is_null(Banana::$spool)) {
+                $this->group(Banana::$group);
+                $this->ingroup = Banana::$group;
+            } else {
+                $id = array_search($id, Banana::$spool->ids);
+            }
+        }
+        $data = $this->article($id);
+        if ($data !== false) {
+            return implode("\n", $data);
+        }
+        $data = null;
+        return $data;
     }
 
     /** Return the indexes of the messages presents in the Box
@@ -127,8 +144,8 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
      */
     public function getIndexes()
     {
-        list($msgnum, $first, $last, $groupname) = $this->group($this->groupname);
-        $this->ingroup = $this->groupname;
+        list($msgnum, $first, $last, $groupname) = $this->group(Banana::$group);
+        $this->ingroup = Banana::$group;
         return array($msgnum, $first, $last);
     }
 
@@ -167,7 +184,7 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
      */
     public function getNewIndexes($since)
     {
-        return $this->newnews($this->groupname, $since);
+        return $this->newnews(Banana::$group, $since);
     }
 
     /** Return true if can post
@@ -204,10 +221,10 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
     public function cancel(BananaMessage &$message)
     {
         $headers = Array('From' => Banana::$profile['From'],
-                         'Newsgroups' => $this->groupname,
+                         'Newsgroups' => Banana::$group,
                          'Subject'    => 'cmsg ' . $message->getHeaderValue('message-id'),
                          'Control'    => 'cancel ' . $message->getHeaderValue('message-id'));
-        $headers = array_merge($headers, Banana::$custom_hdr);
+        $headers = array_merge($headers, Banana::$msgedit_headers);
         $body   = 'Message canceled with Banana';
         $msg    = BananaMessage::newMessage($headers, $body);
         return $this->send($msg);
@@ -219,29 +236,23 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
     {
         return 'NNTP';
     }
-}
 
-/*
-require_once dirname(__FILE__) . '/spool.inc.php';
-$time = microtime(true);
-$nntp = new BananaNNTP('xorg.promo.x2002');
-if (!$nntp->isValid()) {
-    echo "Beuh !\n";
-    exit;
+    /** Return the filename for the spool
+     */
+    public function filename()
+    {
+        $url  = parse_url(Banana::$nntp_host);
+        $file = '';
+        if (isset($url['host'])) {
+            $file .= $url['host'] . '_';
+        }
+        if (isset($url['port'])) {
+            $file .= $url['port'] . '_';
+        }
+        $file .= Banana::$group;
+        return $file;
+    }
 }
-Banana::$protocole =& $nntp;
-Banana::$spool =& BananaSpool::getSpool('xorg.promo.x2002');
-$msg = $nntp->getMessage(3424);
-echo '<html><head>
-        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-        <link rel="stylesheet" type="text/css" href="css/banana.css"/>
-</head><body><table class="banana_msg"><tr><td>';
-//echo $msg->getFormattedBody('plain');
-echo $msg->getFormattedBody();
-echo '</td></tr></table></body></html>', "\n";
-$end = microtime(true);
-echo ($end - $time) . "s\n";
-*/ 
-
-// vim:set et sw=4 sts=4 ts=4:
+
+// vim:set et sw=4 sts=4 ts=4 enc=utf-8:
 ?>