From 2f7328d6680716c00e0737ec5efc36a86b249542 Mon Sep 17 00:00:00 2001 From: christer kahasha <62720246+christer77@users.noreply.github.com> Date: Thu, 14 Nov 2024 17:26:52 +0100 Subject: [PATCH] [FIX]Error Ocurred when attempting Microsoft's email oauth2 setup --- modules/imap/functions.php | 2 +- modules/imap_folders/modules.php | 10 +++++----- modules/nux/modules.php | 4 +++- modules/nux/site.js | 5 +++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/imap/functions.php b/modules/imap/functions.php index 24d6048a18..3f17545ef2 100644 --- a/modules/imap/functions.php +++ b/modules/imap/functions.php @@ -1093,7 +1093,7 @@ function clear_existing_reply_details($session) { */ if (!hm_exists('imap_authed')) { function imap_authed($imap) { - return is_object($imap) && ($imap->get_state() == 'authenticated' || $imap->get_state() == 'selected'); + return is_object($imap) && ($imap->get_state() == 'authenticated' || $imap->get_state() == 'selected' || $imap->get_state() == 'connected'); }} /** diff --git a/modules/imap_folders/modules.php b/modules/imap_folders/modules.php index 4e926b7d4c..42e4783034 100644 --- a/modules/imap_folders/modules.php +++ b/modules/imap_folders/modules.php @@ -101,7 +101,7 @@ public function process() { $cache = Hm_IMAP_List::get_cache($this->cache, $form['imap_server_id']); $imap = Hm_IMAP_List::connect($form['imap_server_id'], $cache); - if (!is_object($imap) || $imap->get_state() != 'authenticated') { + if (!is_object($imap) || ($imap->get_state() != 'authenticated' && $imap->get_state() != 'connected')) { Hm_Msgs::add('ERRUnable to connect to the selected IMAP server'); return; } @@ -135,7 +135,7 @@ public function process() { $cache = Hm_IMAP_List::get_cache($this->cache, $form['imap_server_id']); $imap = Hm_IMAP_List::connect($form['imap_server_id'], $cache); - if (!is_object($imap) || $imap->get_state() != 'authenticated') { + if (!is_object($imap) || ($imap->get_state() != 'authenticated' && $imap->get_state() != 'connected')) { Hm_Msgs::add('ERRUnable to connect to the selected IMAP server'); return; } @@ -184,7 +184,7 @@ public function process() { } $cache = Hm_IMAP_List::get_cache($this->cache, $form['imap_server_id']); $imap = Hm_IMAP_List::connect($form['imap_server_id'], $cache); - if (is_object($imap) && $imap->get_state() == 'authenticated') { + if (is_object($imap) && ($imap->get_state() == 'authenticated' || $imap->get_state() == 'connected')) { $new_folder = prep_folder_name($imap, $form['folder'], false, $parent_str); if ($new_folder && $imap->create_mailbox($new_folder)) { Hm_Msgs::add('Folder created'); @@ -212,7 +212,7 @@ public function process() { if (array_key_exists('parent', $this->request->post)) { $parent_str = $this->request->post['parent']; } - if (is_object($imap) && $imap->get_state() == 'authenticated') { + if (is_object($imap) && ($imap->get_state() == 'authenticated' || $imap->get_state() == 'connected')) { $old_folder = prep_folder_name($imap, $form['folder'], true); $new_folder = prep_folder_name($imap, $form['new_folder'], false, $parent_str); if ($new_folder && $old_folder && $imap->rename_mailbox($old_folder, $new_folder)) { @@ -273,7 +273,7 @@ public function process() { if ($success) { $cache = Hm_IMAP_List::get_cache($this->cache, $form['imap_server_id']); $imap = Hm_IMAP_List::connect($form['imap_server_id'], $cache); - if (is_object($imap) && $imap->get_state() == 'authenticated') { + if (is_object($imap) && ($imap->get_state() == 'authenticated' || $imap->get_state() == 'connected')) { $del_folder = prep_folder_name($imap, $form['folder'], true); if ($this->module_is_supported('sievefilters') && $this->user_config->get('enable_sieve_filter_setting', DEFAULT_ENABLE_SIEVE_FILTER)) { if (is_mailbox_linked_with_filters($del_folder, $form['imap_server_id'], $this)) { diff --git a/modules/nux/modules.php b/modules/nux/modules.php index 905251b8dd..bb6dca8dbf 100644 --- a/modules/nux/modules.php +++ b/modules/nux/modules.php @@ -175,6 +175,7 @@ public function process() { 'user' => $form['nux_email'], 'pass' => $form['nux_pass'], ); + if ($details['sieve'] && $this->module_is_supported('sievefilters') && $this->user_config->get('enable_sieve_filter_setting', DEFAULT_ENABLE_SIEVE_FILTER)) { $imap_list['sieve_config_host'] = $details['sieve']['host'].':'.$details['sieve']['port']; $imap_list['sieve_tls'] = $details['sieve']['tls']; @@ -183,8 +184,9 @@ public function process() { if (! can_save_last_added_server('Hm_IMAP_List', $form['nux_email'])) { return; } + $imap = Hm_IMAP_List::connect($new_id, false); - if ($imap && $imap->get_state() == 'authenticated') { + if ($imap && ($imap->get_state() == 'authenticated' || $imap->get_state() == 'connected')) { if (isset($details['smtp'])) { Hm_SMTP_List::add(array( 'name' => $details['name'], diff --git a/modules/nux/site.js b/modules/nux/site.js index d7dbdef53b..c351bb0689 100644 --- a/modules/nux/site.js +++ b/modules/nux/site.js @@ -47,17 +47,18 @@ var nux_add_account = function() { var display_final_nux_step = function(res) { if (res.nux_account_added) { + console.log(res) if (res.nux_server_id) { Hm_Ajax.request( [{'name': 'hm_ajax_hook', 'value': 'ajax_imap_accept_special_folders'}, {'name': 'imap_server_id', value: res.nux_server_id}, {'name': 'imap_service_name', value: res.nux_service_name}], function () { - Hm_Utils.redirect(); + Hm_Utils.redirect('?page=servers'); } ); } else { - Hm_Utils.redirect(); + Hm_Utils.redirect('?page=servers'); } } };