From 6bdfe1b713a182dc92d89f5b00ac6427a9c38247 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Fri, 28 Jun 2024 13:52:50 -0400 Subject: [PATCH] Add Function to convert message text from UTF7 to UTF8 possibly fix the Google Issue not sure, we need further testing --- cron_ticket_email_parser.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cron_ticket_email_parser.php b/cron_ticket_email_parser.php index fd2ba779..068b18de 100644 --- a/cron_ticket_email_parser.php +++ b/cron_ticket_email_parser.php @@ -346,6 +346,11 @@ function getInboxFolder($client, $inboxNames) { throw new Exception("No inbox folder found."); } +// Function to convert UTF-7 IMAP to UTF-8 +function convertToUtf8($text) { + return mb_convert_encoding($text, 'UTF-8', 'UTF7-IMAP'); +} + try { $inbox = getInboxFolder($client, $inboxNames); $messages = $inbox->query()->unseen()->get(); @@ -371,6 +376,11 @@ if ($messages->count() > 0) { $subject = sanitizeInput($message->getSubject() ?? 'No Subject'); $date = sanitizeInput($message->getDate() ?? date('Y-m-d H:i:s')); + + // Convert message bodies from UTF-7 to UTF-8 if needed + $html_body = convertToUtf8($message->getHtmlBody() ?? ''); + $text_body = convertToUtf8($message->getTextBody() ?? ''); + $message_body = $message->getHtmlBody() ?? ''; if (empty($message_body)) {