summaryrefslogtreecommitdiff
path: root/localmailrecipientsdump
blob: 6662d555843514a1b3d6d69a94f35185f24a7dfd (plain)
  1. #!/bin/sh
  2. #
  3. # /usr/local/sbin/localmailrecipientsdump
  4. # Copyright 2004-2006 Jonas Smedegaard <dr@jones.dk>
  5. #
  6. # Dump a list of all local mail destinations
  7. #
  8. set -e
  9. pfdir="/etc/postfix"
  10. firstitem() {
  11. set -e
  12. file="$1"
  13. cat "$file" | grep -v '^#' | sed 's/#.*//' | head -n 1
  14. }
  15. localdomains() {
  16. set -e
  17. postconf -h mydestination | tr ',' ' '
  18. }
  19. aliasmaps() {
  20. set -e
  21. postconf -h alias_maps | tr ',' ' '
  22. }
  23. virtualmaps() {
  24. set -e
  25. perl -ne 's/^virtual_maps\s*=\s*// and print' < /etc/postfix/main.cf | tr ',' ' '
  26. }
  27. accounts() {
  28. set -e
  29. (
  30. getent passwd | perl -ne 's/:.*// and s/^([a-z]\S*).*/$1/ and print'
  31. for map in $(aliasmaps); do
  32. postalias -s $map | perl -ne 's/^([a-z]\S*):.*/$1/ and print'
  33. done
  34. ) | sort -u
  35. }
  36. mkrecipientsmap() {
  37. for domain in $(localdomains); do
  38. for account in $(accounts); do
  39. echo "$account@$domain OK"
  40. done
  41. done
  42. for map in $(virtualmaps); do
  43. postmap -s $map | perl -ne 's/^([a-z]\S*\@\S+)\s.*/$1 OK/ and print'
  44. done
  45. }
  46. redpill="$(firstitem "/etc/local-ORG/redpill")"
  47. realm="$(firstitem "/etc/local-ORG/realm")"
  48. mkrecipientsmap | sort -t@ -k2 -k1 > "/etc/local-$redpill/$realm/mailrecipients"