Skip to content

Commit 28500ea

Browse files
Baraka24Revisto
authored andcommitted
fix(frontend): use Clearer User Feedback
1 parent 8275d2d commit 28500ea

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

modules/core/output_modules.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function output() {
1818
$res = '<li class="menu_search mb-2"><form method="get">';
1919
$res .= '<div class="input-group">';
2020
if (!$this->get('hide_folder_icons')) {
21-
$res .= '<a href="?page=search" class="input-group-text" id="basic-addon1">' .
21+
$res .= '<a href="?page=search" class="input-group-text" id="basic-addon1">' .
2222
'<i class="bi bi-search"></i>' .
2323
'</a>';
2424
}
@@ -635,7 +635,7 @@ protected function output() {
635635
format_data_sources($this->get('data_sources', array()), $this);
636636

637637
if (!$this->get('disable_delete_prompt', DEFAULT_DISABLE_DELETE_PROMPT)) {
638-
$res .= 'var hm_delete_prompt = function() { return confirm("'.$this->trans('Are you sure?').'"); };';
638+
$res .= 'var hm_delete_prompt = function() { return confirm("'.$this->trans('Are you sure you wanto to delete this server?').'"); };';
639639
}
640640
else {
641641
$res .= 'var hm_delete_prompt = function() { return true; };';
@@ -1686,9 +1686,9 @@ protected function output() {
16861686
$share_folder_modal .= '</thead>';
16871687
$share_folder_modal .= '<tbody></tbody>';
16881688
$share_folder_modal .= '</table>';
1689-
1689+
16901690
$share_folder_modal .= '</div>';
1691-
1691+
16921692
$share_folder_modal .= '<div class="col-lg-4 col-md-12">';
16931693
$share_folder_modal .= '<form id="shareForm" action="" method="POST">';
16941694
$share_folder_modal .= '<input type="hidden" name="server_id" id="server_id" value="">';

modules/imap/handler_modules.php

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ public function process() {
734734

735735
if ($ceo_use_detect_ceo_fraud && hex2bin($form['folder']) == 'INBOX') {
736736
if ($this->isCeoFraud($msg['to'], $msg['subject'], $msg['preview_msg'])) {
737-
737+
738738
$folder = "Suspicious emails";
739739
if (!count($mailbox->get_mailbox_status($folder))) {
740740
$mailbox->create_folder($folder);
@@ -750,7 +750,7 @@ public function process() {
750750
$total--;
751751
}
752752
}
753-
753+
754754
if ($msg) {
755755
if (! $include_preview && isset($msg['preview_msg'])) {
756756
$msg['preview_msg'] = "";
@@ -770,18 +770,18 @@ public function process() {
770770
$this->out('do_not_flag_as_read_on_open', $this->user_config->get('unread_on_open_setting', false));
771771
}
772772
}
773-
public function isCeoFraud($email, $subject, $msg) {
773+
public function isCeoFraud($email, $subject, $msg) {
774774
// 1. Check Suspicious Terms or Requests
775775
$suspiciousTerms = explode(",", $this->user_config->get("ceo_suspicious_terms_setting"));
776776
if ($this->detectSuspiciousTerms($msg, $suspiciousTerms) || $this->detectSuspiciousTerms($subject, $suspiciousTerms)) {
777-
777+
778778
// 2. check ceo_rate_limit
779779
$amounts = $this->extractAmountFromEmail($msg);
780780
$amountLimit = $this->user_config->get("ceo_amount_limit_setting");
781781
$isUpperAmount = array_reduce($amounts, function ($carry, $value) use ($amountLimit) {
782782
return $carry || $value > $amountLimit;
783783
}, false);
784-
784+
785785
if ($isUpperAmount) {
786786
if ($this->user_config->get("ceo_use_trusted_contact_setting")) {
787787
$contacts = $this->get('contact_store');
@@ -815,16 +815,16 @@ private function isEmailInTrustedDomainList($trustedDomain, $email) {
815815
}
816816
private function extractAmountFromEmail($emailBody) {
817817
$pattern = '/\b\d+(?:,\d+)?\.?\d*\s*(?:USD|dollars?|US\$?|EUR|euros?|€|JPY|yen|¥|GBP|pounds?|£|CAD|CAD\$|AUD|AUD\$)/i';
818-
818+
819819
preg_match_all($pattern, $emailBody, $matches);
820-
820+
821821
if ($matches) {
822-
return array_map(function($value) {
823-
return floatval(preg_replace('/[^0-9]/', '', $value));
822+
return array_map(function($value) {
823+
return floatval(preg_replace('/[^0-9]/', '', $value));
824824
}, $matches[0]);
825825
}
826826
}
827-
827+
828828
}
829829

830830
/**
@@ -1135,7 +1135,7 @@ public function process() {
11351135
* @param string $folder The folder where the messages currently reside.
11361136
* @param array $specials Special folder information for handling specific actions.
11371137
* @param array $server_details Details of the server, including its unique ID and settings.
1138-
*
1138+
*
11391139
* @return array Returns an associative array with:
11401140
* - 'error' => bool Indicates if an error occurred during the operation.
11411141
* - 'moved' => array List of moved message identifiers in a specific format.
@@ -1182,7 +1182,7 @@ private function perform_action($mailbox, $action_type, $uids, $folder, $special
11821182
* @param string $action_type The action type that determines which special folder to retrieve (e.g., 'delete', 'archive').
11831183
* @param array $specials An associative array of special folder names, like 'trash', 'archive', and 'junk'.
11841184
* @param array $server_details Details of the server, including its name.
1185-
*
1185+
*
11861186
* @return string|false Returns the special folder name if found, or false if no corresponding folder is configured.
11871187
*/
11881188
private function get_special_folder($action_type, $specials, $server_details) {
@@ -1273,7 +1273,7 @@ public function process() {
12731273
$offset = 0;
12741274
$list_page = 1;
12751275
$maxPerSource = round($limit / count($data_sources));
1276-
1276+
12771277
if (isset($this->request->get['list_page'])) {
12781278
$list_page = (int) $this->request->get['list_page'];
12791279
if ($list_page && $list_page > 1) {
@@ -1373,7 +1373,7 @@ public function process() {
13731373
$offsets = explode(',', $offsets);
13741374
}
13751375
$searchTerms[] = [search_since_based_on_setting($this->user_config), $date];
1376-
1376+
13771377
$result = getCombinedMessagesLists($data_sources, [
13781378
'cache' => $this->cache,
13791379
'session' => $this->session,
@@ -1693,12 +1693,12 @@ class Hm_Handler_load_imap_folders_permissions extends Hm_Handler_Module {
16931693
*/
16941694
public function process() {
16951695
list($success, $form) = $this->process_form(array('imap_server_id','imap_folder_uid','imap_folder'));
1696-
1696+
16971697
if ($success && !empty($form['imap_server_id']) && !empty($form['imap_folder']) && !empty($form['imap_folder_uid'])) {
16981698
Hm_IMAP_List::init($this->user_config, $this->session);
16991699
$server = Hm_IMAP_List::dump($form['imap_server_id'], true);
17001700
$cache = Hm_IMAP_List::get_cache($this->cache, $form['imap_server_id']);
1701-
1701+
17021702
$imap = Hm_IMAP_List::connect($form['imap_server_id'], $cache, $server['user'], $server['pass']);
17031703
$permissions = $imap->get_acl($form['imap_folder']);
17041704
$this->out('imap_folders_permissions', $permissions);
@@ -1716,13 +1716,13 @@ class Hm_Handler_set_acl_to_imap_folders extends Hm_Handler_Module {
17161716
*/
17171717
public function process() {
17181718
list($success, $form) = $this->process_form(array('imap_server_id','imap_folder','identifier','permissions','action'));
1719-
1719+
17201720
if ($success && !empty($form['imap_server_id']) && !empty($form['identifier']) && !empty($form['permissions']) && !empty($form['action'])) {
17211721

17221722
Hm_IMAP_List::init($this->user_config, $this->session);
17231723
$server = Hm_IMAP_List::dump($form['imap_server_id'], true);
17241724
$cache = Hm_IMAP_List::get_cache($this->cache, $form['imap_server_id']);
1725-
1725+
17261726
$imap = Hm_IMAP_List::connect($form['imap_server_id'], $cache, $server['user'], $server['pass']);
17271727
if($form['action'] === 'add') {
17281728
$response = $imap->set_acl($form['imap_folder'], $form['identifier'], $form['permissions']);
@@ -1903,7 +1903,7 @@ public function process() {
19031903
if (isset($this->request->post['imap_connect'])) {
19041904
list($success, $form) = $this->process_form(array('imap_server_id'));
19051905
$imap_details = Hm_IMAP_List::dump($form['imap_server_id'], true);
1906-
if ($success && $imap_details) {
1906+
if ($success && $imap_details) {
19071907
if ($this->module_is_supported('sievefilters') && $this->user_config->get('enable_sieve_filter_setting', DEFAULT_ENABLE_SIEVE_FILTER)) {
19081908
try {
19091909
list($sieve_host, $sieve_port) = parse_sieve_config_host($imap_details['sieve_config_host']);
@@ -2325,9 +2325,15 @@ public function process() {
23252325
if (isset($this->request->post['hide_imap_server'])) {
23262326
list($success, $form) = $this->process_form(array('imap_server_id'));
23272327
if ($success) {
2328-
Hm_IMAP_List::toggle_hidden($form['imap_server_id'], (bool) $this->request->post['hide_imap_server']);
2329-
Hm_Msgs::add('Hidden status updated');
2330-
$this->session->record_unsaved(sprintf('%s server hidden status updated', imap_server_type($form['imap_server_id'])));
2328+
$action = (bool) $this->request->post['hide_imap_server'];
2329+
$server_type = imap_server_type($form['imap_server_id']);
2330+
Hm_IMAP_List::toggle_hidden($form['imap_server_id'], $action);
2331+
if ($action) {
2332+
Hm_Msgs::add(sprintf('%s server has been hidden', $server_type));
2333+
} else {
2334+
Hm_Msgs::add(sprintf('%s server is now visible', $server_type));
2335+
}
2336+
$this->session->record_unsaved(sprintf('%s server visibility updated', $server_type));
23312337
}
23322338
}
23332339
}
@@ -2495,7 +2501,7 @@ function process_ceo_use_detect_ceo_fraud_callback($val) { return $val; }
24952501
function process_ceo_use_trusted_contact_callback($val) { return $val; }
24962502
function process_ceo_suspicious_terms_callback($val) { return $val; }
24972503
function process_ceo_amount_limit_callback($val) { return $val; }
2498-
2504+
24992505
process_site_setting('ceo_use_detect_ceo_fraud', $this, 'process_ceo_use_detect_ceo_fraud_callback');
25002506
process_site_setting('ceo_use_trusted_contact', $this, 'process_ceo_use_trusted_contact_callback');
25012507
process_site_setting('ceo_suspicious_terms', $this, 'process_ceo_suspicious_terms_callback');

tests/phpunit/modules/core/output_modules.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public function test_js_data() {
435435
$this->assertStringStartsWith('<script type="text/javascript" id="data-store">var globals = {};var hm_is_logged = function () { return 0; };var hm_empty_folder = function() { return "So alone"; };var hm_mobile = function() { return 0; };var hm_debug = function() { return "0"; };var hm_mailto = function() { return 0; };var hm_page_name = function() { return ""; };var hm_language_direction = function() { return "ltr"; };var hm_list_path = function() { return ""; };var hm_list_parent = function() { return ""; };var hm_msg_uid = function() { return Hm_Utils.get_from_global("msg_uid", ""); };var hm_encrypt_ajax_requests = function() { return ""; };var hm_encrypt_local_storage = function() { return ""; };var hm_web_root_path = function() { return ""; };var hm_flag_image_src = function() { return "<i class=\\"bi bi-star-half\\"></i>"; };var hm_check_dirty_flag = function() { return 0; };var hm_data_sources = function() { return []; };var hm_delete_prompt = function() { return true; };', implode($res->output_response));
436436
$test->handler_response = array();
437437
$res = $test->run();
438-
$this->assertStringStartsWith('<script type="text/javascript" id="data-store">var globals = {};var hm_is_logged = function () { return 0; };var hm_empty_folder = function() { return "So alone"; };var hm_mobile = function() { return 0; };var hm_debug = function() { return "0"; };var hm_mailto = function() { return 0; };var hm_page_name = function() { return ""; };var hm_language_direction = function() { return "ltr"; };var hm_list_path = function() { return ""; };var hm_list_parent = function() { return ""; };var hm_msg_uid = function() { return Hm_Utils.get_from_global("msg_uid", ""); };var hm_encrypt_ajax_requests = function() { return ""; };var hm_encrypt_local_storage = function() { return ""; };var hm_web_root_path = function() { return ""; };var hm_flag_image_src = function() { return "<i class=\\"bi bi-star-half\\"></i>"; };var hm_check_dirty_flag = function() { return 0; };var hm_data_sources = function() { return []; };var hm_delete_prompt = function() { return confirm("Are you sure?"); };', implode($res->output_response));
438+
$this->assertStringStartsWith('<script type="text/javascript" id="data-store">var globals = {};var hm_is_logged = function () { return 0; };var hm_empty_folder = function() { return "So alone"; };var hm_mobile = function() { return 0; };var hm_debug = function() { return "0"; };var hm_mailto = function() { return 0; };var hm_page_name = function() { return ""; };var hm_language_direction = function() { return "ltr"; };var hm_list_path = function() { return ""; };var hm_list_parent = function() { return ""; };var hm_msg_uid = function() { return Hm_Utils.get_from_global("msg_uid", ""); };var hm_encrypt_ajax_requests = function() { return ""; };var hm_encrypt_local_storage = function() { return ""; };var hm_web_root_path = function() { return ""; };var hm_flag_image_src = function() { return "<i class=\\"bi bi-star-half\\"></i>"; };var hm_check_dirty_flag = function() { return 0; };var hm_data_sources = function() { return []; };var hm_delete_prompt = function() { return confirm("Are you sure you wanto to delete this server?"); };', implode($res->output_response));
439439
}
440440
/**
441441
* @preserveGlobalState disabled

0 commit comments

Comments
 (0)