Skip to content

Commit 4fbf5d2

Browse files
committed
hardcode the auto-blocking for test
1 parent 487f0ed commit 4fbf5d2

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

modules/imap/handler_modules.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,13 +2411,16 @@ public function process() {
24112411
));
24122412

24132413
if ($imap_account && isset($imap_account['sieve_config_host'])) {
2414-
delayed_debug_log('Auto-block: Starting auto-block process');
2414+
delayed_debug_log('Auto-block: Starting auto-block process', array(
2415+
'junk_folder' => $junk_folder
2416+
));
24152417
$auto_block_result = auto_block_spam_sender(
24162418
$this->user_config,
24172419
$this->config,
24182420
$form['imap_server_id'],
24192421
$message_data,
2420-
$spam_reason
2422+
$spam_reason,
2423+
$junk_folder
24212424
);
24222425
if (!$auto_block_result['success']) {
24232426
$result['error'] .= 'Auto-block failed: ' . $auto_block_result['error'] . '; ';

modules/imap/spam_report_config.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ function is_spam_service_enabled($service_name) {
122122
* @return boolean True if auto-blocking is enabled
123123
*/
124124
function is_auto_block_spam_enabled($user_config) {
125-
return $user_config->get('auto_block_spam_sender', true);
125+
// return $user_config->get('auto_block_spam_scope', 'sender');
126+
//return $user_config->get('auto_block_spam_sender', true);
127+
// HARDCODED FOR TESTING - TODO: Revert to user_config after testing
128+
return true;
129+
// Original: return $user_config->get('auto_block_spam_sender', true);
126130
}
127131

128132
/**
@@ -131,7 +135,10 @@ function is_auto_block_spam_enabled($user_config) {
131135
* @return string Auto-block action
132136
*/
133137
function get_auto_block_spam_action($user_config) {
134-
return $user_config->get('auto_block_spam_action', 'move_to_junk');
138+
//return $user_config->get('auto_block_spam_action', 'move_to_junk');
139+
// HARDCODED FOR TESTING - TODO: Revert to user_config after testing
140+
return 'move_to_junk';
141+
// Original: return $user_config->get('auto_block_spam_action', 'move_to_junk');
135142
}
136143

137144
/**
@@ -140,5 +147,7 @@ function get_auto_block_spam_action($user_config) {
140147
* @return string Auto-block scope
141148
*/
142149
function get_auto_block_spam_scope($user_config) {
143-
return $user_config->get('auto_block_spam_scope', 'sender');
150+
// HARDCODED FOR TESTING - TODO: Revert to user_config after testing
151+
return 'sender';
152+
// Original: return $user_config->get('auto_block_spam_scope', 'sender');
144153
}

modules/imap/spam_report_utils.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
* @param string $imap_server_id IMAP server ID
1818
* @param array $message_data Message data containing sender information
1919
* @param string $spam_reason Reason for spam report
20+
* @param string $junk_folder Junk folder name (dynamically detected)
2021
* @return array Result of auto-block operation
2122
*/
22-
function auto_block_spam_sender($user_config, $site_config, $imap_server_id, $message_data, $spam_reason) {
23+
function auto_block_spam_sender($user_config, $site_config, $imap_server_id, $message_data, $spam_reason, $junk_folder = 'Junk') {
2324
try {
2425
// Check if auto-blocking is enabled
2526
if (!is_auto_block_spam_enabled($user_config)) {
@@ -139,6 +140,12 @@ function auto_block_spam_sender($user_config, $site_config, $imap_server_id, $me
139140
// Map action to Sieve action
140141
$sieve_action = map_auto_block_action_to_sieve($action, $user_config, $imap_server_id);
141142

143+
delayed_debug_log('Auto-block: Using junk folder', array(
144+
'junk_folder' => $junk_folder,
145+
'sieve_action' => $sieve_action,
146+
'action' => $action
147+
));
148+
142149
if (!is_array($blocked_senders)) {
143150
$blocked_senders = array();
144151
}
@@ -151,7 +158,8 @@ function auto_block_spam_sender($user_config, $site_config, $imap_server_id, $me
151158
$sieve_action,
152159
$imap_server_id,
153160
$blocked_sender,
154-
'Auto-blocked after spam report: ' . $spam_reason
161+
'Auto-blocked after spam report: ' . $spam_reason,
162+
$junk_folder
155163
);
156164
} elseif (is_array($blocked_list_actions) && array_key_exists($blocked_sender, $blocked_list_actions)) {
157165
$reject_message = '';
@@ -165,15 +173,18 @@ function auto_block_spam_sender($user_config, $site_config, $imap_server_id, $me
165173
$action_type,
166174
$imap_server_id,
167175
$blocked_sender,
168-
$reject_message
176+
$reject_message,
177+
$junk_folder
169178
);
170179
} else {
171180
$actions = block_filter(
172181
$filter,
173182
$user_config,
174183
'default',
175184
$imap_server_id,
176-
$blocked_sender
185+
$blocked_sender,
186+
'',
187+
$junk_folder
177188
);
178189
}
179190
if (is_array($blocked_list_actions)) {

modules/sievefilters/functions.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ function default_reject_message($user_config, $imap_server_id)
348348
}
349349

350350
if (!hm_exists('block_filter')) {
351-
function block_filter($filter, $user_config, $action, $imap_server_id, $sender, $custom_reject_message = '')
351+
function block_filter($filter, $user_config, $action, $imap_server_id, $sender, $custom_reject_message = '', $junk_folder = 'Junk')
352352
{
353353
$ret = ['action' => $action];
354354

@@ -400,8 +400,13 @@ function block_filter($filter, $user_config, $action, $imap_server_id, $sender,
400400
}
401401
elseif ($default_behaviour == 'Move') {
402402
$filter->addRequirement('fileinto');
403+
delayed_debug_log('Sieve filter: Moving to folder', array(
404+
'folder' => $junk_folder,
405+
'sender' => $sender,
406+
'action' => $action
407+
));
403408
$custom_condition->addAction(
404-
new \PhpSieveManager\Filters\Actions\FileIntoFilterAction(['mailbox' => 'Blocked'])
409+
new \PhpSieveManager\Filters\Actions\FileIntoFilterAction(['mailbox' => $junk_folder])
405410
);
406411
}
407412

0 commit comments

Comments
 (0)