Merge a protocole independent version of spoolgen in Banana itself
[banana.git] / banana / banana.inc.php.in
index 2dcf55a..df1768b 100644 (file)
@@ -23,12 +23,14 @@ class Banana
                                     'subscribe' => array(),
                                     'autoup' => 1);
     static public $boxpattern;
+    static public $withtabs = true;
 
 ### Spool ###
     static public $spool_max     = 3000;
     static public $spool_tbefore = 5;
     static public $spool_tafter  = 5;
     static public $spool_tmax    = 50;
+    static public $spool_boxlist = true;
 
 ### Message processing ###
     static public $msgparse_headers = array('content-disposition', 'content-transfer-encoding',
@@ -43,6 +45,8 @@ class Banana
     static public $msgshow_mimeparts = array('multipart/report', 'multipart/mixed', 'text/html', 'text/plain', 'text/enriched', 'text', 'message');
     static public $msgshow_xface     = true;
     static public $msgshow_wrap      = 78;
+    static public $msgshow_externalimages = false;
+    static public $msgshow_withthread = true;
 
     /** Match an url
      * Should be included in a regexp delimited using /, !, , or @ (eg: "/$url_regexp/ui")
@@ -55,7 +59,7 @@ class Banana
      *   $matches[2] = "http://www.polytechnique.org"
      *   $matches[3] = "]"
      */
-    static public $msgshow_url  = '(["\[])?((?:[a-z]+:\/\/|www\.)(?:[\.\,\;\!]*[a-z\@0-9~%$£µ&i#\-+=_\/\?]+)+)(["\]])?';
+    static public $msgshow_url     = '(["\[])?((?:[a-z]+:\/\/|www\.)(?:[\.\,\;\!]*[a-z\@0-9~%$£µ&i#\-+=_\/\?]+)+)(["\]])?';
 
 ### Message edition ###
     static public $msgedit_canattach  = true;
@@ -284,9 +288,11 @@ class Banana
         if (!$this->loadSpool($group)) {
             return _b_('Impossible charger la liste des messages de ') . $group;
         }
-        $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true);
+        if (Banana::$spool_boxlist) {
+            $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true);
+            Banana::$page->assign('groups', $groups);
+        }
         Banana::$page->assign('msgbypage', Banana::$spool_tmax);
-        Banana::$page->assign('groups', $groups);
         return true;
     }
 
@@ -332,8 +338,10 @@ class Banana
         if (Banana::$profile['autoup']) {
             Banana::$spool->markAsRead($artid);
         }
-        $groups    = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true);
-        Banana::$page->assign('groups', $groups);
+        if (Banana::$spool_boxlist) {
+            $groups    = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true);
+            Banana::$page->assign('groups', $groups);
+        }    
         Banana::$page->assign_by_ref('message', $msg);
         Banana::$page->assign('headers', Banana::$msgshow_headers);
         return true;
@@ -429,8 +437,54 @@ class Banana
             $this->removeMessage($group, $artid);
             Banana::$page->redirect(Array('group' => $group, 'first' => $ndx));
         }
+
         Banana::$page->assign_by_ref('message', $msg);
+        Banana::$page->assign('body', $msg->getFormattedBody());
+        Banana::$page->assign('headers', Banana::$msgshow_headers);
+        return true;
+    }
+
+    /**************************************************************************/
+    /* Spoolgen functions                                                     */
+    /**************************************************************************/
+
+    private function checkErrors()
+    {
+        if (Banana::$protocole->lastErrno()) {
+            echo "\nL'erreur suivante s'est produite : "
+                . Banana::$protocole->lastErrno() . " "
+                . Banana::$protocole->lastError() . "\n";
+            return false;
+        }
         return true;
+    } 
+
+    static public function createAllSpool(array $protos)
+    {
+        foreach ($protos as $proto) {
+            $banana = new Banana(array(), $proto);
+
+            if (!$banana->checkErrors()) {
+                continue;
+            }
+            $groups = Banana::$protocole->getBoxList();
+            if (!$banana->checkErrors()) {
+                continue;
+            }
+
+            print "** $proto **\n";
+            foreach (array_keys($groups) as $g) {
+                print "Generating spool for $g : ";
+                Banana::$group = $g;
+                $spool = $banana->loadSpool($g);
+                if (!$banana->checkErrors()) {
+                    break;
+                }
+                print "done.\n";
+                unset($spool);
+            }
+            print "\n";
+        }
     }
 
     /**************************************************************************/
@@ -441,13 +495,20 @@ class Banana
     {
         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']);
             }
-            BananaSpool::getSpool($group, Banana::$profile['lastnews'], Banana::$profile['autoup']);
+            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'];
             }
             Banana::$spool->setMode(Banana::$profile['display'] ? Banana::SPOOL_UNREAD : Banana::SPOOL_ALL);
         }