+ private static function &readFromFile($group)
+ {
+ $spool = null;
+ $file = BananaSpool::spoolFilename();
+ if (!file_exists($file)) {
+ return $spool;
+ }
+ $spool = unserialize(file_get_contents($file));
+ if ($spool->version != BANANA_SPOOL_VERSION || $spool->mode != Banana::SPOOL_ALL) {
+ $spool = null;
+ return $spool;
+ }
+ $spool->markAllAsRead();
+ return $spool;
+ }
+
+ private function compare($a, $b)
+ {
+ return ($b->date - $a->date);
+ }
+
+ private function saveToFile()
+ {
+ $file = BananaSpool::spoolFilename();
+
+ $this->roots = Array();
+ foreach($this->overview as &$msg) {
+ if (is_null($msg->parent)) {
+ $this->roots[] =& $msg;
+ }
+ }
+ usort($this->roots, array($this, 'compare'));
+
+ if ($this->mode == Banana::SPOOL_ALL) {
+ file_put_contents($file, serialize($this));
+ }
+ }
+
+ private function build()
+ {
+ $threshold = 0;
+
+ // Compute the range of indexes
+ list($msgnum, $first, $last) = Banana::$protocole->getIndexes();
+ if ($last < $first) {
+ $threshold = $first + $msgnum - $last;
+ $threshold = (int)(log($threshold)/log(2));
+ $threshold = (2 ^ ($threshold + 1)) - 1;
+ }
+ if (Banana::$spool_max && Banana::$spool_max < $msgnum) {
+ $first = $last - Banana::$spool_max;
+ if ($first < 0) {
+ $first += $threshold;
+ }
+ }
+ $clean = $this->clean($first, $last, $msgnum);
+ $update = $this->update($first, $last, $msgnum);
+
+ if ($clean || $update) {
+ $this->saveToFile();
+ }
+ }