Code Duplication    Length = 41-41 lines in 2 locations

mail/inc/class.mail_ui.inc.php 1 location

@@ 3027-3067 (lines=41) @@
3024
				$newBody	= $singleBodyPart['body'];
3025
				//TODO:$newBody	= $this->highlightQuotes($newBody);
3026
				#error_log(print_r($newBody,true));
3027
				if ($useTidy && extension_loaded('tidy'))
3028
				{
3029
					$tidy = new tidy();
3030
					$cleaned = $tidy->repairString($newBody, Mail::$tidy_config,'utf8');
3031
					// Found errors. Strip it all so there's some output
3032
					if($tidy->getStatus() == 2)
3033
					{
3034
						error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer);
3035
					}
3036
					else
3037
					{
3038
						$newBody = $cleaned;
3039
					}
3040
					if (!$preserveHTML)	// ToDo KL: $preserveHTML is NOT initialised, so always if is dead code
3041
					{
3042
						// filter only the 'body', as we only want that part, if we throw away the Api\Html
3043
						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
3044
						if ($matches[2])
3045
						{
3046
							$hasOther = true;
3047
							$newBody = $matches[2];
3048
						}
3049
					}
3050
				}
3051
				else
3052
				{
3053
					// htmLawed filter only the 'body'
3054
					preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
3055
					if ($matches[2])
3056
					{
3057
						$hasOther = true;
3058
						$newBody = $matches[2];
3059
					}
3060
					$htmLawed = new Api\Html\HtmLawed();
3061
					// the next line should not be needed, but produces better results on HTML 2 Text conversion,
3062
					// as we switched off HTMLaweds tidy functionality
3063
					$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
3064
					$newBody = $htmLawed->run($newBody,Mail::$htmLawed_config);
3065
					if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
3066
					$alreadyHtmlLawed=true;
3067
				}
3068
				// do the cleanup, set for the use of purifier
3069
				//$newBodyBuff = $newBody;
3070
				/* if (!$alreadyHtmlLawed)*/ Mail::getCleanHTML($newBody);

api/src/Mail.php 1 location

@@ 5004-5044 (lines=41) @@
5001
					// as Translation::convert reduces \r\n to \n and purifier eats \n -> peplace it with a single space
5002
					$newBody = str_replace("\n"," ",$newBody);
5003
					// convert HTML to text, as we dont want HTML in infologs
5004
					if ($useTidy && extension_loaded('tidy'))
5005
					{
5006
						$tidy = new tidy();
5007
						$cleaned = $tidy->repairString($newBody, self::$tidy_config,'utf8');
5008
						// Found errors. Strip it all so there's some output
5009
						if($tidy->getStatus() == 2)
5010
						{
5011
							error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer);
5012
						}
5013
						else
5014
						{
5015
							$newBody = $cleaned;
5016
						}
5017
						if (!$preserveHTML)
5018
						{
5019
							// filter only the 'body', as we only want that part, if we throw away the html
5020
							preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
5021
							if ($matches[2])
5022
							{
5023
								$hasOther = true;
5024
								$newBody = $matches[2];
5025
							}
5026
						}
5027
					}
5028
					else
5029
					{
5030
						// htmLawed filter only the 'body'
5031
						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
5032
						if ($matches[2])
5033
						{
5034
							$hasOther = true;
5035
							$newBody = $matches[2];
5036
						}
5037
						$htmLawed = new Html\HtmLawed();
5038
						// the next line should not be needed, but produces better results on HTML 2 Text conversion,
5039
						// as we switched off HTMLaweds tidy functionality
5040
						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
5041
						$newBody = $htmLawed->run($newBody,self::$htmLawed_config);
5042
						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
5043
						$alreadyHtmlLawed=true;
5044
					}
5045
					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
5046
					if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5047
					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);