Fix mbox and feed to the new spool
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Sun, 28 Oct 2007 16:12:31 +0000 (16:12 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:53 +0000 (00:35 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@288 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/feed.inc.php
banana/mbox.inc.php
banana/spool.inc.php

index 32a3d40..5b6d3d7 100644 (file)
@@ -53,13 +53,13 @@ class BananaFeed
         if (!Banana::$spool || Banana::$spool->group != $this->group) {
             return false;
         }
-        if (!Banana::$spool->ids) {
+        if (empty(Banana::$spool->overview)) {
             $spool_indexes = array();
         } else {
-            $spool_indexes = Banana::$spool->ids;
+            $spool_indexes = array_keys(Banana::$spool->overview);
             sort($spool_indexes, SORT_NUMERIC);
             $spool_indexes = array_slice($spool_indexes, -Banana::$feed_size, Banana::$feed_size);
-        }    
+        }
         $feed_indexes  = array_keys($this->messages);
         $old = array_diff($feed_indexes, $spool_indexes);
         foreach ($old as $key) {
@@ -68,6 +68,9 @@ class BananaFeed
         $new = array_diff($spool_indexes, $feed_indexes);
         foreach ($new as $key) {
             $message =& Banana::$protocole->getMessage($key);
+            if (is_null($message)) {
+                return;
+            }
             $array = array();
             $array['author'] = $message->getAuthorName();
             $array['date']   = $message->getHeaderValue('Date');
index c0fb8ae..cb4faa2 100644 (file)
@@ -18,25 +18,25 @@ class BananaMBox implements BananaProtocoleInterface
 
     private $_lasterrno = 0;
     private $_lasterror = null;
-    
+
     public function __construct()
     {
         $this->debug = Banana::$debug_mbox;
     }
-    
+
     public function isValid()
     {
         return true;
         //!Banana::$group || $this->file;
     }
-    
+
     /** Indicate last error n°
      */
     public function lastErrNo()
     {
         return $this->_lasterrno;;
     }
-    
+
     /** Indicate last error text
      */
     public function lastError()
@@ -66,10 +66,10 @@ class BananaMBox implements BananaProtocoleInterface
     {
         $message = null;
         if (!is_numeric($id)) {
-            if (!Banana::$spool) { 
+            if (!Banana::$spool) {
                 return $message;
             }
-            $id = Banana::$spool->ids[$id];
+            $id = Banana::$spool->ids[$id]->id;
         }
         $options = array ('-m ' . $id);
         $this->getMBoxPosition($options, $id);
@@ -85,29 +85,31 @@ class BananaMBox implements BananaProtocoleInterface
         $messages =& $this->getRawMessage($id);
         if ($messages) {
             $messages = new BananaMessage($messages);
+        } else {
+            $messages = null;
         }
-        return $messages;    
+        return $messages;
     }
 
     /** Return the sources of the given message
      */
     public function getMessageSource($id)
-    { 
+    {
         $message =& $this->getRawMessage($id);
         if ($message) {
-            $message = implode("\n", $message); 
+            $message = implode("\n", $message);
         }
         return $message;
-    }   
+    }
 
     /** Compute the number of messages of the box
      */
     private function getCount()
     {
         $options = array();
-        if (@filesize($this->getFileName()) == Banana::$spool->storage['size']) { 
-            return max(Banana::$spool->ids) + 1; 
-        } 
+        if (@filesize($this->getFileName()) == @Banana::$spool->storage['size']) {
+            return max(array_keys(Banana::$spool->overview)) + 1;
+        }
         $this->getMBoxPosition($options);
         $val =& $this->callHelper('-c', $options);
         if (!$val) {
@@ -191,7 +193,7 @@ class BananaMBox implements BananaProtocoleInterface
             return array();
         }
         if (is_null($this->new_messages)) {
-            $this->getCount(); 
+            $this->getCount();
         }
         return range($this->count - $this->new_messages, $this->count - 1);
     }
@@ -235,7 +237,7 @@ class BananaMBox implements BananaProtocoleInterface
         foreach ($headers as $key=>$value) {
             if (!empty($value)) {
                 $hdrs .= "$key: $value\r\n";
-            }    
+            }
         }
         $body = $message->get(false);
         return mail($to, $subject, $body, $hdrs);
@@ -295,7 +297,7 @@ class BananaMBox implements BananaProtocoleInterface
 #######
 # MBox parser
 #######
-    
+
     /** Add the '-p' optioin for callHelper
      */
     private function getMBoxPosition(array &$options, $id = null)
@@ -304,12 +306,12 @@ class BananaMBox implements BananaProtocoleInterface
             if (!is_null($id) && isset(Banana::$spool->overview[$id])) {
                 $key = $id;
             } else {
-                $key = max(Banana::$spool->ids);
+                $key = max(array_keys(Banana::$spool->overview));
                 if (!is_null($id) && $key >= $id) {
                     return;
                 }
             }
-            if (isset(Banana::$spool->overview[$key]->storage['offset'])) { 
+            if (isset(Banana::$spool->overview[$key]->storage['offset'])) {
                 $options[] = '-p ' . $key . ':' . Banana::$spool->overview[$key]->storage['offset'];
             }
         }
index 11fd225..cdd1928 100644 (file)
@@ -52,9 +52,9 @@ class BananaSpoolHead
     public function __construct($id, array &$message)
     {
         $this->id         = $id;
-        $this->msgid      = $message['message-id'];
+        $this->msgid      = @$message['message-id'];
         $this->date       = $message['date'];
-        $this->subject    = $message['subject'];
+        $this->subject    = @$message['subject'];
         $this->from       = $message['from'];
         $this->color      = sprintf('#%06x', abs(crc32($this->from) % 0xffffff));
         $this->desc       = 1;
@@ -247,7 +247,7 @@ class BananaSpool
             $msg         =& $this->overview[$id];
             $parents     =& $this->getReferences($message);
             while (!empty($parents) && ($msg->parent === $msg || is_null($msg->parent))) {
-                $msg->parent =& array_pop($parents);
+                @$msg->parent =& array_pop($parents);
             }
 
             if (!is_null($msg->parent)) {