- /** Go to the given message
- */
- private function goTo($id)
- {
- if ($this->current_id == $id && $this->at_beginning) {
- return true;
- }
- if ($id == 0) {
- fseek($this->file, 0);
- $this->current_id = 0;
- $this->at_beginning = true;
- return true;
- } elseif (isset(Banana::$spool->overview[$id]) || isset($this->messages[$id])) {
- if (isset(Banana::$spool->overview[$id])) {
- $pos = Banana::$spool->overview[$id]->storage['offset'];
- } else {
- $pos = $this->messages[$id]['beginning'];
- }
- if (fseek($this->file, $pos) == 0) {
- $this->current_id = $id;
- $this->at_beginning = true;
- return true;
- } else {
- $this->current_id = null;
- $this->_lasterrno = 2;
- $this->_lasterror = _b_('Can\'t find message ') . $id;
- return false;
- }
- } else {
- $max = @max(array_keys(Banana::$spool->overview));
- if (is_null($max)) {
- $max = 0;
- }
- if ($id <= $max && $max != 0) {
- $this->current_id = null;
- $this->_lasterrno = 3;
- $this->_lasterror = _b_('Invalid message index ') . $id;
- return false;
- }
- if (!$this->goTo($max)) {
- return false;
- }
- if (feof($this->file)) {
- $this->current_id = null;
- $this->_lasterrno = 4;
- $this->_lasterror = _b_('Requested index does not exists or file has been truncated');
- return false;
- }
- while ($this->readCurrentMessage(true) && $this->current_id < $id);
- if ($this->current_id == $id) {
- return true;
- }
- $this->current_id = null;
- $this->_lasterrno = 5;
- $this->_lasterror = _b_('Requested index does not exists or file has been truncated');
- return false;
- }
- }
-
- private function countMessages($from = 0)
- {
- $this->messages =& $this->readMessages(array($from), true, true);
- return count($this->messages);
- }
-
- /** Read the current message (identified by current_id)
- * @param needFrom_ BOOLEAN is true if the first line *must* be a From_ line
- * @param alignNext BOOLEAN is true if the buffer must be aligned at the beginning of the next From_ line
- * @return message sources (without storage data)
- */
- private function &readCurrentMessage($stripBody = false, $needFrom_ = true, $alignNext = true)