From 0dd15446c8271ce6d304ee4e524f2e4165e3957e Mon Sep 17 00:00:00 2001 From: root Date: Mon, 14 Sep 2009 04:57:38 +0200 Subject: Add script localmailrecipientsdump. --- localmailrecipientsdump | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 localmailrecipientsdump (limited to 'localmailrecipientsdump') diff --git a/localmailrecipientsdump b/localmailrecipientsdump new file mode 100755 index 0000000..6662d55 --- /dev/null +++ b/localmailrecipientsdump @@ -0,0 +1,59 @@ +#!/bin/sh +# +# /usr/local/sbin/localmailrecipientsdump +# Copyright 2004-2006 Jonas Smedegaard +# +# Dump a list of all local mail destinations +# + +set -e + +pfdir="/etc/postfix" + +firstitem() { + set -e + file="$1" + + cat "$file" | grep -v '^#' | sed 's/#.*//' | head -n 1 +} + +localdomains() { + set -e + postconf -h mydestination | tr ',' ' ' +} + +aliasmaps() { + set -e + postconf -h alias_maps | tr ',' ' ' +} + +virtualmaps() { + set -e + perl -ne 's/^virtual_maps\s*=\s*// and print' < /etc/postfix/main.cf | tr ',' ' ' +} + +accounts() { + set -e + ( + getent passwd | perl -ne 's/:.*// and s/^([a-z]\S*).*/$1/ and print' + for map in $(aliasmaps); do + postalias -s $map | perl -ne 's/^([a-z]\S*):.*/$1/ and print' + done + ) | sort -u +} + +mkrecipientsmap() { + for domain in $(localdomains); do + for account in $(accounts); do + echo "$account@$domain OK" + done + done + for map in $(virtualmaps); do + postmap -s $map | perl -ne 's/^([a-z]\S*\@\S+)\s.*/$1 OK/ and print' + done +} + +redpill="$(firstitem "/etc/local-ORG/redpill")" +realm="$(firstitem "/etc/local-ORG/realm")" + +mkrecipientsmap | sort -t@ -k2 -k1 > "/etc/local-$redpill/$realm/mailrecipients" -- cgit v1.2.3