postfix-bogofilter 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/sh
  2. FILTER=/usr/bin/bogofilter
  3. # Attempt to read from bogofilter configuration.
  4. FILTER_DIR=$(cat /etc/bogofilter.cf | sed 's/#.*//g' | grep ^bogofilter_dir | awk -F = '{ print $2 }')
  5. # WARNING! The -i is crucial, else you may see
  6. # messages truncated at the first period that is alone on a line
  7. # (which can happen with several kinds of messages, particularly
  8. # quoted-printable)
  9. # -G is ignored before Postfix 2.3 and tells it that the message
  10. # does not originate on the local system (Gateway submission),
  11. # so Postfix avoids some of the local expansions that can leave
  12. # misleading traces in headers, such as local address
  13. # canonicalizations.
  14. POSTFIX="/usr/sbin/sendmail -G -i"
  15. # No bogofilter_dir set in /etc/bogofilter.cf; fall back on directory
  16. # which persists across reboots.
  17. if [ -z "$FILTER_DIR" ]; then
  18. FILTER_DIR=/etc/bogofilter
  19. export BOGOFILTER_DIR=$FILTER_DIR
  20. fi
  21. # Exit codes from <sysexits.h>
  22. EX_TEMPFAIL=75
  23. EX_UNAVAILABLE=69
  24. cd $FILTER_DIR || \
  25. { echo $FILTER_DIR does not exist; exit $EX_TEMPFAIL; }
  26. # Clean up when done or when aborting.
  27. trap "rm -f msg.$$ ; exit $EX_TEMPFAIL" 0 1 2 3 15
  28. # bogofilter -e returns: 0 for OK, nonzero for error
  29. rm -f msg.$$ || exit $EX_TEMPFAIL
  30. $FILTER -p -e > msg.$$ || exit $EX_TEMPFAIL
  31. exec <msg.$$ || exit $EX_TEMPFAIL
  32. rm -f msg.$$ # safe, we hold the file descriptor
  33. exec $POSTFIX "$@"
  34. exit $EX_TEMPFAIL