=?utf-8?q?*=20Principalement=20du=20nettoyage=20de=20code
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Thu, 2 Mar 2006 20:24:23 +0000 (20:24 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:34:35 +0000 (00:34 +0100)
=20*=20Am=C3=83=C2=A9lioration=20des=20filtres=20html?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@23 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/banana.inc.php.in
banana/misc.inc.php
banana/post.inc.php

index 80661eb..4bc8826 100644 (file)
@@ -25,9 +25,6 @@ class Banana
     /** Maximum allowed file size for attachment
      */
     var $maxfilesize = 100000;  
-    /** Indicate wether posting html messages is allowed
-     */
-    var $can_html    = false;
 
     /** Regexp for selecting newsgroups to show (if empty, match all newsgroups)
      * ex : '^xorg\..*' for xorg.*
@@ -42,16 +39,16 @@ class Banana
 
     /** Boundary for multipart messages
      */
-    var $boundary    = "bananaBoundary42";
-    /** Global headers to use for text/plain messages
+    var $boundary    = 'bananaBoundary42';
+    /** Global headers to use for messages
      */
-    var $custom      = "Content-Type: text/plain; charset=utf-8\nMime-Version: 1.0\nContent-Transfer-Encoding: 8bit\nUser-Agent: Banana @VERSION@\n";
+    var $custom      = "Mime-Version: 1.0\nUser-Agent: Banana @VERSION@\n";
     /** Global headers to use from multipart messages
      */
-    var $custom_mp   = "Content-Type: multipart/mixed; boundary=\"bananaBoundary42\"\nContent-Transfer-Encoding: 7bit\nUser-Agent: Banana @VERSION@\n";
-    /** Body part headers to use from multipart messages
+    var $custom_mp   = "Content-Type: multipart/mixed; boundary=\"bananaBoundary42\"\nContent-Transfer-Encoding: 7bit\n";
+    /** Body type when using plain text
      */
-    var $custom_bd   = "Content-Type: text/plain; charset=utf-8\nContent-Transfert-Encoding: 8bit";
+    var $custom_plain= "Content-Type: text/plain; charset=utf-8\nContent-Transfert-Encoding: 8bit\n"; 
 
     /** News serveur to use
      */
@@ -304,7 +301,7 @@ class Banana
         $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile['org'].'</td></tr>';
         $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
         $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
-            .to_entities($body).($this->profile['sig'] ? "\n\n-- \n".htmlentities($this->profile['sig']) : '').'</textarea></td></tr>';
+              .  to_entities($body).($this->profile['sig'] ? "\n\n-- \n".htmlentities($this->profile['sig']) : '').'</textarea></td></tr>';
        $html .= '<tr><th colspan="2">'._b_('Pièces jointes').'</th></tr>';
         $html .= '<tr><td colspan="2"><input type="hidden" name="MAX_FILE_SIZE" value="'.$this->maxfilesize.'" />';
         $html .= '<input type="file" name="newpj" size="40"/></td></tr>';
@@ -344,20 +341,20 @@ class Banana
             $msg .= "References: $refs{$post->headers['message-id']}\n";
         }
 
-        $body = wrap($body, "", $this->wrap);
+        $body_headers  = $this->custom_plain;
+        $body          = wrap($body, "", $this->wrap);
 
         // include attachment in the body
         $uploaded = $this->_upload('newpj');
         switch ($uploaded['error']) {
             case UPLOAD_ERR_OK:
-                $this->custom = $this->custom_mp;
-                $body    = "\n--".$this->boundary."\n".$this->custom_bd."\n\n".$body."\n--".$this->boundary."\n";
-
-                $body   .= 'Content-Type: '.$uploaded['type'].'; name="'.$uploaded['name']."\"\n";
-                $body   .= 'Content-Transfer-Encoding: '.$uploaded['encoding']."\n\n";
-                $body   .= 'Content-Disposition: attachment; filename="'.$uploaded['name']."\"\n";
-                $body   .= $uploaded['data'];
-                $body   .= '--'.$this->boundary.'--';
+                $this->custom = $this->custom_mp.$this->custom;
+                $body         = $this->_make_part($body_headers, $body);
+                $file_head    = 'Content-Type: '.$uploaded['type'].'; name="'.$uploaded['name']."\"\n"
+                              . 'Content-Transfer-Encoding: '.$uploaded['encoding']."\n"
+                              . 'Content-Disposition: attachment; filename="'.$uploaded['name']."\"\n";
+                $body        .= $this->_make_part($file_head, $uploaded['data']);
+                $body        .= "\n--".$this->boundary.'--';
                 break;
 
             case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE:
@@ -375,6 +372,9 @@ class Banana
             case UPLOAD_ERR_NO_TMP_DIR:
                 return '<p class="error">'._b_('Une erreur est survenue sur le serveur lors de l\'upload de ')
                         .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
+
+            default:
+                $this->custom = $body_headers.$this->custom;
         }
 
         // finalise and post the message
@@ -454,6 +454,11 @@ class Banana
 
         return $file;
     }
+
+    function _make_part($headers, $body)
+    {
+        return "\n--".$this->boundary."\n".$headers."\n".$body;
+    }
 }
 
 ?>
index 9b568d8..7520adf 100644 (file)
@@ -42,7 +42,7 @@ function textFormat_translate($format)
  */
 function removeEvilTags($source)
 {
-    $allowedTags = '<h1><b><i><a><ul><li><pre><hr><blockquote><img><br><font><p><small><big><sup><sub><code>';
+    $allowedTags = '<h1><b><i><a><ul><li><pre><hr><blockquote><img><br><font><p><small><big><sup><sub><code><em>';
     $source = strip_tags($source, $allowedTags);
     return preg_replace('/<(.*?)>/ie', "'<'.removeEvilAttributes('\\1').'>'", $source);
 }
@@ -63,8 +63,8 @@ function removeEvilAttributes($tagSource)
  */
 function htmlToPlainText($res)
 {
-    $res = trim(html_entity_decode(strip_tags($res, '<br>')));
-    $res = preg_replace("@<br[^>]>@i", "\n", $res);
+    $res = trim(html_entity_decode(strip_tags($res, '<br><p>')));
+    $res = preg_replace("@</?(br|p)[^>]*>@i", "\n", $res);
     if (!is_utf8($res)) {
         $res = utf8_encode($res);
     }   
index 237e907..d8ff6d0 100644 (file)
@@ -70,7 +70,7 @@ class BananaPost
             foreach ($matches as $match) {
                 $mime = trim(exec('echo '.escapeshellarg($match[1]).' | uudecode -o /dev/stdout | file -bi -'));
                 if ($mime != 'application/x-empty') {
-                    $this->body = str_replace($match[0], '', $this->body);
+                    $this->body = trim(str_replace($match[0], '', $this->body));
                     $body = $match[1];
                     $header['content-type'] = $mime.'; name="'.$match[2].'"';
                     $header['content-transfer-encoding'] = 'x-uuencode';