Update Cron Ticket Email Parser script to take in account of multiple variations of the word inbox

This commit is contained in:
johnnyq 2024-06-22 13:45:39 -04:00
parent 1b937a0e7d
commit ee5e6d157d
1 changed files with 25 additions and 2 deletions

View File

@ -324,8 +324,31 @@ $client = $clientManager->make([
// Connect to the IMAP server
$client->connect();
$inbox = $client->getFolder('INBOX');
$messages = $inbox->query()->unseen()->get();
// 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) {
try {
$folder = $client->getFolder($name);
if ($folder) {
return $folder;
}
} catch (Exception $e) {
// Continue to the next name if the current one fails
continue;
}
}
throw new Exception("No inbox folder found.");
}
try {
$inbox = getInboxFolder($client, $inboxNames);
$messages = $inbox->query()->unseen()->get();
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
if ($messages->count() > 0) {
foreach ($messages as $message) {