'That email is no longer kept.']); exit; } $row = ticketForModal($attachment['ticket_attachment_ticket_id'], 1); $ticket_id = intval($row['ticket_id']); $path = dirname(__DIR__, 3) . "/uploads/tickets/$ticket_id/" . basename((string) $attachment['ticket_attachment_reference_name']); $too_big = is_file($path) && filesize($path) > 25 * 1024 * 1024; $raw = is_file($path) && !$too_big ? (string) file_get_contents($path) : ''; $fields = []; $header_text = ''; $body_text = ''; $attachment_names = []; if ($raw !== '') { require_once dirname(__DIR__, 3) . '/libs/vendor/autoload.php'; // ImapEngine // The header block as it came - everything before the first blank line, folded lines kept $split = preg_split("/\r?\n\r?\n/", $raw, 2); $header_text = $split[0] ?? ''; try { $message = new \DirectoryTree\ImapEngine\FileMessage($raw); $people = function ($addresses) { return implode(', ', array_map(function ($address) { $name = trim((string) $address->name()); return $name !== '' ? "$name <" . $address->email() . '>' : (string) $address->email(); }, array_filter((array) $addresses))); }; $from = $message->from(); $fields = array_filter([ 'From' => $from ? $people([$from]) : '', 'To' => $people($message->to()), 'Cc' => $people($message->cc()), 'Date' => $message->date() ? $message->date()->format('Y-m-d H:i:s T') : '', 'Subject' => (string) $message->subject(), ], function ($value) { return $value !== ''; }); $body_text = (string) $message->text(); if (trim($body_text) === '' && $message->html()) { $html = preg_replace('/<(style|script|head)\b[^>]*>.*?<\/\1>/is', '', (string) $message->html()); $html = preg_replace('/<(br|\/p|\/div|\/tr|\/li|\/h[1-6])[^>]*>/i', "\n", $html); $body_text = html_entity_decode(strip_tags($html), ENT_QUOTES, 'UTF-8'); } $body_text = trim(preg_replace("/\n{3,}/", "\n\n", str_replace("\r", '', $body_text))); foreach ($message->attachments() as $part) { $attachment_names[] = (string) $part->filename(); } } catch (Throwable $e) { $body_text = ''; } } ob_start(); ?>