Fixed printf's in test suite.
[mmh] / test / post / test-post-aliases
1 #!/bin/sh
2 ######################################################
3 #
4 # Test aliases all the way through post
5 #
6 ######################################################
7
8 set -e
9
10 if test -z "${MH_OBJ_DIR}"; then
11     srcdir=`dirname "$0"`/../..
12     MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
13 fi
14
15 . "${srcdir}/test/post/test-post-common.sh"
16
17 # Note that the last address in the blind list does not end with a
18 # semicolon.
19 cat >"${MH_TEST_DIR}/Mail/aliases" <<EOF
20 blind_list: Blind List: one, two, three
21 named.list; one@example.com, two@example.com
22 one: one@example.com
23 two: two@example.com
24 three: three@example.com
25 EOF
26
27 #### Rely on sendmail/smtp or sendmail/pipe below to override default mts.
28 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
29 cp "${MHMTSCONF}" "$mts_fakesendmail"
30 printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
31 MHMTSCONF="$mts_fakesendmail"
32
33 # $1: -mts switch selection
34 # $2: expected output
35 test_alias ()
36 {
37   if [ "$1" = 'sendmail/smtp' ]; then
38     send -draft -alias "${MH_TEST_DIR}/Mail/aliases" -mts sendmail/smtp
39
40     # fakesendmail drops the message and any cc's into this mbox.
41     mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
42     inc -silent -file "$mbox"
43     rm -f "$mbox" "$mbox.map"
44
45     # It's hard to calculate the exact Date: header post is going to
46     # use, so we'll just use sed to remove the actual date so we can easily
47     # compare it against our "correct" output.
48     sed -e 's/^Date:.*/Date:/' "`mhpath cur`" >"${testname}.actual"
49
50     check "${testname}.actual" "$2"
51
52     if [ "`mhpath cur`" != "`mhpath last`" ]; then
53       folder next >/dev/null
54       arith_eval $n + 1; n=$arith_val
55     fi
56
57   elif [ "$1" = 'sendmail/pipe' ]; then
58     set +e
59     send -draft -alias "${MH_TEST_DIR}/Mail/aliases" -mts sendmail/pipe \
60       >"${testname}.actual" 2>&1
61     if [ $? -eq 0 ]; then
62       printf '%s: sendmail/pipe should have failed but didn'"'"'t\n' "$0"
63     else
64       set -e
65       check "${testname}.actual" "$2"
66     fi
67
68   else
69     printf '%s: invalid -mts switch selection\n' "$0"
70     exit 1
71   fi
72 }
73
74
75 # check blind list
76 cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
77 From: Mr Nobody <nobody@example.com>
78 To: blind_list
79 Subject: blind list test
80
81 This is test of a blind list.
82 EOF
83 cp -p "${MH_TEST_DIR}/Mail/draft" "${MH_TEST_DIR}/Mail/draft2"
84
85 cat >"${testname}.expected" <<EOF
86 From: Mr Nobody <nobody@example.com>
87 To: Blind List: ;
88 Subject: blind list test
89 Date:
90
91 This is test of a blind list.
92 EOF
93
94 test_alias sendmail/smtp "${testname}.expected"
95
96 # Make sure the addresses were expanded correctly.
97 mv "${MH_TEST_DIR}/Mail/draft2" "${MH_TEST_DIR}/Mail/draft"
98
99 cat > "${testname}.expected" <<EOF
100 EHLO nosuchhost.example.com
101 MAIL FROM:<nobody@example.com>
102 RCPT TO:<one@example.com>
103 RCPT TO:<two@example.com>
104 RCPT TO:<three@example.com>
105 DATA
106 From: Mr Nobody <nobody@example.com>
107 To: Blind List: ;
108 Subject: blind list test
109 Date:
110
111 This is test of a blind list.
112 .
113 QUIT
114 EOF
115
116 test_post "${testname}.actual" "${testname}.expected" \
117   "-alias ${MH_TEST_DIR}/Mail/aliases"
118
119 # check named list (alias followed by ;)
120 cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
121 From: Mr Nobody <nobody@example.com>
122 To: named.list
123 Subject: named list test
124
125 This is test of a named list.
126 EOF
127
128 cat >"${testname}.expected" <<EOF
129 From: Mr Nobody <nobody@example.com>
130 To: "named.list" <one@example.com>, "named.list" <two@example.com>
131 Subject: named list test
132 Date:
133
134 This is test of a named list.
135 EOF
136
137 test_alias sendmail/smtp "${testname}.expected"
138
139 # check blind list with -mts sendmail/pipe, which should fail
140 cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
141 From: Mr Nobody <nobody@example.com>
142 To: blind_list
143 Subject: blind list test
144
145 This is test of a blind list.
146 EOF
147
148 cat >"${testname}.expected" <<EOF
149 post: blind lists not compatible with sendmail/pipe
150 send: message not delivered to anyone
151 EOF
152
153 test_alias sendmail/pipe "${testname}.expected"
154
155
156 exit ${failed:-0}