From 7d2158a75b6ff294146444a6e1b51170d3f43010 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Fri, 14 Jun 2024 23:21:59 -0400 Subject: mlmmj: Integration with postfix Incoming mail for an mlmmj list is caught by a virtual mapping and directed via virtual transport to the mlmmj system for processing. Outgoing mail is implicitly allowed since it originates from the localhost. The postfix entrypoint script now dynamically generates these mailing list mappings on startup from data in the mlmmj spool directory, so user configuration is minimal. In addition, the script will now sync the user's mailing list parameters into the spool directory, thus automatically creating new lists and deleting old ones. The list creation logic is implemented in a new script `make_list.sh`. This is made necessary as the mlmmj built in tooling for this must be run interactively, so we duplicate the logic. This is separate from `entrypoint.sh` mainly because we need to drop privileges to the mlmmj user while creating files. Signed-off-by: Malfurious --- postfix/entrypoint.sh | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'postfix/entrypoint.sh') diff --git a/postfix/entrypoint.sh b/postfix/entrypoint.sh index 46c06ab..afea241 100755 --- a/postfix/entrypoint.sh +++ b/postfix/entrypoint.sh @@ -1,18 +1,47 @@ #!/bin/sh -# Generate virtual mappings from user password file +users() { + sed 's/:.*$//g' /etc/userconfig/passwd +} + +## Generate virtual mappings from user password file # Incoming mail: "user@domain domain/user/" >vmailbox -# (The trailing slash indicates the directory is a maildir.) -sed 's/:.*$//g' /etc/postfix/vmailbox +# Outgoing mail: "user@domain user@domain" >vaddress +users | awk -F '@' '{printf "%s %s/%s/\n", $0, $2, $1}' >/etc/postfix/vmailbox +users | awk '{printf "%s %s\n", $0, $0}' >/etc/postfix/vaddress + +## Synchronize mailing list configuration directories +eul=$(ls /etc/userconfig/lists | sed '/ /d') # Ignore spaces and dotfiles +vsl=$(ls -A /var/spool/mlmmj) +added=$(printf '%s\n' "$vsl" "$vsl" "$eul" | sort | uniq -u) +removed=$(printf '%s\n' "$eul" "$eul" "$vsl" | sort | uniq -u) + +for list in $added; do + sudo -u mlmmj /etc/postfix/make_list.sh "$list" +done +for list in $removed; do + listdir="/var/spool/mlmmj/$list" + rm -rf "$listdir" + printf 'Deleted list directory: %s\n' "$listdir" +done -# Outgoing mail: "user@domain user@domain" >vaddress -sed 's/:.*$//g' /etc/postfix/vaddress +## Generate virtual mappings from mailing list addresses +# "address@domain list@localhost.mlmmj" >mlvirtual +# "list@localhost.mlmmj mlmmj:list" >mltransport +touch /etc/postfix/mlvirtual +touch /etc/postfix/mltransport +for list in $(ls -A /var/spool/mlmmj); do + address="/var/spool/mlmmj/$list/control/listaddress" # there could be multiple + sed "s/$/ $list@localhost.mlmmj/g" <$address >>/etc/postfix/mlvirtual + echo "$list@localhost.mlmmj mlmmj:$list" >>/etc/postfix/mltransport +done -# Generate Berkeley DB files +## Generate Berkeley DB files +postmap /etc/postfix/mltransport +postmap /etc/postfix/mlvirtual postmap /etc/postfix/vaddress postmap /etc/postfix/vmailbox postmap /etc/userconfig/aliases +## Execute postfix daemons exec /usr/sbin/postfix start-fg -- cgit v1.2.3