Reduce mbox-helper overhead and fix some bugs
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Fri, 4 May 2007 21:11:36 +0000 (21:11 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:39 +0000 (00:35 +0100)
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@243 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/mbox.inc.php
banana/spool.inc.php
mbox-helper/mbox-helper.c

index 4f5e0bf..01c329e 100644 (file)
@@ -105,6 +105,9 @@ class BananaMBox implements BananaProtocoleInterface
     private function getCount()
     {
         $options = array();
+        if (@filesize($this->getFileName()) == Banana::$spool->storage['size']) { 
+            return max(Banana::$spool->ids); 
+        } 
         $this->getMBoxPosition($options);
         $val =& $this->callHelper('-c', $options);
         if (!$val) {
@@ -153,20 +156,12 @@ class BananaMBox implements BananaProtocoleInterface
                     break;
                 }
                 $hval  = array_shift($lines);
-                if ($hval === '') {
-                    break;
-                }
                 if ($hname == 'date') {
                     $headers[$id][$hname] = @strtotime($hval);
                 } else {
                     $headers[$id][$hname] = $hval;
                 }
             }
-            if (!isset($headers[$id]['date'])) {
-                print_r($id);
-                print_r($offset);
-                print_r($headers[$id]);
-            }
         }
         array_walk_recursive($headers, array('BananaMimePart', 'decodeHeader'));
         return $headers;
@@ -181,6 +176,7 @@ class BananaMBox implements BananaProtocoleInterface
                 Banana::$spool->overview[$id]->storage['offset'] = $data['beginning'];
             }
         }
+        Banana::$spool->storage['size'] = @filesize($this->getFileName());
     }
 
     /** Return the indexes of the new messages since the give date
@@ -300,13 +296,13 @@ class BananaMBox implements BananaProtocoleInterface
     
     /** Add the '-p' optioin for callHelper
      */
-    private function getMBoxPosition(array &$option, $id = null)
+    private function getMBoxPosition(array &$options, $id = null)
     {
         if (Banana::$spool->overview) {
-            if (!is_null($id) && Banana::$spool->overview[$id]) {
+            if (!is_null($id) && isset(Banana::$spool->overview[$id])) {
                 $key = $id;
             } else {
-                $key       = max(array_keys(Banana::$spool->overview));
+                $key = max(Banana::$spool->ids);
                 if (!is_null($id) && $key >= $id) {
                     return;
                 }
index 8deff17..7a48339 100644 (file)
@@ -9,7 +9,7 @@
 
 require_once dirname(__FILE__) . '/banana.inc.php';
 
-define('BANANA_SPOOL_VERSION', '0.4');
+define('BANANA_SPOOL_VERSION', '0.5');
 
 /** Class spoolhead
  *  class used in thread overviews
@@ -71,6 +71,8 @@ class BananaSpool
     public $ids;
     /** thread starts */
     public $roots;
+    /** protocole specific data */
+    public $storage = array();
 
     private $unreadnb = 0;
 
index 746f6ca..390d645 100644 (file)
@@ -396,7 +396,7 @@ int main(int argc, char *argv[])
 
     mbox = openMBox(filename);
     if (!mbox) {
-        fprintf(stderr, "can't open file '%s'", filename);
+        fprintf(stderr, "can't open file '%s'\n", filename);
         return 1;
     }
     if ((fmid >= pmid || fmid == -1) && pos) {
@@ -410,7 +410,7 @@ int main(int argc, char *argv[])
     switch (action) {
       case 'b':
         if (fmid == -1) {
-            fprintf(stderr, "you have to define a message number");
+            fprintf(stderr, "you have to define a message number\n");
             break;
         }
         goToMessage(mbox, fmid);
@@ -424,7 +424,7 @@ int main(int argc, char *argv[])
         break;
       case 'd':
         if (fmid == -1) {
-             fprintf(stderr, "you have to define a message number");
+             fprintf(stderr, "you have to define a message number\n");
              break;
         }
         for (i = fmid ; i <= lmid ; i++) {