Skip to content
Snippets Groups Projects
Commit 897ef322 authored by Peter Rotich's avatar Peter Rotich
Browse files

Decide the thread body type at email parsing time.

This would in theory allow us to decide at the email level the content type
to accept.
parent 433d7377
Branches
Tags
No related merge requests found
...@@ -472,10 +472,8 @@ class MailFetcher { ...@@ -472,10 +472,8 @@ class MailFetcher {
foreach ($struct->parameters as $p) { foreach ($struct->parameters as $p) {
if (strtolower($p->attribute) == 'report-type' if (strtolower($p->attribute) == 'report-type'
&& $p->value == 'delivery-status') { && $p->value == 'delivery-status') {
return sprintf('<pre>%s</pre>', return new TextThreadBody( $this->getPart(
Format::htmlchars( $mid, 'text/plain', $this->charset, $struct, false, 1));
$this->getPart($mid, 'text/plain', $this->charset, $struct, false, 1)
));
} }
} }
} }
...@@ -501,27 +499,23 @@ class MailFetcher { ...@@ -501,27 +499,23 @@ class MailFetcher {
global $cfg; global $cfg;
if ($cfg->isHtmlThreadEnabled()) { if ($cfg->isHtmlThreadEnabled()) {
if ($body=$this->getPart($mid, 'text/html', $this->charset)) { if ($html=$this->getPart($mid, 'text/html', $this->charset))
//Cleanup the html. $body = new HtmlThreadBody($html);
$body = (trim($body, " <>br/\t\n\r")) elseif ($text=$this->getPart($mid, 'text/plain', $this->charset))
? Format::safe_html($body) $body = new TextThreadBody($text);
: '--';
}
elseif ($body=$this->getPart($mid, 'text/plain', $this->charset)) {
$body = trim($body)
? sprintf('<pre>%s</pre>',
Format::htmlchars($body))
: '--';
}
}
else {
if (!($body=$this->getPart($mid, 'text/plain', $this->charset))) {
if ($body=$this->getPart($mid, 'text/html', $this->charset)) {
$body = Format::html2text(Format::safe_html($body), 100, false);
}
}
$body = trim($body) ? $body : '--';
} }
elseif ($text=$this->getPart($mid, 'text/plain', $this->charset))
$body = new TextThreadBody($text);
elseif ($html=$this->getPart($mid, 'text/html', $this->charset))
$body = new TextThreadBody(
Format::html2text(Format::safe_html($html),
100, false));
else
$body = new TextThreadBody('');
if ($cfg->stripQuotedReply())
$body->stripQuotedReply($cfg->getReplySeparator());
return $body; return $body;
} }
...@@ -572,7 +566,7 @@ class MailFetcher { ...@@ -572,7 +566,7 @@ class MailFetcher {
$vars['thread-type'] = 'N'; $vars['thread-type'] = 'N';
} }
else { else {
$vars['message'] = Format::stripEmptyLines($this->getBody($mid)); $vars['message'] = $this->getBody($mid);
} }
......
...@@ -229,27 +229,23 @@ class Mail_Parse { ...@@ -229,27 +229,23 @@ class Mail_Parse {
global $cfg; global $cfg;
if ($cfg->isHtmlThreadEnabled()) { if ($cfg->isHtmlThreadEnabled()) {
if ($body=$this->getPart($this->struct,'text/html')) { if ($html=$this->getPart($this->struct,'text/html'))
// Cleanup the html -- Balance html tags & neutralize unsafe tags. $body = new HtmlThreadBody($html);
$body = (trim($body, " <>br/\t\n\r")) elseif ($text=$this->getPart($this->struct,'text/plain'))
? Format::safe_html($body) $body = new TextThreadBody($text);
: '--';
}
elseif ($body=$this->getPart($this->struct,'text/plain')) {
$body = trim($body)
? sprintf('<pre>%s</pre>',
Format::htmlchars($body))
: '--';
}
}
else {
if (!($body=$this->getPart($this->struct,'text/plain'))) {
if ($body=$this->getPart($this->struct,'text/html')) {
$body = Format::html2text(Format::safe_html($body), 100, false);
}
}
$body = trim($body) ? $body : '--';
} }
elseif ($text=$this->getPart($this->struct,'text/plain'))
$body = new TextThreadBody($text);
elseif ($html=$this->getPart($this->struct,'text/html'))
$body = new TextThreadBody(
Format::html2text(Format::safe_html($html),
100, false));
else
$body = new TextThreadBody('');
if ($cfg->stripQuotedReply())
$body->stripQuotedReply($cfg->getReplySeparator());
return $body; return $body;
} }
...@@ -481,7 +477,7 @@ class EmailDataParser { ...@@ -481,7 +477,7 @@ class EmailDataParser {
} }
else { else {
// Typical email // Typical email
$data['message'] = Format::stripEmptyLines($parser->getBody()); $data['message'] = $parser->getBody();
$data['in-reply-to'] = $parser->struct->headers['in-reply-to']; $data['in-reply-to'] = $parser->struct->headers['in-reply-to'];
$data['references'] = $parser->struct->headers['references']; $data['references'] = $parser->struct->headers['references'];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment