Skip to content

Commit

Permalink
[FIX]Error Ocurred when attempting Microsoft's email oauth2 setup
Browse files Browse the repository at this point in the history
  • Loading branch information
christer77 committed Nov 15, 2024
1 parent 495852c commit 2f7328d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}}

/**
Expand Down
10 changes: 5 additions & 5 deletions modules/imap_folders/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 3 additions & 1 deletion modules/nux/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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'],
Expand Down
5 changes: 3 additions & 2 deletions modules/nux/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
};
Expand Down

0 comments on commit 2f7328d

Please sign in to comment.