X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=banana%2Fmbox.inc.php;h=1f158c904c5ae90e3290474345fcdf51965b029b;hb=6ec8703c9a26dc36334478488789433b00c471d7;hp=01c329ebd7d34d93f81f2639c67ee5a996ec0c86;hpb=dc5f77ad837f38a80e02699b97a4d7947f2f7f70;p=banana.git diff --git a/banana/mbox.inc.php b/banana/mbox.inc.php index 01c329e..1f158c9 100644 --- a/banana/mbox.inc.php +++ b/banana/mbox.inc.php @@ -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); - } + 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) { @@ -139,31 +141,33 @@ class BananaMBox implements BananaProtocoleInterface return $headers; } $headers = array(); - while ($lines) { - $id = array_shift($lines); - if ($id === '') { - continue; - } - $offset = array_shift($lines); - if ($offset === '') { - continue; - } - $id = intval($id); - $headers[$id] = array('beginning' => intval($offset)); - while (true) { - $hname = array_shift($lines); - if ($hname === '') { - break; - } - $hval = array_shift($lines); - if ($hname == 'date') { - $headers[$id][$hname] = @strtotime($hval); - } else { - $headers[$id][$hname] = $hval; + $in_message = false; + $get_pos = true; + $hname = null; + foreach ($lines as $key=>&$line) { + if (!$in_message) { + if (!empty($line)) { + $id = intval($line); + $in_message = true; + $get_pos = true; } + } elseif ($get_pos) { + $headers[$id] = array('beginning' => intval($line)); + $get_pos = false; + } elseif (empty($line) && empty($hname)) { + $in_message = false; + } elseif (empty($hname)) { + $hname = $line; + } elseif ($hname == 'date') { + $headers[$id][$hname] = @strtotime($line); + $hname = null; + } else { + BananaMimePart::decodeHeader($line, $hname); + $headers[$id][$hname] = $line; + $hname = null; } + unset($lines[$key]); } - array_walk_recursive($headers, array('BananaMimePart', 'decodeHeader')); return $headers; } @@ -189,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); } @@ -233,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); @@ -293,21 +297,21 @@ class BananaMBox implements BananaProtocoleInterface ####### # MBox parser ####### - + /** Add the '-p' optioin for callHelper */ private function getMBoxPosition(array &$options, $id = null) { - if (Banana::$spool->overview) { + if (Banana::$spool && Banana::$spool->overview) { 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']; } }