email-amazon/DMS/docker-data/dms/config/user-patches.sh

53 lines
2.0 KiB
Bash

#!/bin/bash
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.)
install -D -m 0644 "$SRC_DIR/header_checks" "$DST_DIR/header_checks"
install -D -m 0644 "$SRC_DIR/smtp_header_checks" "$DST_DIR/maps/sender_header_filter.pcre"
# 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: Create and postmap local_transport_maps for selective filtering
echo "[user-patches.sh] Creating local_transport_maps..."
install -D -m 0644 /dev/null "$DST_DIR/local_transport_maps"
cat > "$DST_DIR/local_transport_maps" << 'EOF'
# Filter only local/internal deliveries (adjust to your domains)
/^.*@example\.com$/ smtp:[localhost]:10025 # Replace with your domains, e.g. /^.*@andreasknuth\.de$/
/^.*@another-domain\.com$/ smtp:[localhost]:10025
EOF
postmap "$DST_DIR/local_transport_maps"
echo "[user-patches.sh] ✓ local_transport_maps created and mapped"
# 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"
else
echo "[user-patches.sh] ⚠ WARNING: content_filter.py not found or not executable!"
fi
echo "[user-patches.sh] Postfix customizations complete"
# Postfix neu laden (nachdem docker-mailserver seine eigene Konfig geladen hat)
postfix reload || true