Fixes vim mode line.
[banana.git] / banana / nntp.inc.php
index 3b02c86..1076a57 100644 (file)
@@ -14,7 +14,6 @@ require_once dirname(__FILE__) . '/protocoleinterface.inc.php';
 
 class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
 {
-    private $description = null;
     private $ingroup = null;
 
     private $mode = null;
@@ -27,30 +26,27 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
         $url = parse_url(Banana::$nntp_host);
         if ($url['scheme'] == 'nntps' || $url['scheme'] == 'snntp') {
             $url['host'] = 'ssl://' . $url['host'];
-        }
-        if (!isset($url['port'])) {
+            if (!isset($url['port'])) {
+                $url['port'] = 563;
+            }
+        } else if (!isset($url['port'])) {
             $url['port'] = 119;
         }
-        if (!isset($url['user'])) {
-            parent::__construct($url['host'], $url['port']);
-        } else {
-            parent::__construct($url['host'], $url['port'], 120, false);
+        parent::__construct($url['host'], $url['port']);
+        if (isset($url['user'])) {
             $this->authinfo($url['user'], $url['pass']);
-        }      
+        }
     }
 
     /** Return the descript;ion of the current box
      */
     public function getDescription()
     {
-        if ($this->description) {
-            return $this->description;
-        }
         $descs = $this->xgtitle(Banana::$group);
         if (isset($descs[Banana::$group])) {
-            $this->description = $descs[Banana::$group];
+            return trim(utf8_encode($descs[Banana::$group]));
         }
-        return $this->description;
+        return null;
     }
 
     /** Return the list of the boxes
@@ -67,7 +63,11 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
             } else {
                 $list = $this->listGroups();
                 if ($mode == Banana::BOXES_SUB) {
-                    $sub = array_flip(Banana::$profile['subscribe']);
+                    if (is_array(Banana::$profile['subscribe'])) {
+                        $sub = array_flip(Banana::$profile['subscribe']);
+                    } else {
+                        $sub = array();
+                    }
                     $list = array_intersect_key($list, $sub);
                 }
             }
@@ -78,10 +78,10 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
                     if (!is_utf8($desc)) {
                         $desc = utf8_encode($desc);
                     }
-                    $this->boxes[$group] = array('desc' => $desc);           
+                    $this->boxes[$group] = array('desc' => $desc);
                 } else {
                     $this->boxes[$group] = array('desc' => null);
-                }    
+                }
             }
             ksort($this->boxes);
         }
@@ -89,7 +89,25 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
             foreach ($this->boxes as $group=>&$desc) {
                 list($msgnum, $first, $last, $groupname) = $this->group($group);
                 $this->ingroup = $group;
-                $new = count($this->newnews($group, $since));
+                $new = $this->newnews($group, $since);
+                if (!is_array($new)) {
+                    $new = 0;
+                } else {
+                    $c = count($new);
+                    if ($c > 0 && function_exists('hook_listReadMessages')) {
+                        $msgs = hook_listReadMessages($group);
+                        if (is_array($msgs)) {
+                            foreach ($msgs as $msg) {
+                                if (is_numeric($msg)) {
+                                    $c--;
+                                } else if (in_array($msg, $new)) {
+                                    $c--;
+                                }
+                            }
+                        }
+                    }
+                    $new = $c;
+                }
                 $desc['msgnum'] = $msgnum;
                 $desc['unread'] = $new;
             }
@@ -103,6 +121,7 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
      */
     public function &getMessage($id)
     {
+        $message = null;
         if (is_numeric($id) && Banana::$group != $this->ingroup) {
             if (is_null(Banana::$spool)) {
                 $this->group(Banana::$group);
@@ -113,9 +132,9 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
         }
         $data = $this->article($id);
         if ($data !== false) {
-            return new BananaMessage($data);
+            $message = new BananaMessage($data);
         }
-        return null;
+        return $message;
     }
 
     /** Return the sources of the message
@@ -134,7 +153,8 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
         if ($data !== false) {
             return implode("\n", $data);
         }
-        return null;
+        $data = null;
+        return $data;
     }
 
     /** Return the indexes of the messages presents in the Box
@@ -155,10 +175,11 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
         $messages = array();
         foreach ($msg_headers as $header) {
             $headers = $this->xhdr($header, $firstid, $lastid);
-            array_walk($headers, array('BananaMimePart', 'decodeHeader'));
             $header  = strtolower($header);
             if ($header == 'date') {
                 $headers = array_map('strtotime', $headers);
+            } else {
+                array_walk($headers, array('BananaMimePart', 'decodeHeader'));
             }
             foreach ($headers as $id=>&$value) {
                 if (!isset($messages[$id])) {
@@ -208,7 +229,7 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
 
     /** Send the message
      */
-    public function send(BananaMessage &$message)
+    public function send(BananaMessage $message)
     {
         $sources = $message->get(true);
         return $this->post($sources);
@@ -216,7 +237,7 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
 
     /** Cancel the message
      */
-    public function cancel(BananaMessage &$message)
+    public function cancel(BananaMessage $message)
     {
         $headers = Array('From' => Banana::$profile['From'],
                          'Newsgroups' => Banana::$group,
@@ -252,5 +273,5 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
     }
 }
 
-// vim:set et sw=4 sts=4 ts=4:
+// vim:set et sw=4 sts=4 ts=4 fenc=utf-8:
 ?>