Skip to content

Commit

Permalink
Fix adding one server multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
josaphatim committed Jun 5, 2024
1 parent 5054d17 commit 210cbf5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
22 changes: 22 additions & 0 deletions modules/core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,28 @@ function in_server_list($list, $id, $user) {
return $exists;
}}

/**
* Perform a check on last added server
* It gets delete if already configured
*
* @param string $list class to process on check
* @param string $user username to check for
* @return string|false
*/
if (!hm_exists('can_save_last_added_server')) {
function can_save_last_added_server($list, $user) {
$servers = $list::dump(false, true);
$ids = array_keys($servers);
$new_id = array_pop($ids);
if (in_server_list($list, $new_id, $user)) {
$list::del($new_id);
$type = explode('_', $list)[1];
Hm_Msgs::add('ERRThis ' . $type . ' server and username are already configured');
return false;
}
return true;
}}

/**
* @subpackage core/functions
*/
Expand Down
1 change: 0 additions & 1 deletion modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,6 @@ function submitSmtpImapServer() {
Hm_Ajax.request(requestData, function(res) {
$('#srv_setup_stepper_form_loader').addClass('hide');
$('.step_config-actions').removeClass('hide');
Hm_Notices.show(res.router_user_msgs);

if (res.just_saved_credentials) {
if (res.imap_server_id) {
Expand Down
4 changes: 4 additions & 0 deletions modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,10 @@ function connect_to_imap_server($address, $name, $port, $user, $pass, $tls, $ima
}

$imap_server_id = Hm_IMAP_List::add($imap_list);
if (! can_save_last_added_server('Hm_IMAP_List', $user)) {
return;
}

$server = Hm_IMAP_List::get($imap_server_id, false);

if ($enableSieve &&
Expand Down
18 changes: 4 additions & 14 deletions modules/nux/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,8 @@ public function process() {
if ($details['sieve'] && $this->module_is_supported('sievefilters') && $this->user_config->get('enable_sieve_filter_setting', true)) {
$imap_list['sieve_config_host'] = $details['sieve']['host'].':'.$details['sieve']['port'];
}
Hm_IMAP_List::add($imap_list);
$servers = Hm_IMAP_List::dump(false, true);
$ids = array_keys($servers);
$new_id = array_pop($ids);
if (in_server_list('Hm_IMAP_List', $new_id, $form['nux_email'])) {
Hm_IMAP_List::del($new_id);
Hm_Msgs::add('ERRThis IMAP server and username are already configured');
$new_id = Hm_IMAP_List::add($imap_list);
if (! can_save_last_added_server('Hm_IMAP_List', $form['nux_email'])) {
return;
}
$imap = Hm_IMAP_List::connect($new_id, false);
Expand All @@ -192,13 +187,8 @@ public function process() {
'user' => $form['nux_email'],
'pass' => $form['nux_pass']
));
$this->session->record_unsaved('SMTP server added');
$smtp_servers = Hm_SMTP_List::dump(false, true);
$ids = array_keys($servers);
$new_smtp_id = array_pop($ids);
if (in_server_list('Hm_SMTP_List', $new_smtp_id, $form['nux_email'])) {
Hm_SMTP_List::del($new_smtp_id);
Hm_Msgs::add('ERRThis SMTP server and username are already configured');
if (can_save_last_added_server('Hm_SMTP_List', $form['nux_email'])) {
$this->session->record_unsaved('SMTP server added');
}
}
Hm_IMAP_List::clean_up();
Expand Down
3 changes: 3 additions & 0 deletions modules/smtp/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ function connect_to_smtp_server($address, $name, $port, $user, $pass, $tls, $con
'tls' => $tls);

$smtp_server_id = Hm_SMTP_List::add($smtp_list);
if (! can_save_last_added_server('Hm_SMTP_List', $user)) {
return;
}

$smtp = Hm_SMTP_List::connect($smtp_server_id, false);
if (smtp_authed($smtp)) {
Expand Down

0 comments on commit 210cbf5

Please sign in to comment.