1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#!/bin/sh
#
# localpostproc - A sample postproc which changes the submission email server
# based on user-supplied criteria.
#
# The basic concept is that we change where we submit mail to based on the
# message contents. We use scan(1) to get out fields we care about. But
# really, you could use ANY criteria, such as environment variables,
# recipients, etc etc.
#
#
# Find the draft message, always the last argument, and whether we've
# been called with -whom; the latter sucks.
#
# The case statement has to know about switches that take arguments;
# add to this list as necessary.
#
whom=0
find_draftmessage() {
while test $# -gt 0; do
case "$1" in
-al* | -filt* | -wi* | -client | -idanno | -server | \
-partno | -saslmech | -user | -por* | -width | \
-file* | -mhl* | -mt* | -cr* | -lib* | -auth* | -sendmail)
shift
;;
-whom)
whom=1
;;
-*) ;;
*)
draftmessage="$1"
return 0
;;
esac
shift
done
echo "Cannot find draft message name in argument list"
exit 1
}
realpost="$(mhparam libexecdir)/post"
if [ $# -eq 0 ]; then
echo "Usage: [post switches] filename"
exit 1
fi
find_draftmessage "$@"
if [ $whom -eq 1 ]; then
exec "$realpost" "$@"
fi
fromhost=$(scan -format '%<{resent-from}%(host{resent-from})%|%(host{from})%>' -file "$draftmessage")
if [ $? -ne 0 ]; then
echo "Unable to run scan on draft file $draftmessage, aborting"
exit 1
fi
if [ -z "$fromhost" ]; then
echo "Could not determine hostname of From: address"
exit 1;
fi
#
# Here we use the hostname in the "from" address, but you could use anything
#
case "$fromhost" in
*host1.com)
postflags="-server smtp.host1.com -sasl -port submission"
;;
host2.com)
postflags="-server smtp.host2.com -sasl -tls -port submission"
;;
*)
echo "Don't know how to send email from $fromhost"
exit 1
;;
esac
exec "$realpost" $postflags "$@"
|