| @@ 5041-5081 (lines=41) @@ | ||
| 5038 | // as Translation::convert reduces \r\n to \n and purifier eats \n -> peplace it with a single space |
|
| 5039 | $newBody = str_replace("\n"," ",$newBody); |
|
| 5040 | // convert HTML to text, as we dont want HTML in infologs |
|
| 5041 | if ($useTidy && extension_loaded('tidy')) |
|
| 5042 | { |
|
| 5043 | $tidy = new tidy(); |
|
| 5044 | $cleaned = $tidy->repairString($newBody, self::$tidy_config,'utf8'); |
|
| 5045 | // Found errors. Strip it all so there's some output |
|
| 5046 | if($tidy->getStatus() == 2) |
|
| 5047 | { |
|
| 5048 | error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer); |
|
| 5049 | } |
|
| 5050 | else |
|
| 5051 | { |
|
| 5052 | $newBody = $cleaned; |
|
| 5053 | } |
|
| 5054 | if (!$preserveHTML) |
|
| 5055 | { |
|
| 5056 | // filter only the 'body', as we only want that part, if we throw away the html |
|
| 5057 | preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array()); |
|
| 5058 | if ($matches[2]) |
|
| 5059 | { |
|
| 5060 | $hasOther = true; |
|
| 5061 | $newBody = $matches[2]; |
|
| 5062 | } |
|
| 5063 | } |
|
| 5064 | } |
|
| 5065 | else |
|
| 5066 | { |
|
| 5067 | // htmLawed filter only the 'body' |
|
| 5068 | preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array()); |
|
| 5069 | if ($matches[2]) |
|
| 5070 | { |
|
| 5071 | $hasOther = true; |
|
| 5072 | $newBody = $matches[2]; |
|
| 5073 | } |
|
| 5074 | $htmLawed = new Html\HtmLawed(); |
|
| 5075 | // the next line should not be needed, but produces better results on HTML 2 Text conversion, |
|
| 5076 | // as we switched off HTMLaweds tidy functionality |
|
| 5077 | $newBody = str_replace(array('&amp;','<DIV><BR></DIV>',"<DIV> </DIV>",'<div> </div>'),array('&','<BR>','<BR>','<BR>'),$newBody); |
|
| 5078 | $newBody = $htmLawed->run($newBody,self::$htmLawed_config); |
|
| 5079 | if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3]; |
|
| 5080 | $alreadyHtmlLawed=true; |
|
| 5081 | } |
|
| 5082 | //error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody); |
|
| 5083 | if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true); |
|
| 5084 | //error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody); |
|
| @@ 3167-3207 (lines=41) @@ | ||
| 3164 | $newBody = $singleBodyPart['body']; |
|
| 3165 | //TODO:$newBody = $this->highlightQuotes($newBody); |
|
| 3166 | #error_log(print_r($newBody,true)); |
|
| 3167 | if ($useTidy && extension_loaded('tidy')) |
|
| 3168 | { |
|
| 3169 | $tidy = new tidy(); |
|
| 3170 | $cleaned = $tidy->repairString($newBody, Mail::$tidy_config,'utf8'); |
|
| 3171 | // Found errors. Strip it all so there's some output |
|
| 3172 | if($tidy->getStatus() == 2) |
|
| 3173 | { |
|
| 3174 | error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer); |
|
| 3175 | } |
|
| 3176 | else |
|
| 3177 | { |
|
| 3178 | $newBody = $cleaned; |
|
| 3179 | } |
|
| 3180 | if (!$preserveHTML) // ToDo KL: $preserveHTML is NOT initialised, so always if is dead code |
|
| 3181 | { |
|
| 3182 | // filter only the 'body', as we only want that part, if we throw away the Api\Html |
|
| 3183 | preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array()); |
|
| 3184 | if ($matches[2]) |
|
| 3185 | { |
|
| 3186 | $hasOther = true; |
|
| 3187 | $newBody = $matches[2]; |
|
| 3188 | } |
|
| 3189 | } |
|
| 3190 | } |
|
| 3191 | else |
|
| 3192 | { |
|
| 3193 | // htmLawed filter only the 'body' |
|
| 3194 | preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array()); |
|
| 3195 | if ($matches[2]) |
|
| 3196 | { |
|
| 3197 | $hasOther = true; |
|
| 3198 | $newBody = $matches[2]; |
|
| 3199 | } |
|
| 3200 | $htmLawed = new Api\Html\HtmLawed(); |
|
| 3201 | // the next line should not be needed, but produces better results on HTML 2 Text conversion, |
|
| 3202 | // as we switched off HTMLaweds tidy functionality |
|
| 3203 | $newBody = str_replace(array('&amp;','<DIV><BR></DIV>',"<DIV> </DIV>",'<div> </div>'),array('&','<BR>','<BR>','<BR>'),$newBody); |
|
| 3204 | $newBody = $htmLawed->run($newBody,Mail::$htmLawed_config); |
|
| 3205 | if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3]; |
|
| 3206 | $alreadyHtmlLawed=true; |
|
| 3207 | } |
|
| 3208 | // do the cleanup, set for the use of purifier |
|
| 3209 | //$newBodyBuff = $newBody; |
|
| 3210 | /* if (!$alreadyHtmlLawed)*/ Mail::getCleanHTML($newBody); |
|