Skip to content

Commit 487f0ed

Browse files
committed
debug sieve integration
1 parent d01af29 commit 487f0ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4835
-43
lines changed

AUTO_BLOCK_FIXES.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Auto-Blocking System Fixes
2+
3+
This document describes the fixes implemented to make the auto-blocking system work properly in Cypht.
4+
5+
## Issues Fixed
6+
7+
### 1. Missing Module Dependency
8+
**Problem**: The `sievefilters` module was not enabled in the default configuration, causing all Sieve-related functions to be unavailable.
9+
10+
**Solution**: Added `sievefilters` to the modules list in `config/app.php`:
11+
```php
12+
'modules' => explode(',', env('CYPHT_MODULES','core,contacts,local_contacts,feeds,imap,smtp,account,idle_timer,calendar,themes,nux,developer,history,saved_searches,advanced_search,highlights,profiles,inline_message,imap_folders,keyboard_shortcuts,tags,sievefilters')),
13+
```
14+
15+
### 2. Missing Function Dependencies
16+
**Problem**: The auto-blocking system relied on functions that were only available when the `sievefilters` module was loaded.
17+
18+
**Solution**: Added fallback includes in `modules/imap/spam_report_utils.php`:
19+
```php
20+
// Include sievefilters functions if module is not loaded
21+
if (!function_exists('get_sieve_client_factory')) {
22+
require_once APP_PATH.'modules/sievefilters/functions.php';
23+
}
24+
```
25+
26+
### 3. Poor Error Handling
27+
**Problem**: The system didn't provide clear error messages when auto-blocking failed.
28+
29+
**Solution**: Added comprehensive error handling and logging throughout the auto-blocking process.
30+
31+
### 4. Missing Configuration Validation
32+
**Problem**: The system didn't check if IMAP servers had Sieve configuration before attempting auto-blocking.
33+
34+
**Solution**: Added validation to ensure `sieve_config_host` is configured and provide user feedback.
35+
36+
## How the Auto-Blocking System Works
37+
38+
### 1. User Interface
39+
- Users can report spam by clicking the "Report Spam" button
40+
- A modal dialog appears asking for a reason
41+
- Users can report individual messages or bulk-select multiple messages
42+
43+
### 2. Backend Processing
44+
1. **Input Validation**: Validates required fields (message UIDs, server ID, folder, spam reason)
45+
2. **Rate Limiting**: Prevents abuse using rate limiting
46+
3. **Spam Service Reporting**: Reports to enabled spam services (SpamCop, AbuseIPDB, etc.)
47+
4. **Message Movement**: Moves the reported message to the junk folder
48+
5. **Auto-Blocking**: Automatically blocks the sender if enabled
49+
50+
### 3. Auto-Blocking Process
51+
1. **Extract Sender**: Gets the sender email from message headers
52+
2. **Check Configuration**: Verifies auto-blocking is enabled and Sieve is configured
53+
3. **Create Sieve Filter**: Generates a Sieve script to block future messages
54+
4. **Apply Action**: Moves, discards, or rejects future messages from the sender
55+
5. **Save Configuration**: Updates the Sieve script on the server
56+
57+
## Configuration Requirements
58+
59+
### 1. Enable Sieve Filters Module
60+
The `sievefilters` module must be enabled in `config/app.php`.
61+
62+
### 2. Configure IMAP Server Sieve Settings
63+
Each IMAP server must have the `sieve_config_host` field configured:
64+
- Go to Settings → Servers
65+
- Edit your IMAP server
66+
- Set the "Sieve Configuration Host" field (e.g., `mail.example.com:4190`)
67+
68+
### 3. User Settings
69+
Users can configure auto-blocking behavior in Settings:
70+
- **Enable/Disable**: Toggle auto-blocking on/off
71+
- **Action**: Choose what happens to blocked messages (move to junk, discard, reject)
72+
- **Scope**: Block specific sender or entire domain
73+
74+
## Testing the System
75+
76+
Run the test script to verify the system is working:
77+
```bash
78+
php test_auto_block.php
79+
```
80+
81+
This will check:
82+
- Module availability
83+
- Required functions
84+
- PhpSieveManager classes
85+
- Email extraction
86+
- Domain extraction
87+
- Action mapping
88+
89+
## Troubleshooting
90+
91+
### Auto-blocking not working?
92+
1. **Check module**: Ensure `sievefilters` is enabled in configuration
93+
2. **Check Sieve host**: Verify `sieve_config_host` is set for your IMAP server
94+
3. **Check user settings**: Ensure auto-blocking is enabled in user settings
95+
4. **Check logs**: Look for error messages in the debug logs
96+
97+
### Common Error Messages
98+
- **"Sieve filters module not enabled"**: Enable the `sievefilters` module
99+
- **"Sieve server not configured"**: Set the `sieve_config_host` for your IMAP server
100+
- **"Failed to initialize Sieve client"**: Check your Sieve server connection
101+
- **"Failed to save Sieve script"**: Check Sieve server permissions
102+
103+
### Debug Logging
104+
The system provides detailed debug logging. Enable debug mode to see:
105+
- Auto-blocking attempts
106+
- Success/failure status
107+
- Error details
108+
- Configuration issues
109+
110+
## Files Modified
111+
112+
1. **config/app.php**: Added `sievefilters` to modules list
113+
2. **modules/imap/spam_report_utils.php**: Added error handling and fallback includes
114+
3. **modules/imap/handler_modules.php**: Added better validation and logging
115+
4. **modules/imap/site.js**: Added user feedback for warnings
116+
5. **modules/imap/output_modules.php**: Added configuration warnings
117+
118+
## Dependencies
119+
120+
- **PhpSieveManager**: Required for Sieve script generation (already included in composer.json)
121+
- **sievefilters module**: Provides Sieve client functionality
122+
- **IMAP server with Sieve support**: Required for auto-blocking to work
123+
124+
## Security Considerations
125+
126+
- Auto-blocking uses Sieve filters which run on the mail server
127+
- Rate limiting prevents abuse of the spam reporting feature
128+
- User settings allow granular control over auto-blocking behavior
129+
- All actions are logged for audit purposes

PREDEFINED_SERVICE_EDIT_BUTTONS.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Predefined Service Edit Buttons Implementation
2+
3+
## Overview
4+
This document outlines the implementation of edit buttons for the predefined spam services (SpamCop, AbuseIPDB, StopForumSpam, CleanTalk) and the disabling of the "Add New Service" button.
5+
6+
## Changes Made
7+
8+
### 1. Disabled "Add New Service" Button
9+
**Location:** `modules/imap/output_modules.php` - `Hm_Output_spam_service_management` class
10+
11+
**Change:** Commented out the "Add New Service" button to prevent users from adding custom services for now.
12+
13+
```php
14+
// Add new service button (disabled for now)
15+
// $res .= '<div class="mb-3">';
16+
// $res .= '<button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#addServiceModal">';
17+
// $res .= '<i class="bi bi-plus-circle me-1"></i>'.$this->trans('Add New Service');
18+
// $res .= '</button>';
19+
// $res .= '</div>';
20+
```
21+
22+
### 2. Added Edit Buttons to Service Settings
23+
**Location:** `modules/imap/output_modules.php` - `Hm_Output_spam_services_setting` class
24+
25+
**Change:** Added edit buttons next to each service checkbox in the spam services settings.
26+
27+
```php
28+
$res .= '<td>';
29+
$res .= '<input class="form-check-input" type="checkbox"'.$checked.' value="1" id="'.$key.'" name="'.$key.'" data-default-value="'.($defaults[$key] ? 'true' : 'false').'"/>';
30+
// Add Edit button for each service
31+
$service_id = str_replace('enable_', '', $key);
32+
$res .= '<button type="button" class="btn btn-sm btn-outline-primary ms-2" onclick="editService(\''.$service_id.'\')">';
33+
$res .= '<i class="bi bi-pencil"></i> '.$this->trans('Edit');
34+
$res .= '</button>';
35+
$res .= '</td></tr>';
36+
```
37+
38+
### 3. Created Predefined Service Modals
39+
**Location:** `modules/imap/output_modules.php` - `Hm_Output_predefined_service_modals` class
40+
41+
**Features:**
42+
- **SpamCop Modal:** Simple email endpoint configuration
43+
- **AbuseIPDB Modal:** Full API configuration with authentication
44+
- **StopForumSpam Modal:** Full API configuration with authentication
45+
- **CleanTalk Modal:** Full API configuration with authentication
46+
47+
**Each modal includes:**
48+
- Service-specific fields (email endpoint for SpamCop, API fields for others)
49+
- Current values loaded from the spam service manager
50+
- Enable/disable checkbox
51+
- Form validation
52+
- Bootstrap styling
53+
54+
### 4. Updated JavaScript for Modal Handling
55+
**Location:** `modules/imap/output_modules.php` - `Hm_Output_spam_service_management_js` class
56+
57+
**Change:** Modified the `editService()` function to handle predefined services.
58+
59+
```javascript
60+
function editService(serviceId) {
61+
// Check if it's a predefined service
62+
if (["spamcop", "abuseipdb", "stopforumspam", "cleantalk"].includes(serviceId)) {
63+
// Show predefined service modal
64+
var modal = new bootstrap.Modal(document.getElementById(serviceId + "Modal"));
65+
modal.show();
66+
return;
67+
}
68+
69+
// Handle custom services (existing logic)
70+
// ...
71+
}
72+
```
73+
74+
### 5. Added Handler for Predefined Service Updates
75+
**Location:** `modules/imap/handler_modules.php` - `Hm_Handler_update_predefined_service` class
76+
77+
**Features:**
78+
- Processes form submissions from predefined service modals
79+
- Validates service-specific fields
80+
- Updates service configuration in the spam service manager
81+
- Provides success/error feedback
82+
83+
**Supported Services:**
84+
- **SpamCop:** Email endpoint and enabled status
85+
- **AbuseIPDB:** API endpoint, method, auth type, auth header, auth value, payload template, enabled status
86+
- **StopForumSpam:** API endpoint, method, auth type, auth header, auth value, payload template, enabled status
87+
- **CleanTalk:** API endpoint, method, auth type, auth header, auth value, payload template, enabled status
88+
89+
## Service-Specific Configurations
90+
91+
### SpamCop (Email Service)
92+
- **Type:** Email
93+
- **Required Fields:** Email endpoint
94+
- **Default Endpoint:** `[email protected]`
95+
- **Default Status:** Enabled
96+
97+
### AbuseIPDB (API Service)
98+
- **Type:** API
99+
- **Required Fields:** API endpoint, HTTP method, payload template
100+
- **Optional Fields:** Authentication configuration
101+
- **Default Endpoint:** `https://api.abuseipdb.com/api/v2/report`
102+
- **Default Method:** POST
103+
- **Default Auth Type:** Header
104+
- **Default Auth Header:** Key
105+
- **Default Payload:** `{"ip": "{{ ip }}", "categories": [3], "comment": "{{ reason }}"}`
106+
- **Default Status:** Disabled
107+
108+
### StopForumSpam (API Service)
109+
- **Type:** API
110+
- **Required Fields:** API endpoint, HTTP method, payload template
111+
- **Optional Fields:** Authentication configuration
112+
- **Default Endpoint:** `https://www.stopforumspam.com/add`
113+
- **Default Method:** POST
114+
- **Default Auth Type:** Header
115+
- **Default Auth Header:** api_key
116+
- **Default Payload:** `{"email": "{{ email }}", "ip": "{{ ip }}", "evidence": "{{ reason }}"}`
117+
- **Default Status:** Disabled
118+
119+
### CleanTalk (API Service)
120+
- **Type:** API
121+
- **Required Fields:** API endpoint, HTTP method, payload template
122+
- **Optional Fields:** Authentication configuration
123+
- **Default Endpoint:** `https://moderate.cleantalk.org/api2.0`
124+
- **Default Method:** POST
125+
- **Default Auth Type:** Header
126+
- **Default Auth Header:** auth_key
127+
- **Default Payload:** `{"auth_key": "{{ auth_value }}", "method_name": "spam_check", "message": "{{ body }}", "sender_email": "{{ email }}", "sender_ip": "{{ ip }}"}`
128+
- **Default Status:** Disabled
129+
130+
## Benefits
131+
132+
1. **Simplified Interface:** Users can only edit predefined services, reducing complexity
133+
2. **Service-Specific Forms:** Each service has a tailored form with relevant fields
134+
3. **Current Value Loading:** Modals populate with existing configuration values
135+
4. **Easy Configuration:** Users can quickly configure API keys and endpoints
136+
5. **Consistent UX:** All services follow the same edit pattern
137+
6. **Validation:** Form validation ensures proper configuration
138+
139+
## Usage
140+
141+
1. Navigate to IMAP Settings in the admin interface
142+
2. Scroll to the "External Spam Reporting Services" section
143+
3. Click the "Edit" button next to any service
144+
4. Configure the service-specific fields
145+
5. Click "Update" to save changes
146+
147+
## Future Enhancements
148+
149+
- Re-enable "Add New Service" button when needed
150+
- Add service testing functionality
151+
- Add service status indicators
152+
- Add bulk service management
153+
- Add service import/export functionality

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,8 @@ Docker: [https://hub.docker.com/r/cypht/cypht](https://hub.docker.com/r/cypht/cy
4545
LinkedIn group: [https://www.linkedin.com/groups/13804559/](https://www.linkedin.com/groups/13804559/)
4646

4747
An interview with the project's founder: https://github.com/cypht-org/cypht/wiki/AMA-Jason-Munro
48+
49+
---
50+
51+
**New in this version:**
52+
- All spam reporting, rate limiting, and auto-block settings are now managed in a single **Spam Reporting** section under **Site Settings** in the web interface. This makes it easier for administrators to configure and manage all spam-related options in one place.

0 commit comments

Comments
 (0)