ticket system bugfixes for import: escaping, attachments, dateformat

This commit is contained in:
OpenXE 2023-01-04 12:27:34 +01:00
parent 14bf992b2b
commit 2844c1cc67
3 changed files with 58 additions and 24 deletions

View File

@ -69,26 +69,63 @@ class MailAttachmentData implements MailAttachmentInterface
if ($dispositionHeader === null) { if ($dispositionHeader === null) {
throw new InvalidArgumentException('missing header: "Content-Disposition"'); throw new InvalidArgumentException('missing header: "Content-Disposition"');
} }
$disposition = $dispositionHeader->getValue(); $disposition = $dispositionHeader->getValue();
if (!preg_match('/(.+);\s*filename="([^"]+)".*$/m', $disposition, $matches)) { /*
Content-Disposition: inline
Content-Disposition: attachment
Content-Disposition: attachment; filename="filename.jpg"
This is not correctly implemented -> only the first string is evaluated
Content-Disposition: attachment; filename*0="filename_that_is_"
Content-Disposition: attachment; filename*1="very_long.jpg"
*/
if (preg_match('/(.+);\s*filename(?:\*[0-9]){0,1}="([^"]+)".*$/m', $disposition, $matches)) {
$isInline = strtolower($matches[1]) === 'inline';
$filename = $matches[2];
}
else if ($disposition == 'attachment') {
// Filename is given in Content-Type e.g.
/* Content-Type: application/pdf; name="Filename.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
*/
$contenttypeHeader = $part->getHeader('content-type');
if ($contenttypeHeader === null) {
throw new InvalidArgumentException('missing header: "Content-Type"');
}
$contenttype = $contenttypeHeader->getValue();
if (preg_match('/(.+);\s*name(?:\*[0-9]){0,1}="([^"]+)".*$/m', $contenttype, $matches)) {
$isInline = strtolower($matches[1]) === 'inline';
$filename = $matches[2];
} else {
throw new InvalidArgumentException(
sprintf('missing filename in header value "Content-Type" = "%s"', $contenttype)
);
}
}
else if ($disposition == 'inline') {
$isInline = true;
$filename = ""; // This is questionable
} else {
throw new InvalidArgumentException( throw new InvalidArgumentException(
sprintf('unexpected header value "Content-Disposition" = %s', $disposition) sprintf('unexpected header value "Content-Disposition" = "%s"', $disposition)
); );
} }
$isInline = strtolower($matches[1]) === 'inline';
$filename = $matches[2];
// Thunderbird UTF URL-Format // Thunderbird UTF URL-Format
$UTF_pos = strpos($filename,'UTF-8\'\''); $UTF_pos = strpos($filename,'UTF-8\'\'');
if ($UTF_pos !== false) { if ($UTF_pos !== false) {
$wasUTF = "JA"; $wasUTF = "JA";
$filename = substr($filename,$UTF_pos); $filename = substr($filename,$UTF_pos);
$filename = rawurldecode($filename); $filename = rawurldecode($filename);
} }
$cid = null; $cid = null;
$contentIdHeader = $part->getHeader('content-id'); $contentIdHeader = $part->getHeader('content-id');
if ($contentIdHeader !== null) { if ($contentIdHeader !== null) {

View File

@ -308,10 +308,7 @@ final class MailMessageData implements MailMessageInterface, JsonSerializable
if ($date === null) { if ($date === null) {
return null; return null;
} }
$dateTime = DateTime::createFromFormat(DateTimeInterface::RFC2822, $date->getValue()); $dateTime = date_create($date->getValue());
if ($dateTime === false) {
$dateTime = DateTime::createFromFormat(DateTimeInterface::RFC822, $date->getValue());
}
if ($dateTime === false) { if ($dateTime === false) {
return null; return null;
} }

View File

@ -337,7 +337,7 @@ class TicketImportHelper
if (!empty($queue_id)) { if (!empty($queue_id)) {
$queue_label = $this->db->Select("SELECT label FROM warteschlangen WHERE id = ".$queue_id." LIMIT 1"); $queue_label = $this->db->Select("SELECT label FROM warteschlangen WHERE id = ".$queue_id." LIMIT 1");
} }
$insertTicket = "INSERT INTO `ticket` ( $insertTicket = "INSERT INTO `ticket` (
`schluessel`, `zeit`, `projekt`, `quelle`, `status`, `kunde`, `schluessel`, `zeit`, `projekt`, `quelle`, `status`, `kunde`,
`mailadresse`, `prio`, `betreff`,`warteschlange`,`adresse` `mailadresse`, `prio`, `betreff`,`warteschlange`,`adresse`
@ -347,10 +347,10 @@ class TicketImportHelper
'".$projectId."', '".$projectId."',
'".$this->mailAccount->getEmailAddress()."', '".$this->mailAccount->getEmailAddress()."',
'".$status."', '".$status."',
'".$senderName."', '".$this->db->real_escape_string($senderName)."',
'".$senderAddress."', '".$this->db->real_escape_string($senderAddress)."',
'".'3'."', '".'3'."',
'".$subject."', '".$this->db->real_escape_string($subject)."',
'".$queue_label."', '".$queue_label."',
'".$AddressId."');"; '".$AddressId."');";
@ -383,14 +383,14 @@ class TicketImportHelper
) VALUES ( ) VALUES (
'".$ticketNumber."', '".$ticketNumber."',
'".date('Y-m-d H:i:s', $timestamp)."', '".date('Y-m-d H:i:s', $timestamp)."',
'".$message."', '".$this->db->real_escape_string($message)."',
'".$subject."', '".$this->db->real_escape_string($subject)."',
'".'email'."', '".'email'."',
'".$senderName."', '".$this->db->real_escape_string($senderName)."',
'".$senderAddress."', '".$this->db->real_escape_string($senderAddress)."',
'".$status."', '".$status."',
'".$replyToName."', '".$this->db->real_escape_string($replyToName)."',
'".$replyToAddress."');"; '".$this->db->real_escape_string($replyToAddress)."');";
$this->logger->debug('database insert',['query' => $sql]); $this->logger->debug('database insert',['query' => $sql]);
$this->db->Insert($sql); $this->db->Insert($sql);
@ -555,8 +555,8 @@ class TicketImportHelper
// 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
$this->logger->debug('Null date',['subject' => $message->getSubject()]); $this->logger->debug('Null date',['subject' => $message->getSubject(), $message->getHeader('date')->getValue()]);
$frommd5 = md5($from . $subject); return(false);
} else { } else {
$timestamp = $date->getTimestamp(); $timestamp = $date->getTimestamp();
$frommd5 = md5($from . $subject . $timestamp); $frommd5 = md5($from . $subject . $timestamp);