From 917d8b5947f89af85bad1f4576c16c4c69d8d814 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Tue, 22 Oct 2013 18:38:09 +0000 Subject: [PATCH] Provide '--' message for empty messages Provide fallback html2text mechanism if PHP xml extension is not available --- include/class.mailfetch.php | 18 ++++++++++++------ include/class.mailparse.php | 18 ++++++++++++------ include/html2text.php | 3 +++ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php index fababa054..3398042a2 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 4a3c5e6c5..ed6686035 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 944c62f19..8033a834b 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; -- GitLab