Fix infinite loop if quotation reach last line of the post
[banana.git] / banana / post.inc.php
index 9f3dc59..1da8783 100644 (file)
@@ -58,8 +58,10 @@ class BananaPost
 
         if ($this->_split_multipart($this->headers, $this->body)) {
             $this->set_body_to_part(0);
-        } elseif(isset($mpart_type)) {
-            $this->_split_multipart($mpart_type[1], $mpart_boundary[1]);
+        } else {
+            if(isset($mpart_type)) {
+                $this->_split_multipart($mpart_type[1], $mpart_boundary[1]);
+            }
             $this->_find_uuencode();
             $this->_fix_charset();
         }
@@ -207,7 +209,8 @@ class BananaPost
      */
     function _fix_charset()
     {
-        if (preg_match('!charset="?([^;"]*)"?\s*(;|$)?!', $this->headers['content-type'], $matches)) {
+        if (isset($this->headers['content-type'])
+                && preg_match('!charset="?([^;"]*)"?\s*(;|$)?!', $this->headers['content-type'], $matches)) {
             $body = iconv($matches[1], 'utf-8', $this->body);
             if (strlen($body) == 0) {
                 return false;
@@ -412,14 +415,15 @@ class BananaPost
              . makeImgLink(Array('group'  => $banana->state['group'],
                                  'action' => 'new'),
                            'post.gif',
-                           _b_('Nouveau message'))
+                           _b_('Nouveau message')) . ' '
              . makeImgLink(Array('group'  => $banana->state['group'],
                                  'artid'  => $this->id,
                                  'action' => 'new'),
                            'reply.gif',
                            _b_('RĂ©pondre'));
         if ($this->checkCancel()) {
-            $res .= makeImgLink(Array('group'  => $banana->state['group'],
+            $res .= ' '
+                  . makeImgLink(Array('group'  => $banana->state['group'],
                                       'artid'  => $this->id,
                                       'action' => 'cancel'),
                                 'cancel.gif',
@@ -468,8 +472,12 @@ class BananaPost
             $res .= '</th></tr>';
         }
  
-        preg_match("@text/([^;]+);@", $this->headers['content-type'], $format);
-        $format = $format[1];
+        if (isset($this->headers['content-type'])
+                && preg_match("@text/([^;]+);@", $this->headers['content-type'], $format)) {
+            $format = $format[1];
+        } else {
+            $format = 'plain';
+        }
         $res .= '<tr class="impair"><td colspan="2" class="body"';
         if ($format == 'html') {
             if (preg_match('@<body[^>]*bgcolor="?([#0-9a-f]+)"?[^>]*>@i', $this->body, $bgcolor)) {