Skip to content

Commit 12e396f

Browse files
committed
Changed the tale name for recipient_blacklist
1 parent d1fb40b commit 12e396f

5 files changed

Lines changed: 95 additions & 4 deletions

File tree

blacklist_table.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- MySQL table for PostfixAdmin Recipient Blacklist feature
22
-- This table stores email addresses or patterns that should be rejected/discarded
33

4-
CREATE TABLE IF NOT EXISTS `mysql_virtual_recipient_blacklist` (
4+
CREATE TABLE IF NOT EXISTS `recipient_blacklist` (
55
`id` int(11) NOT NULL AUTO_INCREMENT,
66
`address` varchar(255) NOT NULL COMMENT 'Email address or pattern (e.g., bad@domain.com or @spammer.com)',
77
`action` varchar(20) NOT NULL DEFAULT 'REJECT' COMMENT 'Action to take: REJECT, DISCARD, DEFER',
@@ -16,6 +16,6 @@ CREATE TABLE IF NOT EXISTS `mysql_virtual_recipient_blacklist` (
1616
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Recipient blacklist for email rejection/filtering';
1717

1818
-- Example entries
19-
INSERT IGNORE INTO `mysql_virtual_recipient_blacklist` (`address`, `action`, `domain`) VALUES
19+
INSERT IGNORE INTO `recipient_blacklist` (`address`, `action`, `domain`) VALUES
2020
('@spam.example.com', 'REJECT', 'example.com'),
2121
('baduser@anywhere.com', 'DISCARD', 'example.com');

config.inc.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ function language_hook($PALANG, $language) {
144144
'quota2' => 'quota2',
145145
'dkim' => 'dkim',
146146
'dkim_signing' => 'dkim_signing',
147+
'recipient_blacklist' => 'recipient_blacklist',
147148
);
148149

149150
// Site Admin
@@ -371,7 +372,8 @@ function x_struct_admin_modify($struct) {
371372
$CONF['fetchmail_struct_hook'] = '';
372373
$CONF['dkim_struct_hook'] = '';
373374
$CONF['dkim_signing_struct_hook'] = '';
374-
$CONF['mysql_virtual_recipient_blacklist_struct_hook'] = '';
375+
$CONF['recipient_blacklist_struct_hook'] = '';
376+
$CONF['mysql_virtual_recipient_blacklist_struct_hook'] = ''; // deprecated - use recipient_blacklist_struct_hook
375377

376378
/*
377379
mailbox_postcreation_hook example function

migrate_blacklist_table.sql

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
-- Migration script: mysql_virtual_recipient_blacklist → recipient_blacklist
2+
--
3+
-- This script migrates from the old table name to the new standardized name
4+
-- Run this after updating the PostfixAdmin code
5+
6+
-- Step 1: Create the new table with the correct name
7+
CREATE TABLE IF NOT EXISTS `recipient_blacklist` (
8+
`id` int(11) NOT NULL AUTO_INCREMENT,
9+
`address` varchar(255) NOT NULL COMMENT 'Email address or pattern (e.g., bad@domain.com or @spammer.com)',
10+
`action` varchar(20) NOT NULL DEFAULT 'REJECT' COMMENT 'Action to take: REJECT, DISCARD, DEFER',
11+
`domain` varchar(255) NOT NULL DEFAULT '' COMMENT 'Domain for organization/filtering',
12+
`created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
13+
`modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
14+
`active` tinyint(1) NOT NULL DEFAULT 1,
15+
PRIMARY KEY (`id`),
16+
UNIQUE KEY `address` (`address`),
17+
KEY `domain` (`domain`),
18+
KEY `active` (`active`)
19+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Recipient blacklist for email rejection/filtering';
20+
21+
-- Step 2: Migrate data from old table if it exists
22+
INSERT IGNORE INTO recipient_blacklist (address, action, domain, created, modified, active)
23+
SELECT address, action, domain, created, modified, active
24+
FROM mysql_virtual_recipient_blacklist
25+
WHERE NOT EXISTS (SELECT 1 FROM recipient_blacklist WHERE recipient_blacklist.address = mysql_virtual_recipient_blacklist.address);
26+
27+
-- Step 3: Verify data migration
28+
SELECT 'Old table count:' as info, COUNT(*) as count FROM mysql_virtual_recipient_blacklist
29+
UNION ALL
30+
SELECT 'New table count:' as info, COUNT(*) as count FROM recipient_blacklist;
31+
32+
-- Step 4: After verifying data, uncomment the following line to drop the old table
33+
-- DROP TABLE mysql_virtual_recipient_blacklist;

migrate_postfix_config.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
# Postfix configuration migration script
3+
# This script updates Postfix configuration to use the new table name
4+
5+
set -e
6+
7+
echo "Migrating Postfix configuration for recipient blacklist..."
8+
9+
# Backup current configuration
10+
cp /etc/postfix/main.cf /etc/postfix/main.cf.backup.$(date +%Y%m%d_%H%M%S)
11+
12+
# Update main.cf to use new table name
13+
if grep -q "mysql_virtual_recipient_blacklist" /etc/postfix/main.cf; then
14+
echo "Updating main.cf..."
15+
sed -i 's/mysql_virtual_recipient_blacklist/recipient_blacklist/g' /etc/postfix/main.cf
16+
echo "Updated main.cf"
17+
else
18+
echo "No references to mysql_virtual_recipient_blacklist found in main.cf"
19+
fi
20+
21+
# Rename the MySQL configuration file
22+
if [ -f /etc/postfix/mysql_virtual_recipient_blacklist.cf ]; then
23+
echo "Renaming MySQL config file..."
24+
mv /etc/postfix/mysql_virtual_recipient_blacklist.cf /etc/postfix/recipient_blacklist.cf
25+
echo "Renamed to recipient_blacklist.cf"
26+
fi
27+
28+
# Update the MySQL config file content
29+
if [ -f /etc/postfix/recipient_blacklist.cf ]; then
30+
echo "Updating MySQL config file content..."
31+
sed -i 's/mysql_virtual_recipient_blacklist/recipient_blacklist/g' /etc/postfix/recipient_blacklist.cf
32+
echo "Updated recipient_blacklist.cf"
33+
fi
34+
35+
# Check configuration
36+
echo "Checking Postfix configuration..."
37+
postfix check
38+
39+
if [ $? -eq 0 ]; then
40+
echo "Configuration check passed!"
41+
echo "Reloading Postfix..."
42+
postfix reload
43+
echo "Migration completed successfully!"
44+
else
45+
echo "Configuration check failed! Please review the changes."
46+
exit 1
47+
fi
48+
49+
echo ""
50+
echo "Migration Summary:"
51+
echo "- Updated table name from mysql_virtual_recipient_blacklist to recipient_blacklist"
52+
echo "- Updated Postfix main.cf configuration"
53+
echo "- Renamed MySQL config file"
54+
echo "- Reloaded Postfix configuration"
55+
echo ""
56+
echo "Please run the database migration script (migrate_blacklist_table.sql) to complete the process."

model/BlacklistHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
class BlacklistHandler extends PFAHandler
77
{
8-
protected $db_table = 'mysql_virtual_recipient_blacklist';
8+
protected $db_table = 'recipient_blacklist';
99
protected $id_field = 'address';
1010
protected $domain_field = 'domain';
1111
protected $order_by = 'address';

0 commit comments

Comments
 (0)