Prevents error on newsgroup without any message.
authorStéphane Jacob <sj@m4x.org>
Sat, 1 Oct 2011 15:40:19 +0000 (17:40 +0200)
committerStéphane Jacob <sj@m4x.org>
Sat, 1 Oct 2011 15:40:19 +0000 (17:40 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
banana/mbox.inc.php
banana/spool.inc.php

index f48c877..3483cec 100644 (file)
@@ -108,7 +108,10 @@ class BananaMBox implements BananaProtocoleInterface
     {
         $options = array();
         if (@filesize($this->getFileName()) == @Banana::$spool->storage['size']) {
-            return max(array_keys(Banana::$spool->overview)) + 1;
+            if (!empty(Banana::$spool->overview)) {
+                return max(array_keys(Banana::$spool->overview)) + 1;
+            }
+            return 1;
         }
         $this->getMBoxPosition($options);
         $val =& $this->callHelper('-c', $options);
index ace19f7..e0a144a 100644 (file)
@@ -232,38 +232,42 @@ class BananaSpool
 
         // Build all the new Spool Heads
         $time = time();
-        foreach ($messages as $id=>&$message) {
-            if (!isset($this->overview[$id])) {
-                $this->overview[$id] = new BananaSpoolHead($id, $message);
-                $head =& $this->overview[$id];
-                $this->ids[$head->msgid] =& $head;
-                $head->time = $time;
-            }
-        }
-
-        // Build tree
-        $null = null;
-        foreach ($messages as $id=>&$message) {
-            $msg         =& $this->overview[$id];
-            $parents     =& $this->getReferences($message);
-            while (!empty($parents) && ($msg->parent === $msg || is_null($msg->parent))) {
-                @$msg->parent =& array_pop($parents);
-            }
-
-            if (!is_null($msg->parent)) {
-                $parent =& $msg->parent;
-                $parent->children[] =& $msg;
-                while (!is_null($parent)) {
-                    $parent->desc += $msg->desc;
-                    $parent->time  = $time;
-                    $prev =& $parent;
-                    if ($parent !== $parent->parent) {
-                        $parent =& $parent->parent;
-                    } else {
-                        $parent =& $null;
+        if (!empty($messages)) {
+            foreach ($messages as $id=>&$message) {
+                if (!isset($this->overview[$id])) {
+                    $this->overview[$id] = new BananaSpoolHead($id, $message);
+                    $head =& $this->overview[$id];
+                    $this->ids[$head->msgid] =& $head;
+                    $head->time = $time;
+                }
+            }
+
+            // Build tree
+            $null = null;
+            foreach ($messages as $id=>&$message) {
+                $msg         =& $this->overview[$id];
+                $parents     =& $this->getReferences($message);
+                while (!empty($parents) && ($msg->parent === $msg || is_null($msg->parent))) {
+                    @$msg->parent =& array_pop($parents);
+                }
+
+                if (!is_null($msg->parent)) {
+                    $parent =& $msg->parent;
+                    $parent->children[] =& $msg;
+                    while (!is_null($parent)) {
+                        $parent->desc += $msg->desc;
+                        $parent->time  = $time;
+                        $prev =& $parent;
+                        if ($parent !== $parent->parent) {
+                            $parent =& $parent->parent;
+                        } else {
+                            $parent =& $null;
+                        }
                     }
                 }
             }
+        } else {
+            $messages = array();
         }
         Banana::$protocole->updateSpool($messages);
         return true;