UTF-8...
[banana.git] / banana / banana.inc.php.in
index 2dcf55a..8e9d3a7 100644 (file)
@@ -7,6 +7,8 @@
 * Copyright: See COPYING files that comes with this distribution
 ********************************************************************************/
 
+require_once dirname(__FILE__) . '/text.func.inc.php';
+
 class Banana
 {
 
@@ -19,16 +21,20 @@ class Banana
                                     'headers' => array('From' => 'Anonymous <anonymouse@example.com>'),
                                     'display' => 0,
                                     'lastnews' => 0,
-                                    'locale'  => 'fr_FR',
+                                    'locale'  => 'fr_FR.UTF-8',
                                     'subscribe' => array(),
                                     'autoup' => 1);
     static public $boxpattern;
+    static public $withtabs = true;
+    static public $mimeparts = array();
 
 ### Spool ###
+    static public $spool_root    = '/var/spool/banana';
     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',
@@ -40,9 +46,13 @@ class Banana
 ### Message display ###
     static public $msgshow_headers   = array('from', 'newsgroups', 'followup-to', 'to', 'cc', 'reply-to',
                                        'organization', 'date', 'references', 'in-reply-to');
-    static public $msgshow_mimeparts = array('multipart/report', 'multipart/mixed', 'text/html', 'text/plain', 'text/enriched', 'text', 'message');
+    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_hasextimages   = false;
+    static public $msgshow_withthread = true;
 
     /** Match an url
      * Should be included in a regexp delimited using /, !, , or @ (eg: "/$url_regexp/ui")
@@ -55,7 +65,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;
@@ -91,6 +101,7 @@ class Banana
     const ACTION_MSG_READ   = 5;
     const ACTION_MSG_NEW    = 9;
     const ACTION_MSG_CANCEL = 17;
+    const ACTION_MSG_IMAGES = 33;
 
     // Box list view
     const BOXES_ALL = 0;
@@ -132,7 +143,6 @@ class Banana
      */
     public function __construct($params = null, $protocole = 'NNTP', $pageclass = 'BananaPage')
     {
-        Banana::load('text.func');
         if (is_null($params)) {
             $this->params = $_GET;
         } else {
@@ -152,6 +162,16 @@ class Banana
             Banana::load('page');
         }
         Banana::$page = new $pageclass;
+        $types = array('multipart/report' => _b_('Rapport d\'erreur'),
+                       'multipart/mixed'  => _b_('Composition'),
+                       'text/html'        => _b_('Texte formaté'),
+                       'text/plain'       => _b_('Texte brut'),
+                       'text/enriched'    => _b_('Texte enrichi'),
+                       'text'             => _b_('Texte'),
+                       'message/rfc822'   => _b_('Mail'),
+                       'message'          => _b_('Message'),
+                       'source'           => _b_('Source'));
+        Banana::$mimeparts = array_merge($types, Banana::$mimeparts);
     }
 
     /** Fill state vars (Banana::$group, Banana::$artid, Banana::$action, Banana;:$part, Banana::$first)
@@ -188,6 +208,9 @@ class Banana
           case 'cancel':
             Banana::$action = Banana::ACTION_MSG_CANCEL;
             return;
+          case 'showext':
+            Banana::$action = Banana::ACTION_MSG_IMAGES;
+            return;
           default:
             Banana::$action = Banana::ACTION_MSG_READ;
         }
@@ -227,6 +250,8 @@ class Banana
           case Banana::ACTION_MSG_LIST:
             $error = $this->action_showThread(Banana::$group, Banana::$first);
             break;
+          case Banana::ACTION_MSG_IMAGES:
+            Banana::$msgshow_externalimages = true;
           case Banana::ACTION_MSG_READ:
             $error = $this->action_showMessage(Banana::$group, Banana::$artid, Banana::$part);
             break;
@@ -247,6 +272,13 @@ class Banana
         return Banana::$page->run();
     }
 
+    /** Return the CSS code to include in the headers
+     */
+    public function css()
+    {
+        return Banana::$page->css;
+    }
+
     /**************************************************************************/
     /* actions                                                                */
     /**************************************************************************/
@@ -272,9 +304,11 @@ class Banana
     {
         Banana::$page->setPage('forums');
         $groups    = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true);
-        $newgroups = Banana::$protocole->getBoxList(Banana::BOXES_NEW, Banana::$profile['lastnews'], true);
         Banana::$page->assign('groups', $groups);
-        Banana::$page->assign('newgroups', $newgroups);
+        if (empty(Banana::$profile['subscribe']) || Banana::$profile['lastnews']) {
+            $newgroups = Banana::$protocole->getBoxList(Banana::BOXES_NEW, Banana::$profile['lastnews'], true);
+            Banana::$page->assign('newgroups', $newgroups);
+        }
         return true;
     }
 
@@ -284,9 +318,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;
     }
 
@@ -318,7 +354,8 @@ class Banana
             }
             exit;
         } elseif ($partid == 'text') {
-            Banana::$page->assign('body', $msg->getFormattedBody());
+            $partid = null;
+            Banana::$page->assign('body', $msg->getFormattedBody($partid));
         } elseif ($partid == 'source') {
             $text = Banana::$protocole->getMessageSource($artid);
             if (!is_utf8($text)) {
@@ -332,10 +369,14 @@ 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('extimages', Banana::$msgshow_hasextimages);
         Banana::$page->assign('headers', Banana::$msgshow_headers);
+        Banana::$page->assign('type', $partid);
         return true;
     }
 
@@ -429,8 +470,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,14 +528,14 @@ class Banana
     {
         Banana::load('spool');
         if (!Banana::$spool || Banana::$spool->group != $group) {
-            if ($group == @$_SESSION['banana_group'] && isset($_SESSION['banana_spool'])) {
-                Banana::$spool = unserialize($_SESSION['banana_spool']);
+            $clean = false;
+            if ($group != @$_SESSION['banana_group']) {
+                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);
-            }
             Banana::$spool->setMode(Banana::$profile['display'] ? Banana::SPOOL_UNREAD : Banana::SPOOL_ALL);
         }
         return true;
@@ -475,15 +562,10 @@ class Banana
     protected function removeMessage($group, $artid)
     {
         Banana::$spool->delId($artid);
-        if ($group == $_SESSION['banana_group']) {
-            if (!Banana::$profile['display']) {
-                $_SESSION['banana_spool'] = serialize(Banana::$spool);
-            }    
-            if ($artid == $_SESSION['banana_artid']) {
-                unset($_SESSION['banana_message']);
-                unset($_SESSION['banana_showhdr']);
-                unset($_SESSION['banana_artid']);
-            }
+        if ($group == $_SESSION['banana_group'] && $artid == $_SESSION['banana_artid']) {
+            unset($_SESSION['banana_message']);
+            unset($_SESSION['banana_showhdr']);
+            unset($_SESSION['banana_artid']);
         }
         return true;
     }