summaryrefslogtreecommitdiff
path: root/localmailrecipientsdump
blob: d96038f1e64d7aa0a999171cb0934a3d0d33a67d (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. newmaps="$(postconf -h virtual_alias_maps)"
  26. if [ '$virtual_maps' = "$newmaps" ]; then
  27. perl -ne 's/^virtual_maps\s*=\s*// and print' < /etc/postfix/main.cf | tr ',' ' '
  28. else
  29. echo "$newmaps" | tr ',' ' '
  30. fi
  31. }
  32. accounts() {
  33. set -e
  34. (
  35. getent passwd | perl -ne 's/:.*// and s/^([a-z]\S*).*/$1/ and print'
  36. for map in $(aliasmaps); do
  37. postalias -s $map | perl -ne 's/^([a-z]\S*):.*/$1/ and print'
  38. done
  39. ) | sort -u
  40. }
  41. mkrecipientsmap() {
  42. for domain in $(localdomains); do
  43. for account in $(accounts); do
  44. echo "$account@$domain OK"
  45. done
  46. done
  47. for map in $(virtualmaps); do
  48. case $map in
  49. regexp:/etc/mail/sympa_virtual_regexp_*)
  50. # FIXME: replace catch-all with actual accounts
  51. echo "$map" | perl -ne 's,regexp:/etc/mail/sympa_virtual_regexp_(\S+).*,\@$1 OK, and print'
  52. ;;
  53. hash:*)
  54. postmap -s $map | perl -ne 's/^([a-z]\S*\@\S+)\s.*/$1 OK/ and print'
  55. ;;
  56. *)
  57. echo >&2 "Unsupported map type: $map"
  58. exit 1
  59. ;;
  60. esac
  61. done
  62. }
  63. redpill="$(firstitem "/etc/local-ORG/redpill")"
  64. realm="$(firstitem "/etc/local-ORG/realm")"
  65. mkrecipientsmap | LC_ALL=C sort -t@ -k2 -k1 > "/etc/local-$redpill/$realm/mailrecipients"