X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=banana%2Fpost.inc.php;h=df64f2715200fa46fff1e5f1fafbe2d4531a802c;hb=39816f8b637dbd80dc1a64f1a04adb4f3cf24a9f;hp=1987b56f5cde23ed358eb65378266c24a3d5a833;hpb=a79e9a4f7e785f34056ea9f37421ed7cd8269514;p=banana.git diff --git a/banana/post.inc.php b/banana/post.inc.php index 1987b56..df64f27 100644 --- a/banana/post.inc.php +++ b/banana/post.inc.php @@ -52,12 +52,12 @@ class BananaPost if (preg_match("@multipart/([^;]+);@", $this->headers['content-type'], $mpart_type)) { preg_match("/boundary=\"?([^ \"]+)\"?/", $this->headers['content-type'], $mpart_boundary); $this->_split_multipart($mpart_type[1], $mpart_boundary[1]); - } - - 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); + 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); + } } } @@ -76,11 +76,9 @@ class BananaPost $this->_add_attachment($part); } else if (isset($local_header['content-type']) && preg_match("@text/([^;]+);@", $local_header['content-type'], $format)) { array_push($this->messages, $part); + } } - } - if (count($this->messages) > 0) { - $this->set_body_to_part(0); - } + $this->set_body_to_part(0); } /** extract new headers from the part @@ -204,6 +202,12 @@ class BananaPost $this->headers[$hdr] = $local_header[$hdr]; } } + + 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); + } return true; } @@ -254,12 +258,33 @@ class BananaPost /** convert message to html * @param partid INT id of the multipart message that must be displaid */ - function to_html($partid = 0) + function to_html($partid = -1) { global $banana; - if ($partid != 0) { - $this->set_body_to_part($partid); + if (count($this->messages) > 1) { + if ($partid != -1) { + $this->set_body_to_part($partid); + } else { + // Select prefered text-format + foreach ($banana->body_mime as $mime) { + for ($id = 0 ; $id < count($this->messages) ; $id++) { + if (preg_match("@$mime@", $this->messages[$id]['headers']['content-type'])) { + $partid = $id; + $this->set_body_to_part($partid); + break; + } + } + if ($partid != -1) { + break; + } + } + if ($partid == -1) { + $partid = 0; + } + } + } else { + $partid = 0; } $res = ''; @@ -317,7 +342,7 @@ class BananaPost $res .= ''; } - $res .= ''; + $res .= ''; $ndx = $banana->spool->getndx($this->id); $res .= '';
'._b_('apercu').'
'._b_('Apercu').'
'.$banana->spool->to_html($ndx-$banana->tbefore, $ndx+$banana->tafter, $ndx).'