Skip to content

Commit

Permalink
Auto detect IMAP special folders when configuring account (cypht-org#…
Browse files Browse the repository at this point in the history
…1022)

* Auto detect IMAP special folders when configuring account
  • Loading branch information
Yannick243 authored May 27, 2024
1 parent b2d599d commit a13e77e
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 30 deletions.
6 changes: 5 additions & 1 deletion modules/core/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions modules/core/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
57 changes: 36 additions & 21 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -2189,34 +2189,49 @@ 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');
$('.step_config-actions').removeClass('hide');
});
}

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();
Expand Down
1 change: 1 addition & 0 deletions modules/imap_folders/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
6 changes: 4 additions & 2 deletions modules/nux/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions modules/nux/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions modules/nux/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};

Expand Down

0 comments on commit a13e77e

Please sign in to comment.