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