Add Function to convert message text from UTF7 to UTF8 possibly fix the Google Issue not sure, we need further testing

This commit is contained in:
johnnyq 2024-06-28 13:52:50 -04:00
parent fc82dc705e
commit 6bdfe1b713
1 changed files with 10 additions and 0 deletions

View File

@ -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)) {