From 797579f4e251bdaabe7e0e8d0b3b57ee40ae111f Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Sat, 1 Oct 2011 17:40:19 +0200 Subject: [PATCH] Prevents error on newsgroup without any message. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- banana/mbox.inc.php | 5 ++++- banana/spool.inc.php | 62 ++++++++++++++++++++++++++++------------------------ 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/banana/mbox.inc.php b/banana/mbox.inc.php index f48c877..3483cec 100644 --- a/banana/mbox.inc.php +++ b/banana/mbox.inc.php @@ -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); diff --git a/banana/spool.inc.php b/banana/spool.inc.php index ace19f7..e0a144a 100644 --- a/banana/spool.inc.php +++ b/banana/spool.inc.php @@ -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; -- 2.1.4