From f57cf5cb91f7e8cab7d0d0e74fe62677484aadf8 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 27 Jun 2024 18:50:37 -0400 Subject: [PATCH] Fix Plain Text Emails not showing in ticket replies by converting plain text emails to HTML for displaying --- cron_ticket_email_parser.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/cron_ticket_email_parser.php b/cron_ticket_email_parser.php index 16f48781..6be93eb5 100644 --- a/cron_ticket_email_parser.php +++ b/cron_ticket_email_parser.php @@ -329,6 +329,24 @@ $client->connect(); // Possible names for the inbox folder $inboxNames = ['Inbox', 'INBOX', 'inbox']; +// Initialize the client manager and create the client +$clientManager = new ClientManager(); +$client = $clientManager->make([ + 'host' => $config_imap_host, + 'port' => $config_imap_port, + 'encryption' => $config_imap_encryption, + 'validate_cert' => true, + 'username' => $config_imap_username, + 'password' => $config_imap_password, + 'protocol' => 'imap' +]); + +// Connect to the IMAP server +$client->connect(); + +// Possible names for the inbox folder +$inboxNames = ['Inbox', 'INBOX', 'inbox']; + // Function to get the correct inbox folder function getInboxFolder($client, $inboxNames) { foreach ($inboxNames as $name) { @@ -369,7 +387,12 @@ if ($messages->count() > 0) { $subject = sanitizeInput($message->getSubject() ?? 'No Subject'); $date = sanitizeInput($message->getDate() ?? date('Y-m-d H:i:s')); - $message_body = $message->getHtmlBody() ?? $message->getTextBody() ?? ''; + $message_body = $message->getHtmlBody() ?? ''; + + if (empty($message_body)) { + $text_body = $message->getTextBody() ?? ''; + $message_body = nl2br(htmlspecialchars($text_body)); + } if (preg_match("/\[$config_ticket_prefix\d+\]/", $subject, $ticket_number)) { preg_match('/\d+/', $ticket_number[0], $ticket_number); @@ -434,4 +457,3 @@ $client->disconnect(); // Remove the lock file unlink($lock_file_path); -?>