X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=banana%2Fmbox.inc.php;h=01c329ebd7d34d93f81f2639c67ee5a996ec0c86;hb=dc5f77ad837f38a80e02699b97a4d7947f2f7f70;hp=db3a1fdff76e24c52bcba18a5a40772d674a78e6;hpb=6a684b9ba469c52928dbc05725e51e1d88508c26;p=banana.git diff --git a/banana/mbox.inc.php b/banana/mbox.inc.php index db3a1fd..01c329e 100644 --- a/banana/mbox.inc.php +++ b/banana/mbox.inc.php @@ -72,16 +72,7 @@ class BananaMBox implements BananaProtocoleInterface $id = Banana::$spool->ids[$id]; } $options = array ('-m ' . $id); - if (Banana::$spool->overview) { - if (Banana::$spool->overview[$id]) { - $options[] = '-p ' . $id . ':' . Banana::$spool->overview[$id]->storage['offset']; - } else { - $key = max(array_keys(Banana::$spool->overview)); - if ($key < $id) { - $options[] = '-p ' . $key . ':' . Banana::$spool->overview[$key]->storage['offset']; - } - } - } + $this->getMBoxPosition($options, $id); return $this->callHelper('-b', $options); } @@ -114,10 +105,10 @@ class BananaMBox implements BananaProtocoleInterface private function getCount() { $options = array(); - if (Banana::$spool->overview) { - $key = max(array_keys(Banana::$spool->overview)); - $options[] = '-p ' . $key . ':' . Banana::$spool->overview[$key]->storage['offset']; - } + if (@filesize($this->getFileName()) == Banana::$spool->storage['size']) { + return max(Banana::$spool->ids); + } + $this->getMBoxPosition($options); $val =& $this->callHelper('-c', $options); if (!$val) { return 0; @@ -142,16 +133,7 @@ class BananaMBox implements BananaProtocoleInterface $headers = null; $options = array(); $options[] = "-m $firstid:$lastid"; - if (Banana::$spool->overview) { - if (isset(Banana::$spool->overview[$firstid])) { - $options[] = '-p ' . $firstid . ':' . Banana::$spool->overview[$firstid]->storage['offset']; - } else { - $key = max(array_keys(Banana::$spool->overview)); - if ($key < $firstid) { - $options[] = '-p ' . $key . ':' . Banana::$spool->overview[$key]->storage['offset']; - } - } - } + $this->getMboxPosition($options, $firstid); $lines =& $this->callHelper('-d', $options, $msg_headers); if (!$lines) { return $headers; @@ -174,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; @@ -202,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 @@ -318,6 +293,25 @@ class BananaMBox implements BananaProtocoleInterface ####### # MBox parser ####### + + /** Add the '-p' optioin for callHelper + */ + private function getMBoxPosition(array &$options, $id = null) + { + if (Banana::$spool->overview) { + if (!is_null($id) && isset(Banana::$spool->overview[$id])) { + $key = $id; + } else { + $key = max(Banana::$spool->ids); + if (!is_null($id) && $key >= $id) { + return; + } + } + if (isset(Banana::$spool->overview[$key]->storage['offset'])) { + $options[] = '-p ' . $key . ':' . Banana::$spool->overview[$key]->storage['offset']; + } + } + } private function &callHelper($action, array $options = array(), array $headers = array()) { @@ -329,7 +323,7 @@ class BananaMBox implements BananaProtocoleInterface exec($cmd, $out, $return); if ($this->debug) { $this->bt[] = array('action' => $cmd, 'time' => (microtime(true) - $start), - 'code' => $return, 'response' => count($out)); + 'code' => $return, 'response' => count($out), 'error' => $return ? "Helper failed" : null); } if ($return != 0) { $this->_lasterrorno = 1;