Banana::load('spool');
if (!Banana::$spool || Banana::$spool->group != $group) {
$clean = false;
- if ($group == @$_SESSION['banana_group'] && isset($_SESSION['banana_spool'])) {
- Banana::$spool = unserialize($_SESSION['banana_spool']);
- $clean = @(Banana::$profile['lastnews'] != $_SESSION['banana_lastnews']);
- } else {
- unset($_SESSION['banana_message']);
- unset($_SESSION['banana_artid']);
- unset($_SESSION['banana_showhdr']);
+ if (php_sapi_name() != 'cli') {
+ if ($group == @$_SESSION['banana_group'] && isset($_SESSION['banana_spool'])) {
+ Banana::$spool = unserialize($_SESSION['banana_spool']);
+ $clean = @(Banana::$profile['lastnews'] != $_SESSION['banana_lastnews']);
+ } else {
+ unset($_SESSION['banana_message']);
+ unset($_SESSION['banana_artid']);
+ unset($_SESSION['banana_showhdr']);
+ }
}
BananaSpool::getSpool($group, Banana::$profile['lastnews'], Banana::$profile['autoup'] || $clean);
- $_SESSION['banana_group'] = $group;
- if (!Banana::$profile['display']) {
- $_SESSION['banana_spool'] = serialize(Banana::$spool);
- $_SESSION['banana_lastnews'] = Banana::$profile['lastnews'];
+ if (php_sapi_name() != 'cli') {
+ $_SESSION['banana_group'] = $group;
+ if (!Banana::$profile['display']) {
+ $_SESSION['banana_spool'] = serialize(Banana::$spool);
+ $_SESSION['banana_lastnews'] = Banana::$profile['lastnews'];
+ }
}
Banana::$spool->setMode(Banana::$profile['display'] ? Banana::SPOOL_UNREAD : Banana::SPOOL_ALL);
}
{
$options = array();
if (@filesize($this->getFileName()) == Banana::$spool->storage['size']) {
- return max(Banana::$spool->ids);
+ return max(Banana::$spool->ids) + 1;
}
$this->getMBoxPosition($options);
$val =& $this->callHelper('-c', $options);
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;
}
static public function formatReferences(array &$refs)
{
if (isset($refs['references'])) {
- $text = str_replace('><', '> <', $refs['references']);
- return preg_split('/\s/', strtr($text, Banana::$spool->ids));
+ $text = preg_split('/\s/', str_replace('><', '> <', $refs['references']));
+ foreach ($text as $id=>&$value) {
+ if (isset(Banana::$spool->ids[$value])) {
+ $value = Banana::$spool->ids[$value];
+ } else {
+ unset($text[$id]);
+ }
+ }
+ return $text;
} elseif (isset($refs['in-reply-to']) && isset(Banana::$spool->ids[$refs['in-reply-to']])) {
return array(Banana::$spool->ids[$refs['in-reply-to']]);
} else {
if (!is_utf8($val)) {
$val = utf8_encode($val);
}
- } else {
+ } elseif (strpos($val, '=') !== false) {
$val = preg_replace('/(=\?.*?\?[bq]\?.*?\?=) (=\?.*?\?[bq]\?.*?\?=)/i', '\1\2', $val);
$val = preg_replace('/=\?(.*?)\?([bq])\?(.*?)\?=/ie', 'BananaMimePart::_decodeHeader("\1", "\2", "\3")', $val);
- }
+ }
}
static public function &parseHeaders(array &$lines)
$messages = array();
foreach ($msg_headers as $header) {
$headers = $this->xhdr($header, $firstid, $lastid);
- array_walk($headers, array('BananaMimePart', 'decodeHeader'));
$header = strtolower($header);
if ($header == 'date') {
$headers = array_map('strtotime', $headers);
+ } else {
+ array_walk($headers, array('BananaMimePart', 'decodeHeader'));
}
foreach ($headers as $id=>&$value) {
if (!isset($messages[$id])) {
private function compare($a, $b)
{
- return ($b->date >= $a->date);
+ return ($this->overview[$b]->date >= $this->overview[$a]->date);
}
private function saveToFile()
{
$file = BananaSpool::spoolFilename($this->group);
- uasort($this->overview, array($this, 'compare'));
$this->roots = Array();
- foreach($this->overview as $id=>$msg) {
+ foreach($this->overview as $id=>&$msg) {
if (is_null($msg->parent)) {
$this->roots[] = $id;
}
}
+ usort($this->roots, array($this, 'compare'));
if ($this->mode == Banana::SPOOL_ALL) {
file_put_contents($file, serialize($this));