From b0c5d4386756e7b6cd813adfdc460f19ae416a55 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Tue, 25 Jun 2024 15:48:56 -0400 Subject: [PATCH] Remove the reliance on php-imap extension to test imap connection in setting. Also removed the check for php-imap in the mai, parser as we use fully rely on webklex --- cron_ticket_email_parser.php | 5 ----- post/setting.php | 29 ++++++++++++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/cron_ticket_email_parser.php b/cron_ticket_email_parser.php index 07a4e321..fd930d14 100644 --- a/cron_ticket_email_parser.php +++ b/cron_ticket_email_parser.php @@ -41,11 +41,6 @@ if ($argv[1] !== $config_cron_key) { exit("Cron Key invalid -- Quitting.."); } -// Check IMAP extension works/installed -if (!function_exists('imap_open')) { - exit("Email Parser: PHP IMAP extension is not installed. See https://docs.itflow.org/ticket_email_parse -- Quitting.."); -} - // Get system temp directory $temp_dir = sys_get_temp_dir(); diff --git a/post/setting.php b/post/setting.php index 60d7625a..726c60df 100644 --- a/post/setting.php +++ b/post/setting.php @@ -198,17 +198,32 @@ if (isset($_POST['test_email_imap'])) { validateCSRFToken($_POST['csrf_token']); validateAdminRole(); - // Prepare connection string with encryption (TLS/SSL/) - $imap_mailbox = "$config_imap_host:$config_imap_port/imap/readonly/$config_imap_encryption"; + // Autoload Composer dependencies + require_once __DIR__ . '/plugins/php-imap/vendor/autoload.php'; - // Connect - $imap = imap_open("{{$imap_mailbox}}INBOX", $config_imap_username, $config_imap_password); + // Webklex PHP-IMAP + use Webklex\PHPIMAP\ClientManager; + + try { + // 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(); - if ($imap) { $_SESSION['alert_message'] = "Connected successfully"; - } else { + } catch (Exception $e) { $_SESSION['alert_type'] = "error"; - $_SESSION['alert_message'] = "Test IMAP connection failed"; + $_SESSION['alert_message'] = "Test IMAP connection failed: " . $e->getMessage(); } header("Location: " . $_SERVER["HTTP_REFERER"]);