From dc5f77ad837f38a80e02699b97a4d7947f2f7f70 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Fri, 4 May 2007 21:11:36 +0000 Subject: [PATCH] Reduce mbox-helper overhead and fix some bugs git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@243 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- banana/mbox.inc.php | 18 +++++++----------- banana/spool.inc.php | 4 +++- mbox-helper/mbox-helper.c | 6 +++--- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/banana/mbox.inc.php b/banana/mbox.inc.php index 4f5e0bf..01c329e 100644 --- a/banana/mbox.inc.php +++ b/banana/mbox.inc.php @@ -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; } diff --git a/banana/spool.inc.php b/banana/spool.inc.php index 8deff17..7a48339 100644 --- a/banana/spool.inc.php +++ b/banana/spool.inc.php @@ -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; diff --git a/mbox-helper/mbox-helper.c b/mbox-helper/mbox-helper.c index 746f6ca..390d645 100644 --- a/mbox-helper/mbox-helper.c +++ b/mbox-helper/mbox-helper.c @@ -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++) { -- 2.1.4