Changes regarding ticket incoming file attachments

This commit is contained in:
Xenomporio 2022-07-27 18:05:24 +02:00
parent b7f468e62d
commit 7efbe5bd0b
5 changed files with 77 additions and 152 deletions

View File

@ -70,6 +70,7 @@ class MailAttachmentData implements MailAttachmentInterface
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)) { if (!preg_match('/(.+);\s*filename="([^"]+)".*$/m', $disposition, $matches)) {
throw new InvalidArgumentException( throw new InvalidArgumentException(
sprintf('unexpected header value "Content-Disposition" = %s', $disposition) sprintf('unexpected header value "Content-Disposition" = %s', $disposition)
@ -77,6 +78,17 @@ class MailAttachmentData implements MailAttachmentInterface
} }
$isInline = strtolower($matches[1]) === 'inline'; $isInline = strtolower($matches[1]) === 'inline';
$filename = $matches[2]; $filename = $matches[2];
// Thunderbird UTF URL-Format
$UTF_pos = strpos($filename,'UTF-8\'\'');
if ($UTF_pos !== false) {
$wasUTF = "JA";
$filename = substr($filename,$UTF_pos);
$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

@ -15,6 +15,7 @@ use Xentral\Components\MailClient\Data\MailMessageInterface;
use Xentral\Modules\SystemMailer\Data\EmailBackupAccount; use Xentral\Modules\SystemMailer\Data\EmailBackupAccount;
use Xentral\Modules\Ticket\Importer\TicketFormatter; use Xentral\Modules\Ticket\Importer\TicketFormatter;
use Xentral\Modules\Ticket\Exception\NumberGeneratorException; use Xentral\Modules\Ticket\Exception\NumberGeneratorException;
use Xentral\Modules\Ticket\Exception\InvalidArgumentException;
/** /**
* Utility functions for tickets cronjob for improved testability * Utility functions for tickets cronjob for improved testability
@ -173,6 +174,12 @@ class TicketImportHelper
private function ensureTicketNumberExists(string $ticketNumber): void private function ensureTicketNumberExists(string $ticketNumber): void
{ {
if ($ticketNumber == '') {
throw new InvalidArgumentException(
sprintf('ticket number empty')
);
}
if (!$this->db->Select('SELECT id FROM ticket WHERE schluessel = '.$ticketNumber)) { if (!$this->db->Select('SELECT id FROM ticket WHERE schluessel = '.$ticketNumber)) {
throw new InvalidArgumentException( throw new InvalidArgumentException(
sprintf('ticket number "%s" does not exist', $ticketNumber) sprintf('ticket number "%s" does not exist', $ticketNumber)
@ -234,7 +241,7 @@ class TicketImportHelper
int $timestamp, int $timestamp,
string $replyToName, string $replyToName,
string $replyToAddress string $replyToAddress
): int ): string
{ {
$assigneeAddressId = $this->mailAccount->getAddressId(); $assigneeAddressId = $this->mailAccount->getAddressId();
if ($assigneeAddressId < 1) { if ($assigneeAddressId < 1) {
@ -275,7 +282,7 @@ class TicketImportHelper
$this->logger->debug('inserted ticket',['id' => $ticketId,'ticketnr' => $ticketNumber]); $this->logger->debug('inserted ticket',['id' => $ticketId,'ticketnr' => $ticketNumber]);
// todo als rueckgabe ticketnachricht // todo als rueckgabe ticketnachricht
return (int) $ticketNumber; return $ticketNumber;
} }
public function addTicketMessage( public function addTicketMessage(
@ -311,7 +318,7 @@ class TicketImportHelper
$this->db->Insert($sql); $this->db->Insert($sql);
$messageId = $this->db->GetInsertID(); $messageId = $this->db->GetInsertID();
$this->logger->debug('inserted',['id' => $messageId]); $this->logger->debug('inserted',['id' => $messageId, 'schluessel' => $ticketNumber]);
$this->updateTicketMessagesCount($ticketNumber); $this->updateTicketMessagesCount($ticketNumber);
$this->resetTicketStatus($ticketNumber); $this->resetTicketStatus($ticketNumber);
@ -469,15 +476,14 @@ class TicketImportHelper
echo "ticket suchen oder anlegen\n"; echo "ticket suchen oder anlegen\n";
} }
$_schluessel = null; $ticketNumber = null;
$schluessel = null;
$ticketexists = null; $ticketexists = null;
if (preg_match("/Ticket #[0-9]{12}/i", $subject, $matches)) { if (preg_match("/Ticket #[0-9]{12}/i", $subject, $matches)) {
$schluessel = str_replace('Ticket #', '', $matches[0]); $ticketNumber = str_replace('Ticket #', '', $matches[0]);
$ticketexists = $this->db->Select( $ticketexists = $this->db->Select(
"SELECT schluessel "SELECT schluessel
FROM ticket FROM ticket
WHERE schluessel LIKE '" . $schluessel . "' WHERE schluessel LIKE '" . $ticketNumber . "'
AND schluessel!='' LIMIT 1" AND schluessel!='' LIMIT 1"
); );
} }
@ -498,12 +504,12 @@ class TicketImportHelper
); );
} else { } else {
$this->logger->debug('Add message to existing ticket',['ticketnummer' => $schluessel]); $this->logger->debug('Add message to existing ticket',['ticketnummer' => $ticketNumber]);
} }
// Add message to new or existing ticket // Add message to new or existing ticket
$ticketnachricht = $this->addTicketMessage( $ticketnachricht = $this->addTicketMessage(
(string) $schluessel, (string) $ticketNumber,
$timestamp, $timestamp,
$action_html, //? $action_html, //?
$subject, $subject,
@ -514,136 +520,6 @@ class TicketImportHelper
$from $from
); );
/* OLD CODE
if ($ticketexists) {
if ($DEBUG) {
echo "ticket nummer in betreff gefunden\n";
}
$schluessel = str_replace('Ticket #', '', $matches[0]);
if ($action_html != '') {
$sql = "INSERT INTO `ticket_nachricht`
(
`id`,
`ticket`,
`zeit`,
`text`,
`betreff`,
`medium`,
`verfasser`,
`mail`,
`status`,
`verfasser_replyto`,
`mail_replyto`
) VALUES (
NULL,
'$schluessel',
FROM_UNIXTIME($timestamp),
'" . $this->db->real_escape_string($action_html) . "',
'" . $this->db->real_escape_string($subject) . "',
'email',
'" . $this->db->real_escape_string($name_sender) . "',
'" . $this->db->real_escape_string($from) . "',
'neu',
'" . $this->db->real_escape_string($verfasser_replyto) . "',
'" . $this->db->real_escape_string($mail_replyto) . "'
);";
} else {
$sql = "INSERT INTO `ticket_nachricht`
(
`id`,
`ticket`,
`zeit`,
`text`,
`betreff`,
`medium`,
`verfasser`,
`mail`,
`status`,
`verfasser_replyto`,
`mail_replyto`
) VALUES (
NULL,
'$schluessel',
FROM_UNIXTIME($timestamp),
'" . $this->db->real_escape_string($action) . "',
'" . $this->db->real_escape_string($subject) . "',
'email',
'" . $this->db->real_escape_string($name_sender) . "',
'" . $this->db->real_escape_string($from) . "',
'neu',
'" . $this->db->real_escape_string($verfasser_replyto) . "',
'" . $this->db->real_escape_string($mail_replyto) . "'
);";
}
if (!$DEBUG) {
$this->db->InsertWithoutLog(
"UPDATE ticket_nachricht
SET status = 'abgeschlossen'
WHERE ticket LIKE '$schluessel'"
);
$this->db->InsertWithoutLog($sql);
$ticketnachricht = $this->db->GetInsertID();
$this->db->InsertWithoutLog(
"UPDATE ticket
SET status='neu', zugewiesen = 0, inbearbeitung=0
WHERE schluessel LIKE '$schluessel'"
);
$this->db->Update(
"UPDATE `ticket` AS `t`
INNER JOIN (
SELECT COUNT(`id`) AS `co`, `ticket`
FROM `ticket_nachricht`
GROUP BY `ticket`
) AS `tn` ON t.schluessel = tn.ticket
SET t.nachrichten_anz = tn.co
WHERE t.schluessel = '$schluessel'"
);
}
} else {
if (!$DEBUG) {
if ($action_html != '') {
$ticketnachricht = $this->ticketModule->CreateTicket(
$this->projectId,
$mailacc,
$name_sender,
$from,
$subject,
$action_html,
$timestamp,
"email",
null,
$verfasser_replyto,
$mail_replyto
); // ACHTUNG immer Projekt eprooshop
} else {
$ticketnachricht = $this->ticketModule->CreateTicket(
$this->projectId,
$mailacc,
$name_sender,
$from,
$subject,
$action,
$timestamp,
"email",
null,
$verfasser_replyto,
$mail_replyto
); // ACHTUNG immer Projekt eprooshop
}
$schluessel = $this->db->Select(
"SELECT `ticket`
FROM `ticket_nachricht`
WHERE `id`='$ticketnachricht' LIMIT 1"
);
} else {
echo "Lege neues Ticket an\n";
}
} */
if ($ticketnachricht > 0 && $id > 0) { if ($ticketnachricht > 0 && $id > 0) {
$this->db->Update( $this->db->Update(
"UPDATE `emailbackup_mails` "UPDATE `emailbackup_mails`
@ -702,6 +578,9 @@ class TicketImportHelper
} }
} }
$this->logger->debug('Add attachments',['ticketnummer' => $ticketNumber, 'nachricht' => $ticketnachricht, 'count' => count($attachments)]);
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
if ($attachment->getFileName() !== '') { if ($attachment->getFileName() !== '') {
if ($DEBUG) { if ($DEBUG) {
@ -715,11 +594,14 @@ class TicketImportHelper
//Schreibe Anhänge in Datei-Tabelle //Schreibe Anhänge in Datei-Tabelle
$datei = $ordner . '/' . $attachment->getFileName(); $datei = $ordner . '/' . $attachment->getFileName();
$dateiname = $attachment->getFileName(); $dateiname = $attachment->getFileName();
if (stripos($dateiname, '=?utf-8') !== false) {
$this->logger->debug("Attachment", ['filename' => $dateiname]);
if (stripos(strtoupper($dateiname), '=?UTF-8') !== false) {
$dateiname = $this->formatter->encodeToUtf8($dateiname); $dateiname = $this->formatter->encodeToUtf8($dateiname);
$dateiname = htmlspecialchars_decode($dateiname); $dateiname = htmlspecialchars_decode($dateiname);
} }
if (stripos($dateiname, '=?iso-8859') !== false) { if (stripos(strtoupper($dateiname), '=?ISO-8859') !== false) {
$dateiname = $this->formatter->encodeToUtf8($dateiname); $dateiname = $this->formatter->encodeToUtf8($dateiname);
$dateiname = htmlspecialchars_decode($dateiname); $dateiname = htmlspecialchars_decode($dateiname);
} }
@ -743,6 +625,9 @@ class TicketImportHelper
if ($DEBUG) { if ($DEBUG) {
echo "AddDateiStichwort $tmpid,'Anhang','Ticket',$ticketnachricht,true)\n"; echo "AddDateiStichwort $tmpid,'Anhang','Ticket',$ticketnachricht,true)\n";
} else { } else {
$this->logger->debug('Add attachment',['ticketnummer' => $ticketNumber,'id' => $tmpid, 'nachricht' => $ticketnachricht]);
$this->erpApi->AddDateiStichwort( $this->erpApi->AddDateiStichwort(
$tmpid, $tmpid,
'Anhang', 'Anhang',
@ -770,9 +655,9 @@ class TicketImportHelper
if (empty($text)) $text = ''; if (empty($text)) $text = '';
if (empty($betreff)) $betreff = ''; if (empty($betreff)) $betreff = '';
$text = str_replace('{TICKET}', $schluessel, $text); $text = str_replace('{TICKET}', $ticketNumber, $text);
$text = str_replace('{BETREFF}', $subject, $text); $text = str_replace('{BETREFF}', $subject, $text);
$betreff = str_replace('{TICKET}', $schluessel, $betreff); $betreff = str_replace('{TICKET}', $ticketNumber, $betreff);
$betreff = str_replace('{BETREFF}', $subject, $betreff); $betreff = str_replace('{BETREFF}', $subject, $betreff);

View File

@ -29858,7 +29858,6 @@ function ChargenMHDAuslagern($artikel, $menge, $lagerplatztyp, $lpid,$typ,$wert,
return ''; return '';
} }
function GetSelectDokumentKunde($typ,$adresse,$select) function GetSelectDokumentKunde($typ,$adresse,$select)
{ {
$typ_bezeichnung = ucfirst($typ); $typ_bezeichnung = ucfirst($typ);
@ -43965,7 +43964,8 @@ function Firmendaten($field,$projekt="")
$version = $this->app->DB->Select("SELECT MAX(version) FROM datei_version WHERE datei='$id'"); $version = $this->app->DB->Select("SELECT MAX(version) FROM datei_version WHERE datei='$id'");
$newid = $this->app->DB->Select("SELECT dateiname FROM datei_version WHERE datei='$id' AND version='$version' LIMIT 1"); $newid = $this->app->DB->Select("SELECT dateiname FROM datei_version WHERE datei='$id' AND version='$version' LIMIT 1");
return $this->UmlauteEntfernen($newid); // return $this->UmlauteEntfernen($newid);
return $newid;
} }
@ -43990,7 +43990,7 @@ function Firmendaten($field,$projekt="")
$tmpname = tempnam($this->GetTMP(), $prefix); $tmpname = tempnam($this->GetTMP(), $prefix);
$newname = $tmpname."_".$this->GetDateiName($datei['datei']); $newname = $tmpname."_".$this->GetDateiName($datei['datei']);
copy($this->GetDateiPfad($datei['datei']),$newname); copy($this->GetDateiPfad($datei['datei']),$newname); // Why in the world..?!
$tmp[] = $newname; $tmp[] = $newname;
} }
@ -44005,7 +44005,8 @@ function Firmendaten($field,$projekt="")
} }
$tmp = []; $tmp = [];
foreach($dateien as $datei) { foreach($dateien as $datei) {
$tmp[] = $this->GetDateiPfad($datei['datei']); // $tmp[] = $this->GetDateiPfad($datei['datei']);
$tmp[] = $datei['datei']; // return the datei id
} }
return $tmp; return $tmp;
} }

View File

@ -9,6 +9,7 @@
<tr><td>{|[NACHRICHT_RICHTUNG]|}:</td><td>[NACHRICHT_NAME] &lt;[NACHRICHT_EMAILADRESSE]&gt;</td></tr> <tr><td>{|[NACHRICHT_RICHTUNG]|}:</td><td>[NACHRICHT_NAME] &lt;[NACHRICHT_EMAILADRESSE]&gt;</td></tr>
<tr><td colspan=2><hr style="border-style:solid; border-width:1px"></td></tr> <tr><td colspan=2><hr style="border-style:solid; border-width:1px"></td></tr>
<tr><td colspan=2><div id="body" style="overflow:scroll; max-height:400px;">[NACHRICHT_TEXT]</div></td></tr> <tr><td colspan=2><div id="body" style="overflow:scroll; max-height:400px;">[NACHRICHT_TEXT]</div></td></tr>
<tr><td colspan=2><div id="body" style="overflow:scroll; max-height:400px;">[NACHRICHT_ANHANG]</div></td></tr>
</table> </table>
</fieldset> </fieldset>
</div> </div>

View File

@ -109,6 +109,10 @@ class Ticket {
$this->ticket_list(); $this->ticket_list();
} }
function get_messages_of_ticket($ticket_id) {
return $this->app->DB->SelectArr("SELECT n.id, n.betreff, n.verfasser, n.mail, n.zeit, n.versendet, n.text FROM ticket_nachricht n INNER JOIN ticket t ON t.schluessel = n.ticket WHERE t.id = ".$ticket_id." ORDER BY n.zeit DESC");
}
function ticket_edit() { function ticket_edit() {
$id = $this->app->Secure->GetGET('id'); $id = $this->app->Secure->GetGET('id');
@ -119,6 +123,7 @@ class Ticket {
$id = $this->app->Secure->GetGET('id'); $id = $this->app->Secure->GetGET('id');
$input = $this->GetInput(); $input = $this->GetInput();
$submit = $this->app->Secure->GetPOST('submit'); $submit = $this->app->Secure->GetPOST('submit');
$msg = $this->app->erp->base64_url_decode($this->app->Secure->GetGET('msg'));
if (empty($id)) { if (empty($id)) {
// New item // New item
@ -183,7 +188,7 @@ class Ticket {
$this->app->YUI->AutoComplete("warteschlange","warteschlangename"); $this->app->YUI->AutoComplete("warteschlange","warteschlangename");
// Get messsages // Get messsages
$messages = $this->app->DB->SelectArr("SELECT n.betreff, n.verfasser, n.mail, n.zeit, n.versendet, n.text FROM ticket_nachricht n INNER JOIN ticket t ON t.schluessel = n.ticket WHERE t.id = ".$id." ORDER BY n.zeit DESC"); $messages = $this->get_messages_of_ticket($id);
switch ($submit) { switch ($submit) {
case 'neue_email': case 'neue_email':
@ -234,7 +239,6 @@ class Ticket {
true true
) != 0 ) != 0
) { ) {
$msg = '<div class="info">Die E-Mail wurde erfolgreich versendet an '.$input['email_an'].'. '.$this->app->erp->mail_error.'</div>';
// Put message into ticket_nachricht // Put message into ticket_nachricht
$sql = "INSERT INTO `ticket_nachricht` ( $sql = "INSERT INTO `ticket_nachricht` (
@ -255,13 +259,16 @@ class Ticket {
$this->app->DB->Insert($sql); $this->app->DB->Insert($sql);
$msg = '<div class="info">Die E-Mail wurde erfolgreich versendet an '.$input['email_an'].'. '.$this->app->erp->mail_error.'</div>';
header("Location: index.php?module=ticket&action=edit&id=".$id."&msg=".$this->app->erp->base64_url_encode($msg));
} }
else { else {
$msg = '<div class="error">Fehler beim Versenden der E-Mail: '.$this->app->erp->mail_error.'</div>'; $msg = '<div class="error">Fehler beim Versenden der E-Mail: '.$this->app->erp->mail_error.'</div>';
} }
// Get messsages again // Get messsages again
$messages = $this->app->DB->SelectArr("SELECT n.betreff, n.verfasser, n.mail, n.zeit, n.versendet, n.text FROM ticket_nachricht n INNER JOIN ticket t ON t.schluessel = n.ticket WHERE t.id = ".$id." ORDER BY n.zeit DESC"); $messages = $this->get_messages_of_ticket($id);
break; break;
} }
@ -280,6 +287,26 @@ class Ticket {
$this->app->Tpl->Set("NACHRICHT_NAME",$message['verfasser']); $this->app->Tpl->Set("NACHRICHT_NAME",$message['verfasser']);
$this->app->Tpl->Set("NACHRICHT_EMAILADRESSE",$message['mail']); $this->app->Tpl->Set("NACHRICHT_EMAILADRESSE",$message['mail']);
$this->app->Tpl->Set("NACHRICHT_TEXT",$message['text']); $this->app->Tpl->Set("NACHRICHT_TEXT",$message['text']);
$file_attachments = $this->app->erp->GetDateiSubjektObjekt('Anhang','Ticket',$message['id']);
if (!empty($file_attachments)) {
$this->app->Tpl->Add('NACHRICHT_ANHANG',"<hr style=\"border-style:solid; border-width:1px\">");
foreach ($file_attachments as $file_attachment) {
$this->app->Tpl->Add('NACHRICHT_ANHANG',
"<a href=\"index.php?module=dateien&action=send&id=".$file_attachment.
"\">".
htmlentities($this->app->erp->GetDateiName($file_attachment)).
" (".
$this->app->erp->GetDateiSize($file_attachment).
")".
"</a>".
"</br>");
}
}
$this->app->Tpl->Parse('MESSAGES', "ticket_nachricht.tpl"); $this->app->Tpl->Parse('MESSAGES', "ticket_nachricht.tpl");
} }
@ -308,7 +335,6 @@ class Ticket {
$input['email_bcc'] = $this->app->Secure->GetPOST('email_bcc'); $input['email_bcc'] = $this->app->Secure->GetPOST('email_bcc');
$input['email_betreff'] = $this->app->Secure->GetPOST('email_betreff'); $input['email_betreff'] = $this->app->Secure->GetPOST('email_betreff');
$input['email_text'] = $this->app->Secure->GetPOST('email_text'); $input['email_text'] = $this->app->Secure->GetPOST('email_text');
return $input; return $input;
} }