| @@ 4953-4993 (lines=41) @@ | ||
| 4950 | // as Translation::convert reduces \r\n to \n and purifier eats \n -> peplace it with a single space |
|
| 4951 | $newBody = str_replace("\n"," ",$newBody); |
|
| 4952 | // convert HTML to text, as we dont want HTML in infologs |
|
| 4953 | if ($useTidy && extension_loaded('tidy')) |
|
| 4954 | { |
|
| 4955 | $tidy = new tidy(); |
|
| 4956 | $cleaned = $tidy->repairString($newBody, self::$tidy_config,'utf8'); |
|
| 4957 | // Found errors. Strip it all so there's some output |
|
| 4958 | if($tidy->getStatus() == 2) |
|
| 4959 | { |
|
| 4960 | error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer); |
|
| 4961 | } |
|
| 4962 | else |
|
| 4963 | { |
|
| 4964 | $newBody = $cleaned; |
|
| 4965 | } |
|
| 4966 | if (!$preserveHTML) |
|
| 4967 | { |
|
| 4968 | // filter only the 'body', as we only want that part, if we throw away the html |
|
| 4969 | preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array()); |
|
| 4970 | if ($matches[2]) |
|
| 4971 | { |
|
| 4972 | $hasOther = true; |
|
| 4973 | $newBody = $matches[2]; |
|
| 4974 | } |
|
| 4975 | } |
|
| 4976 | } |
|
| 4977 | else |
|
| 4978 | { |
|
| 4979 | // htmLawed filter only the 'body' |
|
| 4980 | preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array()); |
|
| 4981 | if ($matches[2]) |
|
| 4982 | { |
|
| 4983 | $hasOther = true; |
|
| 4984 | $newBody = $matches[2]; |
|
| 4985 | } |
|
| 4986 | $htmLawed = new Html\HtmLawed(); |
|
| 4987 | // the next line should not be needed, but produces better results on HTML 2 Text conversion, |
|
| 4988 | // as we switched off HTMLaweds tidy functionality |
|
| 4989 | $newBody = str_replace(array('&amp;','<DIV><BR></DIV>',"<DIV> </DIV>",'<div> </div>'),array('&','<BR>','<BR>','<BR>'),$newBody); |
|
| 4990 | $newBody = $htmLawed->run($newBody,self::$htmLawed_config); |
|
| 4991 | if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3]; |
|
| 4992 | $alreadyHtmlLawed=true; |
|
| 4993 | } |
|
| 4994 | //error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody); |
|
| 4995 | if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true); |
|
| 4996 | //error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody); |
|
| @@ 3021-3061 (lines=41) @@ | ||
| 3018 | $newBody = $singleBodyPart['body']; |
|
| 3019 | //TODO:$newBody = $this->highlightQuotes($newBody); |
|
| 3020 | #error_log(print_r($newBody,true)); |
|
| 3021 | if ($useTidy && extension_loaded('tidy')) |
|
| 3022 | { |
|
| 3023 | $tidy = new tidy(); |
|
| 3024 | $cleaned = $tidy->repairString($newBody, Mail::$tidy_config,'utf8'); |
|
| 3025 | // Found errors. Strip it all so there's some output |
|
| 3026 | if($tidy->getStatus() == 2) |
|
| 3027 | { |
|
| 3028 | error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer); |
|
| 3029 | } |
|
| 3030 | else |
|
| 3031 | { |
|
| 3032 | $newBody = $cleaned; |
|
| 3033 | } |
|
| 3034 | if (!$preserveHTML) // ToDo KL: $preserveHTML is NOT initialised, so always if is dead code |
|
| 3035 | { |
|
| 3036 | // filter only the 'body', as we only want that part, if we throw away the Api\Html |
|
| 3037 | preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array()); |
|
| 3038 | if ($matches[2]) |
|
| 3039 | { |
|
| 3040 | $hasOther = true; |
|
| 3041 | $newBody = $matches[2]; |
|
| 3042 | } |
|
| 3043 | } |
|
| 3044 | } |
|
| 3045 | else |
|
| 3046 | { |
|
| 3047 | // htmLawed filter only the 'body' |
|
| 3048 | preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array()); |
|
| 3049 | if ($matches[2]) |
|
| 3050 | { |
|
| 3051 | $hasOther = true; |
|
| 3052 | $newBody = $matches[2]; |
|
| 3053 | } |
|
| 3054 | $htmLawed = new Api\Html\HtmLawed(); |
|
| 3055 | // the next line should not be needed, but produces better results on HTML 2 Text conversion, |
|
| 3056 | // as we switched off HTMLaweds tidy functionality |
|
| 3057 | $newBody = str_replace(array('&amp;','<DIV><BR></DIV>',"<DIV> </DIV>",'<div> </div>'),array('&','<BR>','<BR>','<BR>'),$newBody); |
|
| 3058 | $newBody = $htmLawed->run($newBody,Mail::$htmLawed_config); |
|
| 3059 | if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3]; |
|
| 3060 | $alreadyHtmlLawed=true; |
|
| 3061 | } |
|
| 3062 | // do the cleanup, set for the use of purifier |
|
| 3063 | //$newBodyBuff = $newBody; |
|
| 3064 | /* if (!$alreadyHtmlLawed)*/ Mail::getCleanHTML($newBody); |
|