diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php index fababa054d5d847234487fa64a8dab1752a7ee06..3398042a2914b681ebbde24a99ed81131dddc18b 100644 --- a/include/class.mailfetch.php +++ b/include/class.mailfetch.php @@ -421,22 +421,28 @@ class MailFetcher { if ($cfg->isHtmlThreadEnabled()) { if ($body=$this->getPart($mid, 'text/html', $this->charset)) { //Cleanup the html. - $body=Format::safe_html($body); //Balance html tags & neutralize unsafe tags. + $body = (trim($body, " <>br/\t\n\r")) + ? Format::safe_html($body) + : '--'; } elseif ($body=$this->getPart($mid, 'text/plain', $this->charset)) { - $body = Format::htmlchars($body); - $body = "<div style=\"white-space:pre-wrap\">$body</div>"; + $body = trim($body) + ? sprintf('<div style="white-space:pre-wrap">%s</div>', + Format::htmlchars($body)) + : '--'; } } else { if ($body=$this->getPart($mid, 'text/plain', $this->charset)) { - //Cleanup the html. $body = Format::htmlchars($body); - $body = "<div style=\"white-space:pre-wrap\">$body</div>"; } elseif ($body=$this->getPart($mid, 'text/html', $this->charset)) { - $body = convert_html_to_text($body, 100); + $body = convert_html_to_text(Format::safe_html($body), 100); } + $body = trim($body) + ? sprintf('<div style="white-space:pre-wrap">%s</div>', + $body) + : '--'; } return $body; } diff --git a/include/class.mailparse.php b/include/class.mailparse.php index 4a3c5e6c5bb8c2e3c5c7f22f9c4a0165a8a6a7c5..ed668603556c7329299e38d6211750c74b778a29 100644 --- a/include/class.mailparse.php +++ b/include/class.mailparse.php @@ -160,23 +160,29 @@ class Mail_Parse { if ($cfg->isHtmlThreadEnabled()) { if ($body=$this->getPart($this->struct,'text/html')) { - //Cleanup the html. - $body=Format::safe_html($body); //Balance html tags & neutralize unsafe tags. + // Cleanup the html -- Balance html tags & neutralize unsafe tags. + $body = (trim($body, " <>br/\t\n\r")) + ? Format::safe_html($body) + : '--'; } elseif ($body=$this->getPart($this->struct,'text/plain')) { - $body = Format::htmlchars($body); - $body = "<div style=\"white-space:pre-wrap\">$body</div>"; + $body = trim($body) + ? sprintf('<div style="white-space:pre-wrap">%s</div>', + Format::htmlchars($body)) + : '--'; } } else { if ($body=$this->getPart($this->struct,'text/plain')) { - //Cleanup the html. $body = Format::htmlchars($body); - $body = "<div style=\"white-space:pre-wrap\">$body</div>"; } elseif ($body=$this->getPart($this->struct,'text/html')) { $body = convert_html_to_text($body, 100); } + $body = trim($body) + ? sprintf('<div style="white-space:pre-wrap">%s</div>', + $body) + : '--'; } return $body; } diff --git a/include/html2text.php b/include/html2text.php index 944c62f19b2472bed206b8bfeed6b3e8219d241e..8033a834b1d2e90b28a43b730a5a45c5b70d0edc 100644 --- a/include/html2text.php +++ b/include/html2text.php @@ -27,6 +27,9 @@ function convert_html_to_text($html, $width=74) { $html = fix_newlines($html); + if (!extension_loaded('xml')) + return strip_tags($html); + $doc = new DOMDocument('1.0', 'utf-8'); if (!@$doc->loadHTML($html)) return $html;