From a13e77e86aa323ff7dc2d5a85924655787928336 Mon Sep 17 00:00:00 2001 From: Yannick nsenga Date: Mon, 27 May 2024 16:30:46 +0200 Subject: [PATCH] Auto detect IMAP special folders when configuring account (#1022) * Auto detect IMAP special folders when configuring account --- modules/core/handler_modules.php | 6 +++- modules/core/setup.php | 2 ++ modules/core/site.js | 57 ++++++++++++++++++++------------ modules/imap_folders/modules.php | 1 + modules/nux/modules.php | 6 ++-- modules/nux/setup.php | 4 +-- modules/nux/site.js | 10 +++--- 7 files changed, 56 insertions(+), 30 deletions(-) diff --git a/modules/core/handler_modules.php b/modules/core/handler_modules.php index 3dd1bfef7c..adf089e71c 100644 --- a/modules/core/handler_modules.php +++ b/modules/core/handler_modules.php @@ -1101,8 +1101,12 @@ public function process() { add_profile($profileName, $profileSignature, $profileReplyTo, $profileIsDefault, $email, $imapAddress, $this->smtp_server_id, $this->imap_server_id, $this); } - Hm_Msgs::add("Server saved"); + if ($this->module_is_supported('imap_folders')) { + $this->out('imap_server_id', $this->imap_server_id); + $this->out('imap_service_name', $provider); + } $this->out('just_saved_credentials', true); + Hm_Msgs::add("Server saved"); } } } diff --git a/modules/core/setup.php b/modules/core/setup.php index 646816b357..73594fb494 100644 --- a/modules/core/setup.php +++ b/modules/core/setup.php @@ -217,6 +217,8 @@ 'msg_parts' => array(FILTER_UNSAFE_RAW, false), 'page_links' => array(FILTER_UNSAFE_RAW, false), 'folder_status' => array(FILTER_DEFAULT, FILTER_REQUIRE_ARRAY), + 'imap_server_id' => array(FILTER_DEFAULT, false), + 'imap_service_name' => array(FILTER_DEFAULT, false), ), 'allowed_cookie' => array( 'CYPHTID' => FILTER_DEFAULT, diff --git a/modules/core/site.js b/modules/core/site.js index 0f56c76b86..c1d7bc49b8 100644 --- a/modules/core/site.js +++ b/modules/core/site.js @@ -2189,27 +2189,18 @@ function submitSmtpImapServer() { Hm_Notices.show(res.router_user_msgs); if (res.just_saved_credentials) { - $('#srv_setup_stepper_stepper').find('form').trigger('reset'); - display_config_step(0); - - //Initialize the form - $("#srv_setup_stepper_profile_reply_to").val(''); - $("#srv_setup_stepper_profile_signature").val(''); - $("#srv_setup_stepper_profile_name").val(''); - $("#srv_setup_stepper_email").val(''); - $("#srv_setup_stepper_password").val(''); - $("#srv_setup_stepper_profile_is_default").prop('checked', true); - $("#srv_setup_stepper_is_sender").prop('checked', true); - $("#srv_setup_stepper_is_receiver").prop('checked', true); - $("#srv_setup_stepper_enable_sieve").prop('checked', false); - $("#srv_setup_stepper_only_jmap").prop('checked', false); - $('#step_config-imap_bloc').show(); - $('#step_config-smtp_bloc').show(); - $('#srv_setup_stepper_profile_bloc').show(); - - Hm_Utils.set_unsaved_changes(1); - Hm_Folders.reload_folders(true); - location.reload(); + if (res.imap_server_id) { + Hm_Ajax.request( + [{'name': 'hm_ajax_hook', 'value': 'ajax_imap_accept_special_folders'}, + {'name': 'imap_server_id', value: res.imap_server_id}, + {'name': 'imap_service_name', value: res.imap_service_name}], + function () { + resetQuickSetupForm(); + } + ); + } else { + resetQuickSetupForm(); + } } }, null, null, function (res) { $('#srv_setup_stepper_form_loader').addClass('hide'); @@ -2217,6 +2208,30 @@ function submitSmtpImapServer() { }); } +function resetQuickSetupForm() { + $('#srv_setup_stepper_stepper').find('form').trigger('reset'); + display_config_step(0); + + //Initialize the form + $("#srv_setup_stepper_profile_reply_to").val(''); + $("#srv_setup_stepper_profile_signature").val(''); + $("#srv_setup_stepper_profile_name").val(''); + $("#srv_setup_stepper_email").val(''); + $("#srv_setup_stepper_password").val(''); + $("#srv_setup_stepper_profile_is_default").prop('checked', true); + $("#srv_setup_stepper_is_sender").prop('checked', true); + $("#srv_setup_stepper_is_receiver").prop('checked', true); + $("#srv_setup_stepper_enable_sieve").prop('checked', false); + $("#srv_setup_stepper_only_jmap").prop('checked', false); + $('#step_config-imap_bloc').show(); + $('#step_config-smtp_bloc').show(); + $('#srv_setup_stepper_profile_bloc').show(); + + Hm_Utils.set_unsaved_changes(1); + Hm_Folders.reload_folders(true); + location.reload(); +} + function handleCreateProfileCheckboxChange(checkbox) { if(checkbox.checked) { $('#srv_setup_stepper_profile_bloc').show(); diff --git a/modules/imap_folders/modules.php b/modules/imap_folders/modules.php index 865a4f76e4..2181d16235 100644 --- a/modules/imap_folders/modules.php +++ b/modules/imap_folders/modules.php @@ -129,6 +129,7 @@ public function process() { */ class Hm_Handler_process_accept_special_folders extends Hm_Handler_Module { public function process() { + list($success, $form) = $this->process_form(array('imap_server_id', 'imap_service_name')); if ($success) { $cache = Hm_IMAP_List::get_cache($this->cache, $form['imap_server_id']); diff --git a/modules/nux/modules.php b/modules/nux/modules.php index ea57fb6e5a..5d901d09af 100644 --- a/modules/nux/modules.php +++ b/modules/nux/modules.php @@ -209,8 +209,10 @@ public function process() { $this->save_hm_msgs(); $this->session->close_early(); $this->out('nux_account_added', true); - $this->out('nux_server_id', $new_id); - $this->out('nux_service_name', $form['nux_service']); + if ($this->module_is_supported('imap_folders')) { + $this->out('nux_server_id', $new_id); + $this->out('nux_service_name', $form['nux_service']); + } } else { Hm_IMAP_List::del($new_id); diff --git a/modules/nux/setup.php b/modules/nux/setup.php index 5633c320b4..d541719711 100644 --- a/modules/nux/setup.php +++ b/modules/nux/setup.php @@ -66,8 +66,8 @@ 'nux_service_step_two' => array(FILTER_UNSAFE_RAW, false), 'service_details' => array(FILTER_UNSAFE_RAW, false), 'nux_account_added' => array(FILTER_VALIDATE_BOOLEAN, false), - 'nux_server_id' => array(FILTER_VALIDATE_INT, false), - 'nux_service_name' => array(FILTER_DEFAULT, false) + 'nux_server_id' => array(FILTER_DEFAULT, false), + 'nux_service_name' => array(FILTER_DEFAULT, false), ), 'allowed_post' => array( 'nux_service' => FILTER_DEFAULT, diff --git a/modules/nux/site.js b/modules/nux/site.js index f4549a0b2b..91b29dcedc 100644 --- a/modules/nux/site.js +++ b/modules/nux/site.js @@ -47,16 +47,18 @@ var nux_add_account = function() { var display_final_nux_step = function(res) { if (res.nux_account_added) { - if (confirm('Do you accept special folders?')) { + 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}], - false + function () { + Hm_Utils.redirect(); + } ); + } else { + Hm_Utils.redirect(); } - - Hm_Utils.redirect(); } };