From 322b97de389e1a8befd1f9d48f293f6b2a311223 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Tue, 11 Jul 2006 18:15:07 +0000 Subject: [PATCH] Charset conversion from an unknown charset do not erase the body of the message git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@78 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- Changelog | 3 +++ banana/post.inc.php | 29 +++++++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Changelog b/Changelog index e4cfa90..ccc5403 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +Tue, 11 Jul 2006 Florent Bruneau + * Bugfix: body conversion from unknown charset + Mon, 10 Jul 2006 Florent Bruneau * Use dynamic links from tree images * Bugfix: force spool rows height diff --git a/banana/post.inc.php b/banana/post.inc.php index b85f23d..8262285 100644 --- a/banana/post.inc.php +++ b/banana/post.inc.php @@ -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; } -- 2.1.4