sieve generation
This commit is contained in:
@@ -1 +0,0 @@
|
||||
# Filter only local/internal deliveries (adjust to your domains)
|
||||
@@ -1,11 +0,0 @@
|
||||
# Content Filter Configuration
|
||||
# Routes local/internal mail through content filter for forwarding and auto-reply
|
||||
|
||||
# Use transport_maps for selective filtering
|
||||
# Only internal deliveries go through content filter
|
||||
# Transport map is auto-generated from postfix-accounts.cf by user-patches.sh
|
||||
transport_maps = regexp:/etc/postfix/local_transport_maps
|
||||
|
||||
# Optional: If you want ALL local deliveries to go through filter (not recommended)
|
||||
# Uncomment this line and comment out transport_maps above:
|
||||
# content_filter = smtp:[localhost]:10025
|
||||
@@ -1,32 +0,0 @@
|
||||
#
|
||||
# Content Filter Setup
|
||||
# Two additional SMTP services for content filtering
|
||||
#
|
||||
# Port 10025: Content filter input
|
||||
# Receives mail from main Postfix, passes to content_filter.py
|
||||
localhost:10025 inet n - n - - smtpd
|
||||
-o content_filter=
|
||||
-o local_recipient_maps=
|
||||
-o relay_recipient_maps=
|
||||
-o smtpd_restriction_classes=
|
||||
-o smtpd_client_restrictions=
|
||||
-o smtpd_helo_restrictions=
|
||||
-o smtpd_sender_restrictions=
|
||||
-o smtpd_recipient_restrictions=permit_mynetworks,reject
|
||||
-o mynetworks=127.0.0.0/8
|
||||
-o smtpd_authorized_xforward_hosts=127.0.0.0/8
|
||||
-o receive_override_options=no_unknown_recipient_checks
|
||||
# Port 10026: Content filter output (re-injection)
|
||||
# Receives processed mail from content_filter.py for final delivery
|
||||
localhost:10026 inet n - n - - smtpd
|
||||
-o content_filter=
|
||||
-o local_recipient_maps=
|
||||
-o relay_recipient_maps=
|
||||
-o smtpd_restriction_classes=
|
||||
-o smtpd_client_restrictions=
|
||||
-o smtpd_helo_restrictions=
|
||||
-o smtpd_sender_restrictions=
|
||||
-o smtpd_recipient_restrictions=permit_mynetworks,reject
|
||||
-o mynetworks=127.0.0.0/8,[::1]/128
|
||||
-o smtpd_authorized_xforward_hosts=127.0.0.0/8,[::1]/128
|
||||
-o receive_override_options=no_header_body_checks,no_unknown_recipient_checks
|
||||
@@ -1,117 +0,0 @@
|
||||
#!/bin/bash
|
||||
# user-patches.sh - Optimized version with dynamic transport_maps generation
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
CFG_ROOT="/tmp/docker-mailserver"
|
||||
SRC_DIR="$CFG_ROOT/postfix"
|
||||
DST_DIR="/etc/postfix"
|
||||
|
||||
echo "[user-patches.sh] Starting Postfix customizations..."
|
||||
|
||||
# Existing patches (header_checks, etc.)
|
||||
if [ -f "$SRC_DIR/header_checks" ]; then
|
||||
install -D -m 0644 "$SRC_DIR/header_checks" "$DST_DIR/header_checks"
|
||||
echo "[user-patches.sh] ✓ header_checks installed"
|
||||
fi
|
||||
|
||||
if [ -f "$SRC_DIR/smtp_header_checks" ]; then
|
||||
install -D -m 0644 "$SRC_DIR/smtp_header_checks" "$DST_DIR/maps/sender_header_filter.pcre"
|
||||
echo "[user-patches.sh] ✓ smtp_header_checks installed"
|
||||
fi
|
||||
|
||||
# NEW: Append content filter configuration to main.cf
|
||||
if [ -f "$SRC_DIR/main.cf.append" ]; then
|
||||
echo "[user-patches.sh] Appending content filter config to main.cf..."
|
||||
cat "$SRC_DIR/main.cf.append" >> "$DST_DIR/main.cf"
|
||||
echo "[user-patches.sh] ✓ main.cf updated"
|
||||
else
|
||||
echo "[user-patches.sh] ⚠ main.cf.append not found, skipping"
|
||||
fi
|
||||
|
||||
# NEW: Append content filter services to master.cf
|
||||
if [ -f "$SRC_DIR/master.cf.append" ]; then
|
||||
echo "[user-patches.sh] Appending content filter services to master.cf..."
|
||||
cat "$SRC_DIR/master.cf.append" >> "$DST_DIR/master.cf"
|
||||
echo "[user-patches.sh] ✓ master.cf updated"
|
||||
else
|
||||
echo "[user-patches.sh] ⚠ master.cf.append not found, skipping"
|
||||
fi
|
||||
|
||||
# NEW: Generate local_transport_maps dynamically from postfix-accounts.cf
|
||||
echo "[user-patches.sh] Generating local_transport_maps..."
|
||||
|
||||
TRANSPORT_MAP="$DST_DIR/local_transport_maps"
|
||||
ACCOUNTS_FILE="$CFG_ROOT/postfix-accounts.cf"
|
||||
|
||||
# Create empty transport map
|
||||
> "$TRANSPORT_MAP"
|
||||
|
||||
if [ -f "$ACCOUNTS_FILE" ]; then
|
||||
# Extract unique domains from postfix-accounts.cf
|
||||
# Format of postfix-accounts.cf: user@domain.com|{PLAIN}password
|
||||
|
||||
echo "# Auto-generated transport map for content filter" >> "$TRANSPORT_MAP"
|
||||
echo "# Generated at: $(date)" >> "$TRANSPORT_MAP"
|
||||
echo "" >> "$TRANSPORT_MAP"
|
||||
|
||||
# Extract domains and create regex patterns
|
||||
awk -F'@|\\|' '{print $2}' "$ACCOUNTS_FILE" | \
|
||||
sort -u | \
|
||||
while read -r domain; do
|
||||
if [ -n "$domain" ]; then
|
||||
# Escape dots for regex
|
||||
escaped_domain=$(echo "$domain" | sed 's/\./\\./g')
|
||||
echo "/^.*@${escaped_domain}\$/ smtp:[localhost]:10025" >> "$TRANSPORT_MAP"
|
||||
echo "[user-patches.sh] - Added filter for: $domain"
|
||||
fi
|
||||
done
|
||||
|
||||
# Compile the map
|
||||
if [ -s "$TRANSPORT_MAP" ]; then
|
||||
postmap "$TRANSPORT_MAP"
|
||||
echo "[user-patches.sh] ✓ local_transport_maps created with $(grep -c '^/' "$TRANSPORT_MAP" || echo 0) domains"
|
||||
else
|
||||
echo "[user-patches.sh] ⚠ No domains found in $ACCOUNTS_FILE"
|
||||
fi
|
||||
else
|
||||
echo "[user-patches.sh] ⚠ $ACCOUNTS_FILE not found, creating minimal transport_maps"
|
||||
|
||||
# Fallback: Create minimal config
|
||||
cat > "$TRANSPORT_MAP" << 'EOF'
|
||||
# Minimal transport map - edit manually or populate postfix-accounts.cf
|
||||
# Format: /^.*@domain\.com$/ smtp:[localhost]:10025
|
||||
|
||||
# Example (replace with your domains):
|
||||
# /^.*@example\.com$/ smtp:[localhost]:10025
|
||||
# /^.*@another\.com$/ smtp:[localhost]:10025
|
||||
EOF
|
||||
postmap "$TRANSPORT_MAP"
|
||||
fi
|
||||
|
||||
# Verify content filter script exists and is executable
|
||||
if [ -x "/usr/local/bin/content_filter.py" ]; then
|
||||
echo "[user-patches.sh] ✓ Content filter script found"
|
||||
|
||||
# Test Python dependencies
|
||||
if python3 -c "import boto3" 2>/dev/null; then
|
||||
echo "[user-patches.sh] ✓ boto3 installed"
|
||||
else
|
||||
echo "[user-patches.sh] ⚠ WARNING: boto3 not installed!"
|
||||
fi
|
||||
else
|
||||
echo "[user-patches.sh] ⚠ WARNING: content_filter.py not found or not executable!"
|
||||
fi
|
||||
|
||||
# Create log file if it doesn't exist
|
||||
if [ ! -f "/var/log/mail/content_filter.log" ]; then
|
||||
touch /var/log/mail/content_filter.log
|
||||
chown mail:mail /var/log/mail/content_filter.log
|
||||
chmod 644 /var/log/mail/content_filter.log
|
||||
echo "[user-patches.sh] ✓ Created content_filter.log"
|
||||
fi
|
||||
|
||||
echo "[user-patches.sh] Postfix customizations complete"
|
||||
|
||||
# Postfix neu laden (nachdem docker-mailserver seine eigene Konfig geladen hat)
|
||||
postfix reload || true
|
||||
Reference in New Issue
Block a user