Move spool file in $PROTO/$GROUP/spool instead of $PROTO/$GROUP
[banana.git] / banana / spool.inc.php
index 11fd225..3d44785 100644 (file)
@@ -9,7 +9,7 @@
 
 require_once dirname(__FILE__) . '/banana.inc.php';
 
-define('BANANA_SPOOL_VERSION', '0.5.12');
+define('BANANA_SPOOL_VERSION', '0.5.13');
 
 /** Class spoolhead
  *  class used in thread overviews
@@ -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;
@@ -127,23 +127,30 @@ class BananaSpool
             $spool->markAllAsRead();
         }
         $spool->updateUnread($since);
-        //var_dump($spool->trees);
         return $spool;
     }
 
-    private static function spoolFilename($group)
+    public static function getPath($file = null)
     {
-        $file = Banana::$spool_root . '/' . Banana::$protocole->name() . '/';
-        if (!is_dir($file)) {
-            mkdir($file);
+        $path = Banana::$spool_root . '/' . Banana::$protocole->name() . '/' . Banana::$protocole->filename();
+        if (!is_dir($path)) {
+            if (file_exists($path)) {
+                @unlink($path);
+            }
+            mkdir($path, 0777, true);
         }
-        return $file . Banana::$protocole->filename();
+        return $path . '/' . $file;
+    }
+
+    private static function spoolFilename()
+    {
+        return BananaSpool::getPath('spool');
     }
 
     private static function &readFromFile($group)
     {
         $spool = null;
-        $file = BananaSpool::spoolFilename($group);
+        $file = BananaSpool::spoolFilename();
         if (!file_exists($file)) {
             return $spool;
         }
@@ -163,7 +170,7 @@ class BananaSpool
 
     private function saveToFile()
     {
-        $file = BananaSpool::spoolFilename($this->group);
+        $file = BananaSpool::spoolFilename();
 
         $this->roots = Array();
         foreach($this->overview as &$msg) {
@@ -247,7 +254,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)) {