Code Duplication    Length = 41-41 lines in 2 locations

api/src/Mail.php 1 location

@@ 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;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<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);

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

@@ 3157-3197 (lines=41) @@
3154
				$newBody	= $singleBodyPart['body'];
3155
				//TODO:$newBody	= $this->highlightQuotes($newBody);
3156
				#error_log(print_r($newBody,true));
3157
				if ($useTidy && extension_loaded('tidy'))
3158
				{
3159
					$tidy = new tidy();
3160
					$cleaned = $tidy->repairString($newBody, Mail::$tidy_config,'utf8');
3161
					// Found errors. Strip it all so there's some output
3162
					if($tidy->getStatus() == 2)
3163
					{
3164
						error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer);
3165
					}
3166
					else
3167
					{
3168
						$newBody = $cleaned;
3169
					}
3170
					if (!$preserveHTML)	// ToDo KL: $preserveHTML is NOT initialised, so always if is dead code
3171
					{
3172
						// filter only the 'body', as we only want that part, if we throw away the Api\Html
3173
						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
3174
						if ($matches[2])
3175
						{
3176
							$hasOther = true;
3177
							$newBody = $matches[2];
3178
						}
3179
					}
3180
				}
3181
				else
3182
				{
3183
					// htmLawed filter only the 'body'
3184
					preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
3185
					if ($matches[2])
3186
					{
3187
						$hasOther = true;
3188
						$newBody = $matches[2];
3189
					}
3190
					$htmLawed = new Api\Html\HtmLawed();
3191
					// the next line should not be needed, but produces better results on HTML 2 Text conversion,
3192
					// as we switched off HTMLaweds tidy functionality
3193
					$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
3194
					$newBody = $htmLawed->run($newBody,Mail::$htmLawed_config);
3195
					if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
3196
					$alreadyHtmlLawed=true;
3197
				}
3198
				// do the cleanup, set for the use of purifier
3199
				//$newBodyBuff = $newBody;
3200
				/* if (!$alreadyHtmlLawed)*/ Mail::getCleanHTML($newBody);