3 * Copyright (c) STMicroelectronics, 2004-2009. All rights reserved
5 * This file is a part of Codendi.
7 * Codendi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Codendi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
21 require_once('Mail/mimeDecode.php');
23 class ForumML_mimeDecode extends Mail_mimeDecode {
26 * Redfined here just to avoid breakage on isStatic test (first line).
27 * It's just a copy/paste of parent's method
29 function decode($params = null)
31 // determine if this method has been called statically
32 $isStatic = !(isset($this) && get_class($this) == __CLASS__);
34 // Have we been called statically?
35 // If so, create an object and pass details to that.
36 if ($isStatic AND isset($params['input'])) {
38 $obj = new Mail_mimeDecode($params['input']);
39 $structure = $obj->decode($params);
41 // Called statically but no input
42 } elseif ($isStatic) {
43 return PEAR::raiseError('Called statically and no input given');
45 // Called via an object
47 $this->_include_bodies = isset($params['include_bodies']) ?
48 $params['include_bodies'] : false;
49 $this->_decode_bodies = isset($params['decode_bodies']) ?
50 $params['decode_bodies'] : false;
51 $this->_decode_headers = isset($params['decode_headers']) ?
52 $params['decode_headers'] : false;
54 $structure = $this->_decode($this->_header, $this->_body);
55 if ($structure === false) {
56 $structure = $this->raiseError($this->_error);
64 * Redefined to convert headers to utf8 automatically. Same method than
65 * parent except code between // +++ Codendi: UTF8
67 function _decodeHeader($input)
69 // Remove white space between encoded-words
70 $input = preg_replace('/(=\?[^?]+\?(q|b)\?[^?]*\?=)(\s)+=\?/i', '\1=?', $input);
72 // For each encoded-word...
73 while (preg_match('/(=\?([^?]+)\?(q|b)\?([^?]*)\?=)/i', $input, $matches)) {
75 $encoded = $matches[1];
76 $charset = $matches[2];
77 $encoding = $matches[3];
80 switch (strtolower($encoding)) {
82 $text = base64_decode($text);
86 $text = str_replace('_', ' ', $text);
87 preg_match_all('/=([a-f0-9]{2})/i', $text, $matches);
88 foreach($matches[1] as $value)
89 $text = str_replace('='.$value, chr(hexdec($value)), $text);
94 if (function_exists('mb_convert_encoding')) {
95 $text = mb_convert_encoding($text, 'UTF-8', $charset);
99 $input = str_replace($encoded, $text, $input);