From: Stéphane Jacob Date: Sat, 1 Oct 2011 15:40:19 +0000 (+0200) Subject: Prevents error on newsgroup without any message. X-Git-Url: http://git.polytechnique.org/?p=banana.git;a=commitdiff_plain;h=797579f4e251bdaabe7e0e8d0b3b57ee40ae111f Prevents error on newsgroup without any message. Signed-off-by: Stéphane Jacob --- 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;