Limit the size of the images in multipart/mixed view (on browsers which supports...
[banana.git] / banana / banana.inc.php.in
index 3313966..e260626 100644 (file)
@@ -29,6 +29,7 @@ class Banana
     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,12 +41,12 @@ 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('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;
 
     /** Match an url
-     * Should be included in a regexp delimited using /, !, , or @ (eg: "/$url_regexp/i")
+     * Should be included in a regexp delimited using /, !, , or @ (eg: "/$url_regexp/ui")
      * If it matches, return 3 main parts :
      *  \\1 and \\3 are delimiters
      *  \\2 is the url
@@ -55,7 +56,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;
@@ -63,7 +64,10 @@ class Banana
     /** Global headers to use for messages
      */
     static public $msgedit_headers  = array('Mime-Version' => '1.0', 'User-Agent' => 'Banana @VERSION@');
-    
+    /** Mime type order for quoting
+     */
+    static public $msgedit_mimeparts = array('multipart/report', 'multipart/mixed', 'text/plain', 'text/enriched', 'text/html', 'text', 'message');
+
 ### Protocole ###
     /** News serveur to use
      */
@@ -200,7 +204,7 @@ class Banana
         
         // Check if the state is valid
         if (Banana::$protocole->lastErrNo()) {
-            return Banana::$page->kill(_b_('Une erreur a été rencontrée lors de la connexion au serveur') . '<br />'
+            return Banana::$page->kill(_b_('Une erreur a été rencontrée lors de la connexion au serveur') . '<br />'
                                       . Banana::$protocole->lastError());
         }
         if (!Banana::$protocole->isValid()) {
@@ -209,7 +213,7 @@ class Banana
         if (Banana::$action & Banana::ACTION_BOX_NEEDED) {
             if(Banana::$boxpattern && !preg_match('/' . Banana::$boxpattern . '/i', $group)) {
                 Banana::$page->setPage('group');        
-                return Banana::$page->kill(_b_("Ce newsgroup n'existe pas ou vous n'avez pas l'autorisation d'y accéder"));
+                return Banana::$page->kill(_b_("Ce newsgroup n'existe pas ou vous n'avez pas l'autorisation d'y accéder"));
             }
         }
 
@@ -234,7 +238,7 @@ class Banana
             $error = $this->action_cancelMessage(Banana::$group, Banana::$artid);
             break;
           default:
-            $error = _b_("L'action demandée n'est pas supportée par Banana");
+            $error = _b_("L'action demandée n'est pas supportée par Banana");
         }
 
         // Generate the page
@@ -281,9 +285,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;
     }
 
@@ -291,7 +297,7 @@ class Banana
     {
         Banana::$page->setPage('message');
         $istext = $partid == 'text' || $partid == 'source'
-            || preg_match("/[-a-z0-9_]+\/[-a-z0-9_]+/", $partid);
+                || preg_match('!^[-a-z0-9_]+/[-a-z0-9_]+$!', $partid);
         if ($istext) {
             $this->loadSpool($group);
         }
@@ -299,7 +305,7 @@ class Banana
         if (is_null($msg)) {
             $this->loadSpool($group);
             $this->removeMessage($group, $artid);
-            return _b_('Le message demandé n\'existe pas. Il est possible qu\'il ait été annulé');
+            return _b_('Le message demandé n\'existe pas. Il est possible qu\'il ait été annulé');
         }
         if ($partid == 'xface') {
             $msg->getXFace();
@@ -317,8 +323,11 @@ class Banana
         } elseif ($partid == 'text') {
             Banana::$page->assign('body', $msg->getFormattedBody());
         } elseif ($partid == 'source') {
-            Banana::$page->assign('body',
-                                  '<pre>' . banana_htmlentities(Banana::$protocole->getMessageSource($artid)) . '</pre>');
+            $text = Banana::$protocole->getMessageSource($artid);
+            if (!is_utf8($text)) {
+                $text = utf8_encode($text);
+            }
+            Banana::$page->assign('body', '<pre>' . banana_htmlentities($text) . '</pre>');
         } else {
             Banana::$page->assign('body', $msg->getFormattedBody($partid));
         }
@@ -326,8 +335,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;
@@ -362,7 +373,7 @@ class Banana
             } elseif (Banana::$msgedit_canattach && isset($_FILES['attachment'])) {
                 $uploaded = $_FILES['attachment'];
                 if (!is_uploaded_file($uploaded['tmp_name'])) {
-                    Banana::$page->trig(_b_('Une erreur est survenue lors du téléchargement du fichier'));
+                    Banana::$page->trig(_b_('Une erreur est survenue lors du téléchargement du fichier'));
                 } else {
                     $msg = BananaMessage::newMessage($hdr_values, $_POST['body'], $uploaded);
                 }
@@ -379,7 +390,7 @@ class Banana
         } else {
             if (!is_null($artid)) {
                 $msg    =& $this->loadMessage($group, $artid);
-                $body    = $msg->getSender() . _b_(' a écrit :') . "\n" . $msg->quote();
+                $body    = $msg->getSender() . _b_(' a écrit :') . "\n" . $msg->quote();
                 $subject = $msg->getHeaderValue('subject');
                 $headers['Subject']['user'] = 'Re: ' . preg_replace("/^re\s*:\s*/i", '', $subject);
                 $target  = $msg->getHeaderValue($hdrs['reply']);
@@ -423,7 +434,10 @@ 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;
     }
 
@@ -435,13 +449,16 @@ 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']);
             }
-            BananaSpool::getSpool($group, Banana::$profile['lastnews']);
+            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);
         }
@@ -491,5 +508,5 @@ class Banana
     }
 }
 
-// vim:set et sw=4 sts=4 ts=4
+// vim:set et sw=4 sts=4 ts=4 enc=utf-8:
 ?>