Skip to content
Snippets Groups Projects
Commit 917d8b59 authored by Jared Hancock's avatar Jared Hancock
Browse files

Provide '--' message for empty messages

Provide fallback html2text mechanism if PHP xml extension is not available
parent 15d5dd63
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment