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

This commit is contained in:
johnnyq 2024-06-25 15:48:56 -04:00
parent 40866e34e2
commit b0c5d43867
2 changed files with 22 additions and 12 deletions

View File

@ -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();

View File

@ -198,17 +198,32 @@ if (isset($_POST['test_email_imap'])) {
validateCSRFToken($_POST['csrf_token']);
validateAdminRole();
// Prepare connection string with encryption (TLS/SSL/<blank>)
$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"]);