Merge remote-tracking branch 'upstream/master' into subscriptioncycle

This commit is contained in:
Andreas Palm
2023-01-12 21:52:56 +01:00
30 changed files with 2854 additions and 232161 deletions
@@ -62,33 +62,90 @@ 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"');
}
$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 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)
);
}
$isInline = strtolower($matches[1]) === 'inline';
$filename = $matches[2];
// Thunderbird UTF URL-Format
$UTF_pos = strpos($filename,'UTF-8\'\'');
if ($UTF_pos !== false) {
if ($UTF_pos !== false) {
$wasUTF = "JA";
$filename = substr($filename,$UTF_pos);
$filename = rawurldecode($filename);
}
$cid = null;
$contentIdHeader = $part->getHeader('content-id');
if ($contentIdHeader !== null) {
@@ -308,10 +308,7 @@ final class MailMessageData implements MailMessageInterface, JsonSerializable
if ($date === null) {
return null;
}
$dateTime = DateTime::createFromFormat(DateTimeInterface::RFC2822, $date->getValue());
if ($dateTime === false) {
$dateTime = DateTime::createFromFormat(DateTimeInterface::RFC822, $date->getValue());
}
$dateTime = date_create($date->getValue());
if ($dateTime === false) {
return null;
}
@@ -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);
}
}
@@ -337,7 +337,7 @@ class TicketImportHelper
if (!empty($queue_id)) {
$queue_label = $this->db->Select("SELECT label FROM warteschlangen WHERE id = ".$queue_id." LIMIT 1");
}
$insertTicket = "INSERT INTO `ticket` (
`schluessel`, `zeit`, `projekt`, `quelle`, `status`, `kunde`,
`mailadresse`, `prio`, `betreff`,`warteschlange`,`adresse`
@@ -347,10 +347,10 @@ class TicketImportHelper
'".$projectId."',
'".$this->mailAccount->getEmailAddress()."',
'".$status."',
'".$senderName."',
'".$senderAddress."',
'".$this->db->real_escape_string($senderName)."',
'".$this->db->real_escape_string($senderAddress)."',
'".'3'."',
'".$subject."',
'".$this->db->real_escape_string($subject)."',
'".$queue_label."',
'".$AddressId."');";
@@ -383,14 +383,14 @@ class TicketImportHelper
) VALUES (
'".$ticketNumber."',
'".date('Y-m-d H:i:s', $timestamp)."',
'".$message."',
'".$subject."',
'".$this->db->real_escape_string($message)."',
'".$this->db->real_escape_string($subject)."',
'".'email'."',
'".$senderName."',
'".$senderAddress."',
'".$this->db->real_escape_string($senderName)."',
'".$this->db->real_escape_string($senderAddress)."',
'".$status."',
'".$replyToName."',
'".$replyToAddress."');";
'".$this->db->real_escape_string($replyToName)."',
'".$this->db->real_escape_string($replyToAddress)."');";
$this->logger->debug('database insert',['query' => $sql]);
$this->db->Insert($sql);
@@ -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,18 +545,33 @@ 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
$this->logger->debug('Null date',['subject' => $message->getSubject()]);
$frommd5 = md5($from . $subject);
$this->logger->debug('Null date',['subject' => $message->getSubject(), $message->getHeader('date')->getValue()]);
return(false);
} else {
$timestamp = $date->getTimestamp();
$frommd5 = md5($from . $subject . $timestamp);
@@ -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;