Ticket system improvements for import encoding, ticket system limited display of html elements (strip_tags)

This commit is contained in:
OpenXE 2023-01-12 00:01:20 +01:00
parent 1fdd6dbf95
commit 613d45b1cc
4 changed files with 80 additions and 12 deletions

View File

@ -62,9 +62,11 @@ class MailAttachmentData implements MailAttachmentInterface
{ {
$encodingHeader = $part->getHeader('content-transfer-encoding'); $encodingHeader = $part->getHeader('content-transfer-encoding');
if ($encodingHeader === null) { if ($encodingHeader === null) {
throw new InvalidArgumentException('missing header: "Content-Transfer-Encoding"'); // Assume this is no error (?) throw new InvalidArgumentException('missing header: "Content-Transfer-Encoding"');
} $encoding = '';
} else {
$encoding = $encodingHeader->getValue(); $encoding = $encodingHeader->getValue();
}
$dispositionHeader = $part->getHeader('content-disposition'); $dispositionHeader = $part->getHeader('content-disposition');
if ($dispositionHeader === null) { if ($dispositionHeader === null) {
throw new InvalidArgumentException('missing header: "Content-Disposition"'); throw new InvalidArgumentException('missing header: "Content-Disposition"');
@ -111,11 +113,29 @@ class MailAttachmentData implements MailAttachmentInterface
else if ($disposition == 'inline') { else if ($disposition == 'inline') {
$isInline = true; $isInline = true;
$filename = ""; // This is questionable $filename = ""; // This is questionable
}
else if (strpos($disposition,'attachment;\n') == 0) { // No filename, check for content type message/rfc822
$contenttypeHeader = $part->getHeader('content-type');
if ($contenttypeHeader === null) {
throw new InvalidArgumentException('missing header: "Content-Type"');
}
$contenttype = $contenttypeHeader->getValue();
if ($contenttype == 'message/rfc822') {
$isInline = false;
$filename = 'ForwardedMessage.eml';
} else { } else {
throw new InvalidArgumentException( throw new InvalidArgumentException(
sprintf('unexpected header value "Content-Disposition" = "%s"', $disposition) sprintf('unexpected header value "Content-Disposition" = "%s"', $disposition)
); );
} }
}
else {
throw new InvalidArgumentException(
sprintf('unexpected header value "Content-Disposition" = "%s", not message/rfc822', $disposition)
);
}
// Thunderbird UTF URL-Format // Thunderbird UTF URL-Format
$UTF_pos = strpos($filename,'UTF-8\'\''); $UTF_pos = strpos($filename,'UTF-8\'\'');

View File

@ -22,12 +22,22 @@ class TicketFormatter
*/ */
public function encodeToUtf8(string $string): string public function encodeToUtf8(string $string): string
{ {
$encoding = mb_detect_encoding($string, 'UTF-8, ISO-8859-1, ISO-8859-15', true);
return mb_convert_encoding( $converted = mb_convert_encoding(
$string, $string,
'UTF-8', 'UTF-8',
$encoding 'auto'
);
// Fallback
if ($converted === false) {
$converted = mb_convert_encoding(
$string,
'UTF-8',
'iso-8859-1'
); );
} }
return ($converted);
}
} }

View File

@ -491,7 +491,7 @@ class TicketImportHelper
} }
try { try {
$this->logger->debug('Start import', ['message' => $message->getSubject()]); $this->logger->debug('Start import', ['message' => $message]);
$result = $this->importMessage($message); $result = $this->importMessage($message);
@ -546,12 +546,27 @@ class TicketImportHelper
if ($htmlBody === null) { if ($htmlBody === null) {
$htmlBody = ''; $htmlBody = '';
} }
if ($plainTextBody == '' && $htmlBody == '') {
$simple_content = $message->getContent();
if (empty($simple_content)) {
$this->logger->debug('Empty mail',['message' => $message]);
} else {
$plainTextBody = $simple_content;
$htmlBody = nl2br(htmlentities($simple_content));
}
}
$this->logger->debug('Text',['plain' => $plainTextBody, 'html' => $htmlBody, 'simple_content' => $simple_content]);
$action = $this->formatter->encodeToUtf8($plainTextBody); $action = $this->formatter->encodeToUtf8($plainTextBody);
$action_html = $this->formatter->encodeToUtf8($htmlBody); $action_html = $this->formatter->encodeToUtf8($htmlBody);
if (strlen($action_html) < strlen($action)) { if (strlen($action_html) < strlen($action)) {
$action_html = nl2br($action); $action_html = nl2br($action);
} }
$this->logger->debug('Text (converted)',['plain' => $action, 'html' => $action_html]);
// Import database emailbackup // Import database emailbackup
$date = $message->getDate(); $date = $message->getDate();
if (is_null($date)) { // This should not be happening -> Todo check getDate function if (is_null($date)) { // This should not be happening -> Todo check getDate function
@ -576,7 +591,7 @@ class TicketImportHelper
if ($result == 0) { if ($result == 0) {
$this->logger->debug('Importing message',['']); $this->logger->debug('Importing message',['message' => $message]);
$attachments = $message->getAttachments(); $attachments = $message->getAttachments();
$anhang = count($attachments) > 0 ? 1 : 0; $anhang = count($attachments) > 0 ? 1 : 0;

View File

@ -351,7 +351,7 @@ class Ticket {
$this->app->Tpl->Set("NACHRICHT_RECIPIENTS",htmlentities($message['quelle'])); $this->app->Tpl->Set("NACHRICHT_RECIPIENTS",htmlentities($message['quelle']));
} }
$this->app->Tpl->Set("NACHRICHT_CC_RECIPIENTS",htmlentities($message['mail_cc_recipients'])); $this->app->Tpl->Set("NACHRICHT_CC_RECIPIENTS",htmlentities($message['mail_cc_recipients']));
$this->app->Tpl->Set("NACHRICHT_BETREFF",'<a href="index.php?module=ticket&action=text&mid='.$message['id'].'" target="_blank">'.htmlentities($message['betreff']).'</a>'); $this->app->Tpl->Set("NACHRICHT_BETREFF",'<a href="index.php?module=ticket&action=text&mid='.$message['id'].'&insecure=1" target="_blank">'.htmlentities($message['betreff']).'</a>');
$this->app->Tpl->Set("NACHRICHT_FLOAT","left"); $this->app->Tpl->Set("NACHRICHT_FLOAT","left");
$this->app->Tpl->Set("META_FLOAT","right"); $this->app->Tpl->Set("META_FLOAT","right");
$this->app->Tpl->Set("NACHRICHT_ZEIT",$message['zeit']); $this->app->Tpl->Set("NACHRICHT_ZEIT",$message['zeit']);
@ -368,9 +368,21 @@ class Ticket {
} }
} }
function ticket_text() { function ticket_text() {
$secure_html_tags = array(
'<br>',
'<p>',
'<strong>',
'<b>',
'<table>',
'<tr>',
'<td>',
'<style>'
);
$mid = $this->app->Secure->GetGET('mid'); $mid = $this->app->Secure->GetGET('mid');
$insecure = $this->app->Secure->GetGET('insecure');
if (empty($mid)) { if (empty($mid)) {
return; return;
@ -381,7 +393,18 @@ class Ticket {
if (empty($messages)) { if (empty($messages)) {
} }
if ($insecure) {
$this->app->Tpl->Set("TEXT",$messages[0]['text']); $this->app->Tpl->Set("TEXT",$messages[0]['text']);
} else {
$secure_text = strip_tags($messages[0]['text'],$secure_html_tags);
if (strlen($secure_text) != strlen($messages[0]['text'])) {
// $secure_text = "<p style=\"all: initial;border-bottom-color:black;border-bottom-style:solid;border-bottom-width:1px;display:block;font-size:small;\">Einige Elemente wurden durch OpenXE blockiert.</p>".$secure_text;
$secure_text = "<img src=\"./themes/{$this->app->Conf->WFconf['defaulttheme']}/images/icon-invisible.svg\" alt=\"Einige Elemente wurden durch OpenXE blockiert.\" title=\"Einige Elemente wurden durch OpenXE blockiert.\" border=\"0\" style=\"all: initial;display:block;float:right;font-size:small;\">".$secure_text;
}
$this->app->Tpl->Set("TEXT",$secure_text);
}
$this->app->Tpl->Output('ticket_text.tpl'); $this->app->Tpl->Output('ticket_text.tpl');
$this->app->ExitXentral(); $this->app->ExitXentral();
} }