From 613d45b1cced3e52cfde6c92a1ce815e771f82a8 Mon Sep 17 00:00:00 2001
From: OpenXE <>
Date: Thu, 12 Jan 2023 00:01:20 +0100
Subject: [PATCH] Ticket system improvements for import encoding, ticket system
limited display of html elements (strip_tags)
---
.../MailClient/Data/MailAttachmentData.php | 28 +++++++++++++++---
.../Ticket/Importer/TicketFormatter.php | 16 ++++++++--
.../Ticket/Task/TicketImportHelper.php | 19 ++++++++++--
www/pages/ticket.php | 29 +++++++++++++++++--
4 files changed, 80 insertions(+), 12 deletions(-)
diff --git a/classes/Components/MailClient/Data/MailAttachmentData.php b/classes/Components/MailClient/Data/MailAttachmentData.php
index f5dfcfda..fe414934 100644
--- a/classes/Components/MailClient/Data/MailAttachmentData.php
+++ b/classes/Components/MailClient/Data/MailAttachmentData.php
@@ -62,9 +62,11 @@ class MailAttachmentData implements MailAttachmentInterface
{
$encodingHeader = $part->getHeader('content-transfer-encoding');
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');
if ($dispositionHeader === null) {
throw new InvalidArgumentException('missing header: "Content-Disposition"');
@@ -111,9 +113,27 @@ class MailAttachmentData implements MailAttachmentInterface
else if ($disposition == 'inline') {
$isInline = true;
$filename = ""; // This is questionable
- } else {
+ }
+ 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 {
+ throw new InvalidArgumentException(
+ sprintf('unexpected header value "Content-Disposition" = "%s"', $disposition)
+ );
+ }
+ }
+ else {
throw new InvalidArgumentException(
- sprintf('unexpected header value "Content-Disposition" = "%s"', $disposition)
+ sprintf('unexpected header value "Content-Disposition" = "%s", not message/rfc822', $disposition)
);
}
diff --git a/classes/Modules/Ticket/Importer/TicketFormatter.php b/classes/Modules/Ticket/Importer/TicketFormatter.php
index 818a0929..8709f98b 100644
--- a/classes/Modules/Ticket/Importer/TicketFormatter.php
+++ b/classes/Modules/Ticket/Importer/TicketFormatter.php
@@ -22,12 +22,22 @@ class TicketFormatter
*/
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,
'UTF-8',
- $encoding
+ 'auto'
);
+
+ // Fallback
+ if ($converted === false) {
+ $converted = mb_convert_encoding(
+ $string,
+ 'UTF-8',
+ 'iso-8859-1'
+ );
+ }
+
+ return ($converted);
}
}
diff --git a/classes/Modules/Ticket/Task/TicketImportHelper.php b/classes/Modules/Ticket/Task/TicketImportHelper.php
index deec6b49..6bec5cd0 100644
--- a/classes/Modules/Ticket/Task/TicketImportHelper.php
+++ b/classes/Modules/Ticket/Task/TicketImportHelper.php
@@ -491,7 +491,7 @@ class TicketImportHelper
}
try {
- $this->logger->debug('Start import', ['message' => $message->getSubject()]);
+ $this->logger->debug('Start import', ['message' => $message]);
$result = $this->importMessage($message);
@@ -545,13 +545,28 @@ class TicketImportHelper
$htmlBody = $message->getHtmlBody();
if ($htmlBody === null) {
$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_html = $this->formatter->encodeToUtf8($htmlBody);
if (strlen($action_html) < strlen($action)) {
$action_html = nl2br($action);
}
+ $this->logger->debug('Text (converted)',['plain' => $action, 'html' => $action_html]);
+
// Import database emailbackup
$date = $message->getDate();
if (is_null($date)) { // This should not be happening -> Todo check getDate function
@@ -576,7 +591,7 @@ class TicketImportHelper
if ($result == 0) {
- $this->logger->debug('Importing message',['']);
+ $this->logger->debug('Importing message',['message' => $message]);
$attachments = $message->getAttachments();
$anhang = count($attachments) > 0 ? 1 : 0;
diff --git a/www/pages/ticket.php b/www/pages/ticket.php
index bd653b2c..40369ef2 100644
--- a/www/pages/ticket.php
+++ b/www/pages/ticket.php
@@ -351,7 +351,7 @@ class Ticket {
$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_BETREFF",''.htmlentities($message['betreff']).'');
+ $this->app->Tpl->Set("NACHRICHT_BETREFF",''.htmlentities($message['betreff']).'');
$this->app->Tpl->Set("NACHRICHT_FLOAT","left");
$this->app->Tpl->Set("META_FLOAT","right");
$this->app->Tpl->Set("NACHRICHT_ZEIT",$message['zeit']);
@@ -368,9 +368,21 @@ class Ticket {
}
}
+ function ticket_text() {
+
+ $secure_html_tags = array(
+ '
',
+ '
',
+ '',
+ '',
+ '',
+ '
',
+ ' ',
+ '