]> diplodocus.org Git - nmh/blob - test/post/test-post-aliases
Updates for 1.7 release.
[nmh] / 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 four: Mister Four <four@example.com>
26 EOF
27
28 #### Rely on sendmail/smtp or sendmail/pipe below to override default mts.
29 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
30 cp "${MHMTSCONF}" "$mts_fakesendmail"
31 printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
32 MHMTSCONF="$mts_fakesendmail"
33
34 # $1: -mts switch selection
35 # $2: expected output
36 test_alias ()
37 {
38 if [ "$1" = 'sendmail/smtp' ]; then
39 run_prog send -draft -alias "${MH_TEST_DIR}/Mail/aliases" -mts sendmail/smtp
40
41 # fakesendmail drops the message and any cc's into this mbox.
42 mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
43 inc -silent -file "$mbox"
44 rm -f "$mbox"
45
46 # It's hard to calculate the exact Date: header post is going to
47 # use, so we'll just use sed to remove the actual date so we can easily
48 # compare it against our "correct" output.
49 sed -e 's/^Date:.*/Date:/' "`mhpath cur`" >"${testname}.actual"
50
51 check "${testname}.actual" "$2"
52
53 if [ "`mhpath cur`" != "`mhpath last`" ]; then
54 folder next >/dev/null
55 arith_eval $n + 1; n=$arith_val
56 fi
57
58 elif [ "$1" = 'sendmail/pipe' ]; then
59 set +e
60 run_prog send -draft -alias "${MH_TEST_DIR}/Mail/aliases" \
61 -mts sendmail/pipe >"${testname}.actual" 2>&1
62 if [ $? -eq 0 ]; then
63 printf '%s: sendmail/pipe should have failed but didn'"'"'t\n' "$0"
64 else
65 set -e
66 check "${testname}.actual" "$2"
67 fi
68
69 else
70 printf '%s: invalid -mts switch selection\n' "$0"
71 exit 1
72 fi
73 }
74
75
76 # check blind list
77 cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
78 From: Mr Nobody <nobody@example.com>
79 To: blind_list
80 Subject: blind list test
81
82 This is test of a blind list.
83 EOF
84 cp -p "${MH_TEST_DIR}/Mail/draft" "${MH_TEST_DIR}/Mail/draft2"
85
86 cat >"${testname}.expected" <<EOF
87 From: Mr Nobody <nobody@example.com>
88 To: Blind List: ;
89 Subject: blind list test
90 MIME-Version: 1.0
91 Content-Type: text/plain; charset="us-ascii"
92 Date:
93
94 This is test of a blind list.
95 EOF
96
97 test_alias sendmail/smtp "${testname}.expected"
98
99 # Make sure the addresses were expanded correctly.
100 mv "${MH_TEST_DIR}/Mail/draft2" "${MH_TEST_DIR}/Mail/draft"
101
102 cat > "${testname}.expected" <<EOF
103 EHLO nosuchhost.example.com
104 MAIL FROM:<nobody@example.com>
105 RCPT TO:<one@example.com>
106 RCPT TO:<two@example.com>
107 RCPT TO:<three@example.com>
108 DATA
109 From: Mr Nobody <nobody@example.com>
110 To: Blind List: ;
111 Subject: blind list test
112 MIME-Version: 1.0
113 Content-Type: text/plain; charset="us-ascii"
114 Date:
115
116 This is test of a blind list.
117 .
118 QUIT
119 EOF
120
121 test_post "${testname}.actual" "${testname}.expected" \
122 "-alias ${MH_TEST_DIR}/Mail/aliases"
123
124 # check named list (alias followed by ;)
125 cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
126 From: Mr Nobody <nobody@example.com>
127 To: named.list
128 Subject: named list test
129
130 This is test of a named list.
131 EOF
132
133 cat >"${testname}.expected" <<EOF
134 From: Mr Nobody <nobody@example.com>
135 To: "named.list" <one@example.com>, "named.list" <two@example.com>
136 Subject: named list test
137 MIME-Version: 1.0
138 Content-Type: text/plain; charset="us-ascii"
139 Date:
140
141 This is test of a named list.
142 EOF
143
144 test_alias sendmail/smtp "${testname}.expected"
145
146 # check blind list with -mts sendmail/pipe, which should fail
147 cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
148 From: Mr Nobody <nobody@example.com>
149 To: blind_list
150 Subject: blind list test
151
152 This is test of a blind list.
153 EOF
154
155 cat >"${testname}.expected" <<EOF
156 post: blind lists not compatible with sendmail/pipe
157 send: message not delivered to anyone
158 EOF
159
160 test_alias sendmail/pipe "${testname}.expected"
161
162 # check that alias expansion happens in the From: line when doing a bcc
163 cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
164 From: four
165 To: one
166 Bcc: two
167 Subject: from bcc expansion test
168
169 This is test of from line expansion for a bcc.
170 EOF
171
172 cat >"${testname}.expected" <<EOF
173 EHLO nosuchhost.example.com
174 MAIL FROM:<four@example.com>
175 RCPT TO:<one@example.com>
176 RCPT TO:<two@example.com>
177 RSET
178 MAIL FROM:<four@example.com>
179 RCPT TO:<one@example.com>
180 DATA
181 From: Mister Four <four@example.com>
182 To: one@example.com
183 Subject: from bcc expansion test
184 MIME-Version: 1.0
185 Content-Type: text/plain; charset="us-ascii"
186 Date:
187
188 This is test of from line expansion for a bcc.
189 .
190 RSET
191 MAIL FROM:<four@example.com>
192 RCPT TO:<two@example.com>
193 DATA
194 From: Mister Four <four@example.com>
195 Date:
196 Subject: from bcc expansion test
197 BCC:
198
199 ------- Blind-Carbon-Copy
200
201 From: Mister Four <four@example.com>
202 To: one@example.com
203 Subject: from bcc expansion test
204 MIME-Version: 1.0
205 Content-Type: text/plain; charset="us-ascii"
206 Date:
207
208 This is test of from line expansion for a bcc.
209
210 ------- End of Blind-Carbon-Copy
211 .
212 QUIT
213 EOF
214
215 test_post "${testname}.actual" "${testname}.expected" \
216 "-alias ${MH_TEST_DIR}/Mail/aliases"
217
218
219 exit ${failed:-0}