Charset conversion from an unknown charset do not erase the body of the message
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Tue, 11 Jul 2006 18:15:07 +0000 (18:15 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:34:52 +0000 (00:34 +0100)
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@78 9869982d-c50d-0410-be91-f2a2ec7c7c7b

Changelog
banana/post.inc.php

index e4cfa90..ccc5403 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,6 @@
+Tue, 11 Jul 2006                    Florent Bruneau <florent.bruneau@m4x.org>
+       * Bugfix: body conversion from unknown charset
+
 Mon, 10 Jul 2006                    Florent Bruneau <florent.bruneau@m4x.org>
        * Use dynamic links from tree images
        * Bugfix: force spool rows height
index b85f23d..8262285 100644 (file)
@@ -61,11 +61,7 @@ class BananaPost
         } else {
             $this->_split_multipart($mpart_type[1], $mpart_boundary[1]);
             $this->_find_uuencode();
-            if (preg_match('!charset=([^;]*)\s*(;|$)!', $this->headers['content-type'], $matches)) {
-                $this->body = iconv($matches[1], 'utf-8', $this->body);
-            } else {
-                $this->body = utf8_encode($this->body);
-            }
+            $this->_fix_charset();
         }
     }
 
@@ -195,6 +191,23 @@ class BananaPost
         return true;
     }
 
+    /** Fix body charset (convert body to utf8)
+     * @return false if failed
+     */
+    function _fix_charset()
+    {
+        if (preg_match('!charset=([^;]*)\s*(;|$)!', $this->headers['content-type'], $matches)) {
+            $body = iconv($matches[1], 'utf-8', $this->body);
+            if (strlen($body) == 0) {
+                return false;
+            }
+            $this->body = $body;
+        } else {
+            $this->body = utf8_encode($this->body);
+        }
+        return true;
+    }
+
     /** return body in plain text (useful for messages without a text/plain part)
      */
     function get_body()
@@ -257,11 +270,7 @@ class BananaPost
             }
         }
 
-        if (preg_match('!charset=([^;]*)\s*(;|$)!', $this->headers['content-type'], $matches)) {
-            $this->body = iconv($matches[1], 'utf-8', $this->body);
-        } else {
-            $this->body = utf8_encode($this->body);
-        }
+        $this->_fix_charset();
         return true;
     }