Fix erroneous unread count in some specific cases.
[banana.git] / banana / nntp.inc.php
index 17aaeba..910075d 100644 (file)
@@ -26,16 +26,16 @@ 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
@@ -63,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);
                 }
             }
@@ -74,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);
         }
@@ -85,7 +89,12 @@ 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 {
+                    $new = count($new);
+                }
                 $desc['msgnum'] = $msgnum;
                 $desc['unread'] = $new;
             }
@@ -153,10 +162,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])) {
@@ -206,7 +216,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);
@@ -214,7 +224,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,