Skip to content

Commit 53d564b

Browse files
refactor(sieve_filters): Update sieve filters helpers
1 parent 007dce8 commit 53d564b

File tree

6 files changed

+194
-282
lines changed

6 files changed

+194
-282
lines changed

modules/core/navigation/routes.js

Lines changed: 81 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,91 +2,87 @@
22
NOTE: Handlers are registered as strings instead of functions because some modules might not be enabled, making their pages' handler functions unaccessible.
33
*/
44
const modulesRoutes = [
5-
{
6-
page: "hello_world",
7-
handler: "applyHelloWorldPageHandlers",
8-
},
9-
{
10-
page: "message_list",
11-
handler: "applyMessageListPageHandlers",
12-
},
13-
{
14-
page: "message",
15-
handler: "applyMessagePageHandlers",
16-
},
17-
{
18-
page: "compose",
19-
handler: "applyComposePageHandlers",
20-
},
21-
{
22-
page: "servers",
23-
handler: "applyServersPageHandlers",
24-
},
25-
{
26-
page: "settings",
27-
handler: "applySettingsPageHandlers",
28-
},
29-
{
30-
page: "search",
31-
handler: "applySearchPageHandlers",
32-
},
33-
{
34-
page: "home",
35-
handler: "applyHomePageHandlers",
36-
},
37-
{
38-
page: "info",
39-
handler: "applyInfoPageHandlers",
40-
},
41-
{
42-
page: "calendar",
43-
handler: "applyCalendarPageHandlers",
44-
},
45-
{
46-
page: "advanced_search",
47-
handler: "applyAdvancedSearchPageHandlers",
48-
},
49-
{
50-
page: "contacts",
51-
handler: "applyContactsPageHandlers",
52-
},
53-
{
54-
page: "history",
55-
handler: "applyHistoryPageHandlers",
56-
},
57-
{
58-
page: "folders",
59-
handler: "applyFoldersPageHandlers",
60-
},
61-
{
62-
page: "folders_subscription",
63-
handler: "applyFoldersSubscriptionPageHandlers",
64-
},
65-
{
66-
page: "pgp",
67-
handler: "applyPgpPageHandlers",
68-
},
69-
{
70-
page: "profiles",
71-
handler: "applyProfilesPageHandler",
72-
},
73-
{
74-
page: "block_list",
75-
handler: "applyBlockListPageHandlers",
76-
},
77-
{
78-
page: "sieve_filters",
79-
handler: "applySieveFiltersPageHandler",
80-
},
81-
{
82-
page: "message",
83-
handler: "applySieveFiltersPageHandler",
84-
},
85-
{
86-
page: "shortcuts",
87-
handler: "applyShortcutsPageHandlers",
88-
},
89-
];
5+
{
6+
page: 'hello_world',
7+
handler: 'applyHelloWorldPageHandlers'
8+
},
9+
{
10+
page: 'message_list',
11+
handler: 'applyMessageListPageHandlers'
12+
},
13+
{
14+
page: 'message',
15+
handler: 'applyMessagePageHandlers'
16+
},
17+
{
18+
page: 'compose',
19+
handler: 'applyComposePageHandlers'
20+
},
21+
{
22+
page: 'servers',
23+
handler: 'applyServersPageHandlers'
24+
},
25+
{
26+
page: 'settings',
27+
handler: 'applySettingsPageHandlers'
28+
},
29+
{
30+
page: 'search',
31+
handler: 'applySearchPageHandlers'
32+
},
33+
{
34+
page: 'home',
35+
handler: 'applyHomePageHandlers'
36+
},
37+
{
38+
page: 'info',
39+
handler: 'applyInfoPageHandlers'
40+
},
41+
{
42+
page: 'calendar',
43+
handler: 'applyCalendarPageHandlers'
44+
},
45+
{
46+
page: 'advanced_search',
47+
handler: 'applyAdvancedSearchPageHandlers'
48+
},
49+
{
50+
page: 'contacts',
51+
handler: 'applyContactsPageHandlers'
52+
},
53+
{
54+
page: 'history',
55+
handler: 'applyHistoryPageHandlers'
56+
},
57+
{
58+
page: 'folders',
59+
handler: 'applyFoldersPageHandlers'
60+
},
61+
{
62+
page: 'folders_subscription',
63+
handler: 'applyFoldersSubscriptionPageHandlers'
64+
},
65+
{
66+
page: 'pgp',
67+
handler: 'applyPgpPageHandlers'
68+
},
69+
{
70+
page: 'profiles',
71+
handler: 'applyProfilesPageHandler'
72+
},
73+
{
74+
page: 'block_list',
75+
handler: 'applyBlockListPageHandlers'
76+
},
77+
{
78+
page: 'sieve_filters',
79+
handler: 'applySieveFiltersPageHandler'
80+
},
81+
{
82+
page: 'shortcuts',
83+
handler: 'applyShortcutsPageHandlers'
84+
}
85+
]
9086

9187
/*
9288
Now let's validate and use handlers that are given.

modules/core/site.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2752,7 +2752,8 @@ const Hm_Filters = (function (my) {
27522752
],
27532753
function (res) {
27542754
if (Object.keys(res.script_details).length === 0) {
2755-
window.location = window.location;
2755+
window.location.href = "?page=sieve_filters";
2756+
27562757
} else {
27572758
edit_script_modal.open();
27582759
$(".modal_sieve_script_textarea").val(res.script_details.gen_script);
@@ -2941,13 +2942,15 @@ class Hm_Filter_Modal extends Hm_Modal {
29412942
this.addFooterBtn("Save", "btn-primary ms-auto", async () => {
29422943
let result = save_filter(current_account);
29432944
if (result) {
2945+
Hm_Notices.show("Filter saved", "success");
29442946
this.hide();
29452947
}
29462948
});
29472949

29482950
this.addFooterBtn("Convert to code", "btn-warning", async () => {
29492951
let result = save_filter(current_account, true);
29502952
if (result) {
2953+
Hm_Notices.show("Filter saved", "success");
29512954
this.hide();
29522955
}
29532956
});

modules/imap/output_modules.php

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -424,53 +424,55 @@ protected function output() {
424424
}
425425
}
426426

427-
$txt .= '<a class="hLink text-decoration-none btn btn-sm btn-outline-secondary dropdown-toggle" '
428-
. 'id="filter_message" href="#" data-bs-toggle="dropdown" aria-expanded="false">'
429-
. $this->trans('Filter similar messages')
430-
. '</a>'
431-
. '<div class="dropdown-menu move_to_location p-3">'
432-
. '<form id="create-filter-form" style="min-width:260px;" account="' . $mailbox_name . '">'
433-
// From (enabled, checked by default)
434-
. '<div class="form-check mb-1">'
435-
. '<input class="form-check-input" type="checkbox" id="use_from" checked>'
436-
. '<input type="hidden" name="from" value="' . htmlspecialchars($sender) . '">'
437-
. '<label class="form-check-label small" for="use_from">'
438-
. $this->trans('From:') . ' ' . htmlspecialchars($sender)
439-
. '</label>'
440-
. '</div>'
441-
442-
// To (disabled by default)
443-
. '<div class="form-check mb-1">'
444-
. '<input class="form-check-input" type="checkbox" id="use_to" >'
445-
. '<input type="hidden" name="to" value="' . htmlspecialchars($headers['To']) . '">'
446-
. '<label class="form-check-label small text-muted" for="use_to">'
447-
. $this->trans('To:') . ' ' . $headers['To']
448-
. '</label>'
449-
. '</div>'
450-
451-
// Subject (disabled by default)
452-
. '<div class="form-check mb-1">'
453-
. '<input class="form-check-input" type="checkbox" id="use_subject" >'
454-
. '<input type="hidden" name="subject" value="' . htmlspecialchars($headers['Subject']) . '">'
455-
. '<label class="form-check-label small text-muted" for="use_subject">'
456-
. $this->trans('Subject contains:') . ' ' . $headers['Subject']
457-
. '</label>'
458-
. '</div>'
459-
460-
// Reply-To (disabled by default)
461-
. '<div class="form-check mb-2">'
462-
. '<input class="form-check-input" type="checkbox" id="use_reply" >'
463-
. '<input type="hidden" name="reply-to" value="' . htmlspecialchars($headers['Reply-To']) . '">'
464-
. '<label class="form-check-label small text-muted" for="use_reply">'
465-
. $this->trans('Reply-To:') . ' ' . $headers['Reply-To']
466-
. '</label>'
467-
. '</div>'
468-
469-
. '<button type="submit" id="create_filter" class="btn btn-primary btn-sm" >'
470-
. $this->trans('Create filter')
471-
. '</button>'
472-
. '</form>'
473-
. '</div>';
427+
if ($this->get('sieve_filters_enabled')) {
428+
$txt .= '<a class="hLink text-decoration-none btn btn-sm btn-outline-secondary dropdown-toggle me-2" '
429+
. 'id="filter_message" href="#" data-bs-toggle="dropdown" aria-expanded="false">'
430+
. $this->trans('Filter similar messages')
431+
. '</a>'
432+
. '<div class="dropdown-menu move_to_location p-3">'
433+
. '<form id="create-filter-form" style="min-width:260px;" account="' . $mailbox_name . '">'
434+
// From (enabled, checked by default)
435+
. '<div class="form-check mb-1">'
436+
. '<input class="form-check-input" type="checkbox" id="use_from" checked>'
437+
. '<input type="hidden" name="from" value="' . htmlspecialchars($sender) . '">'
438+
. '<label class="form-check-label small" for="use_from">'
439+
. $this->trans('From:') . ' ' . htmlspecialchars($sender)
440+
. '</label>'
441+
. '</div>'
442+
443+
// To (disabled by default)
444+
. '<div class="form-check mb-1">'
445+
. '<input class="form-check-input" type="checkbox" id="use_to" >'
446+
. '<input type="hidden" name="to" value="' . htmlspecialchars($headers['To']) . '">'
447+
. '<label class="form-check-label small text-muted" for="use_to">'
448+
. $this->trans('To:') . ' ' . $headers['To']
449+
. '</label>'
450+
. '</div>'
451+
452+
// Subject (disabled by default)
453+
. '<div class="form-check mb-1">'
454+
. '<input class="form-check-input" type="checkbox" id="use_subject" >'
455+
. '<input type="hidden" name="subject" value="' . htmlspecialchars($headers['Subject']) . '">'
456+
. '<label class="form-check-label small text-muted" for="use_subject">'
457+
. $this->trans('Subject contains:') . ' ' . $headers['Subject']
458+
. '</label>'
459+
. '</div>'
460+
461+
// Reply-To (disabled by default)
462+
. '<div class="form-check mb-2">'
463+
. '<input class="form-check-input" type="checkbox" id="use_reply" >'
464+
. '<input type="hidden" name="reply-to" value="' . htmlspecialchars($headers['Reply-To']) . '">'
465+
. '<label class="form-check-label small text-muted" for="use_reply">'
466+
. $this->trans('Reply-To:') . ' ' . $headers['Reply-To']
467+
. '</label>'
468+
. '</div>'
469+
470+
. '<button type="submit" id="create_filter" class="btn btn-primary btn-sm" >'
471+
. $this->trans('Create filter')
472+
. '</button>'
473+
. '</form>'
474+
. '</div>';
475+
}
474476

475477
$txt .= '<a class="hlink text-decoration-none btn btn-sm btn-outline-secondary" id="show_message_source" href="#">' . $this->trans('Show Source') . '</a>';
476478

modules/imap/setup.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
add_handler('ajax_imap_message_content', 'save_imap_cache', true);
156156
add_handler('ajax_imap_message_content', 'save_imap_servers', true);
157157
add_handler('ajax_imap_message_content', 'close_session_early', true, 'core');
158-
// add_output('ajax_imap_message_content', 'filter_message_headers', true);
158+
add_output('ajax_imap_message_content', 'filter_message_headers', true);
159159
add_output('ajax_imap_message_content', 'filter_message_body', true);
160160
add_output('ajax_imap_message_content', 'filter_message_struct', true);
161161

@@ -337,6 +337,7 @@
337337
'do_not_flag_as_read_on_open' => array(FILTER_VALIDATE_BOOLEAN, false),
338338
'ajax_imap_folders_permissions' => array(FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY),
339339
'move_responses' => array(FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY),
340+
'mailbox_name' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
340341
),
341342

342343
'allowed_get' => array(

0 commit comments

Comments
 (0)