Code Duplication    Length = 41-41 lines in 2 locations

api/src/Mail.php 1 location

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

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

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