Skip to content

Commit f4eb59b

Browse files
committed
Added possibility to edit server data
1 parent 262f39f commit f4eb59b

File tree

11 files changed

+232
-62
lines changed

11 files changed

+232
-62
lines changed

lib/repository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function add($entity, $save = true) {
5555

5656
public static function edit($id, $entity) {
5757
if (array_key_exists($id, self::$entities)) {
58-
self::$entities[$id] = $entity;
58+
self::$entities[$id] = array_merge(self::$entities[$id], $entity);
5959
self::save();
6060
return true;
6161
}

modules/core/functions.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,20 @@ function can_save_last_added_server($list, $user) {
567567
return true;
568568
}}
569569

570+
if (!hm_exists('same_smtp_imap_server')) {
571+
function same_smtp_imap_server($list, $user) {
572+
$servers = $list::get(false, true);
573+
$ids = array_keys($servers);
574+
$new_id = array_pop($ids);
575+
if (in_server_list($list, $new_id, $user)) {
576+
$list::del($new_id);
577+
$type = explode('_', $list)[1];
578+
Hm_Msgs::add('ERRThis ' . $type . ' server and username are already configured');
579+
return false;
580+
}
581+
return true;
582+
}}
583+
570584
/**
571585
* @subpackage core/functions
572586
*/

modules/core/handler_modules.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,10 @@ public function process() {
991991
'srv_setup_stepper_profile_reply_to',
992992
'srv_setup_stepper_imap_sieve_host',
993993
'srv_setup_stepper_only_jmap',
994-
'srv_setup_stepper_jmap_hide_from_c_page',
994+
'srv_setup_stepper_imap_hide_from_c_page',
995995
'srv_setup_stepper_jmap_address',
996+
'srv_setup_stepper_imap_server_id',
997+
'srv_setup_stepper_smtp_server_id',
996998
));
997999

9981000
if ($success) {
@@ -1017,8 +1019,10 @@ public function process() {
10171019
'srv_setup_stepper_profile_reply_to' => $profileReplyTo,
10181020
'srv_setup_stepper_imap_sieve_host' => $imapSieveHost,
10191021
'srv_setup_stepper_only_jmap' => $onlyJmap,
1020-
'srv_setup_stepper_jmap_hide_from_c_page' => $jmapHideFromCPage,
1022+
'srv_setup_stepper_imap_hide_from_c_page' => $hideFromCombinedView,
10211023
'srv_setup_stepper_jmap_address' => $jmapAddress,
1024+
'srv_setup_stepper_imap_server_id' => $imapServerId,
1025+
'srv_setup_stepper_smtp_server_id' => $smtpServerId
10221026
] = $form;
10231027

10241028
/*
@@ -1041,30 +1045,37 @@ public function process() {
10411045
false,
10421046
'jmap',
10431047
$this,
1044-
$jmapHideFromCPage
1048+
$hideFromCombinedView,
1049+
$imapServerId
10451050
);
10461051

1052+
if(!isset($this->jmap_server_id)) {
1053+
Hm_Msgs::add("ERRCould not save JMAP server");
1054+
return;
1055+
};
1056+
10471057
Hm_Msgs::add("JMAP Server saved");
10481058
$this->out('just_saved_credentials', true);
1059+
return;
10491060
} else {
10501061
/*
1051-
* Connect to SMTP server if user wants to send emails
1052-
*/
1062+
* Connect to SMTP server if user wants to send emails
1063+
*/
10531064
if($isSender){
10541065
if (!$this->module_is_supported('smtp')) {
10551066
Hm_Msgs::add("ERRSMTP module is not enabled");
10561067
return;
10571068
}
1058-
1059-
$this->smtp_server_id = connect_to_smtp_server($smtpAddress, $profileName, $smtpPort, $email, $password, $smtpTls, $this);
1069+
$this->smtp_server_id = connect_to_smtp_server($smtpAddress, $profileName, $smtpPort, $email, $password, $smtpTls, $smtpServerId);
10601070
if(!isset($this->smtp_server_id)){
1071+
Hm_Msgs::add("ERRCould not save server");
10611072
return;
10621073
}
10631074
}
10641075

10651076
/*
1066-
* Connect to IMAP server if user wants to receive emails
1067-
*/
1077+
* Connect to IMAP server if user wants to receive emails
1078+
*/
10681079
if($isReceiver){
10691080
if (!$this->module_is_supported('imap')) {
10701081
Hm_Msgs::add("ERRIMAP module is not enabled");
@@ -1081,18 +1092,21 @@ public function process() {
10811092
$imapSieveHost,
10821093
$enableSieve,
10831094
'imap',
1084-
$this
1095+
$this,
1096+
$hideFromCombinedView,
1097+
$imapServerId,
10851098
);
10861099

10871100
if(!isset($this->imap_server_id)) {
10881101
if($isSender && isset($this->smtp_server_id)){
10891102
delete_smtp_server($this->smtp_server_id, $this);
10901103
}
1104+
Hm_Msgs::add("ERRCould not save server");
10911105
return;
10921106
};
10931107
}
10941108

1095-
if($isSender && $isReceiver && $createProfile && isset($this->imap_server_id) && isset($this->smtp_server_id)) {
1109+
if($isSender && $isReceiver && $createProfile && isset($this->imap_server_id) && isset($this->smtp_server_id) && ! ($smtpServerId || $imapServerId)) {
10961110
if (!$this->module_is_supported('profiles')) {
10971111
Hm_Msgs::add("ERRProfiles module is not enabled");
10981112
return;

modules/core/output_modules.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,8 @@ protected function output() {
21512151
<div>
21522152
<form class=" me-0" method="POST">
21532153
<input type="hidden" name="hm_page_key" value="'.$this->html_safe(Hm_Request_Key::generate()).'" />
2154+
<input type="hidden" name="srv_setup_stepper_imap_server_id" id="srv_setup_stepper_imap_server_id" />
2155+
<input type="hidden" name="srv_setup_stepper_smtp_server_id" id="srv_setup_stepper_smtp_server_id" />
21542156
<div class="form-floating mb-3">
21552157
<input required type="text" id="srv_setup_stepper_profile_name" name="srv_setup_stepper_profile_name" class="txt_fld form-control" value="" placeholder="'.$this->trans('Name').'">
21562158
<label class="" for="srv_setup_stepper_profile_name">'.$this->trans('Name').'</label>
@@ -2169,7 +2171,7 @@ protected function output() {
21692171
</form>
21702172
</div>
21712173
<div class="step_config-actions mt-4 d-flex justify-content-between">
2172-
<button class="btn btn-primary px-5" onclick="display_config_step(0)">'.$this->trans('Cancel').'</button>
2174+
<button class="btn btn-primary px-5" onclick="display_config_step(0);resetQuickSetupForm();">'.$this->trans('Cancel').'</button>
21732175
<button class="btn btn-primary px-5" onclick="display_config_step(2)">'.$this->trans('Next').'</button>
21742176
</div>
21752177
</div>
@@ -2236,19 +2238,14 @@ protected function output() {
22362238

22372239
$res .= '</form>
22382240
</div>
2239-
<div class="srv_setup_stepper_form_loader hide" id="srv_setup_stepper_form_loader">
2240-
<div class="spinner-border text-dark" role="status">
2241-
<span class="visually-hidden">Loading...</span>
2242-
</div>
2243-
</div>
22442241
<div class="step_config-actions mt-4 d-flex justify-content-between">
2245-
<button class="btn btn-danger px-3" onclick="display_config_step(0)">'.$this->trans('Cancel').'</button>
2242+
<button class="btn btn-danger px-3" onclick="display_config_step(0);resetQuickSetupForm();">'.$this->trans('Cancel').'</button>
22462243
<button class="btn btn-primary px-4" onclick="display_config_step(1)">'.$this->trans('Previous').'</button>
2247-
<button class="btn btn-primary px-3" onclick="display_config_step(3)">'.$this->trans('Finish').'</button>
2244+
<button class="btn btn-primary px-3" onclick="display_config_step(3)" id="stepper-action-finish">'.$this->trans('Finish').'</button>
22482245
</div>
22492246
</div>
22502247
<div id="step_config_0" class="step_config current_config_step">
2251-
<button class="btn btn-primary px-4" onclick="display_config_step(1)"><i class="bi bi-plus-square-fill me-2"></i> '.$this->trans('Add a new server').'</button>
2248+
<button class="imap-jmap-smtp-btn btn btn-primary px-4" onclick="display_config_step(1)"><i class="bi bi-plus-square-fill me-2"></i> '.$this->trans('Add a new server').'</button>
22522249
</div>
22532250
</div>
22542251
</div>

modules/core/setup.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@
310310
'drafts_per_source' => FILTER_DEFAULT,
311311
'drafts_since' => FILTER_DEFAULT,
312312
'warn_for_unsaved_changes' => FILTER_VALIDATE_BOOLEAN,
313+
'srv_setup_stepper_imap_server_id' => FILTER_DEFAULT,
314+
'srv_setup_stepper_smtp_server_id' => FILTER_DEFAULT,
313315
'srv_setup_stepper_profile_name' => FILTER_DEFAULT,
314316
'srv_setup_stepper_email' => FILTER_DEFAULT,
315317
'srv_setup_stepper_password' => FILTER_UNSAFE_RAW,
@@ -330,6 +332,7 @@
330332
'srv_setup_stepper_imap_sieve_host' => FILTER_DEFAULT,
331333
'srv_setup_stepper_only_jmap' => FILTER_VALIDATE_BOOLEAN,
332334
'srv_setup_stepper_jmap_hide_from_c_page' => FILTER_VALIDATE_BOOLEAN,
333-
'srv_setup_stepper_jmap_address' => FILTER_DEFAULT
335+
'srv_setup_stepper_jmap_address' => FILTER_DEFAULT,
336+
'srv_setup_stepper_imap_hide_from_c_page' => FILTER_VALIDATE_BOOLEAN
334337
)
335338
);

0 commit comments

Comments
 (0)