Skip to content

Commit

Permalink
Fix Plain Text Emails not showing in ticket replies by converting pla…
Browse files Browse the repository at this point in the history
…in text emails to HTML for displaying
  • Loading branch information
johnnyq committed Jun 27, 2024
1 parent 95fd034 commit f57cf5c
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions cron_ticket_email_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,24 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac
// 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) {
Expand Down Expand Up @@ -369,7 +387,12 @@ function getInboxFolder($client, $inboxNames) {

$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);
Expand Down Expand Up @@ -434,4 +457,3 @@ function getInboxFolder($client, $inboxNames) {

// Remove the lock file
unlink($lock_file_path);
?>

0 comments on commit f57cf5c

Please sign in to comment.