]> diplodocus.org Git - nmh/blob - test/post/test-post-aliases
Update XOAUTH2 documentation.
[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 start_test "blind list"
78 cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
79 From: Mr Nobody <nobody@example.com>
80 To: blind_list
81 Subject: blind list test
82
83 This is test of a blind list.
84 EOF
85 cp -p "${MH_TEST_DIR}/Mail/draft" "${MH_TEST_DIR}/Mail/draft2"
86
87 cat >"${testname}.expected" <<EOF
88 From: Mr Nobody <nobody@example.com>
89 To: Blind List: ;
90 Subject: blind list test
91 MIME-Version: 1.0
92 Content-Type: text/plain; charset="us-ascii"
93 Date:
94
95 This is test of a blind list.
96 EOF
97
98 test_alias sendmail/smtp "${testname}.expected"
99
100 # Make sure the addresses were expanded correctly.
101 mv "${MH_TEST_DIR}/Mail/draft2" "${MH_TEST_DIR}/Mail/draft"
102
103 cat > "${testname}.expected" <<EOF
104 EHLO nosuchhost.example.com
105 MAIL FROM:<nobody@example.com>
106 RCPT TO:<one@example.com>
107 RCPT TO:<two@example.com>
108 RCPT TO:<three@example.com>
109 DATA
110 From: Mr Nobody <nobody@example.com>
111 To: Blind List: ;
112 Subject: blind list test
113 MIME-Version: 1.0
114 Content-Type: text/plain; charset="us-ascii"
115 Date:
116
117 This is test of a blind list.
118 .
119 QUIT
120 EOF
121
122 test_post "${testname}.actual" "${testname}.expected" \
123 "-alias ${MH_TEST_DIR}/Mail/aliases"
124
125 # check named list (alias followed by ;)
126 start_test "named list (alias followed by ;)"
127 cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
128 From: Mr Nobody <nobody@example.com>
129 To: named.list
130 Subject: named list test
131
132 This is test of a named list.
133 EOF
134
135 cat >"${testname}.expected" <<EOF
136 From: Mr Nobody <nobody@example.com>
137 To: "named.list" <one@example.com>, "named.list" <two@example.com>
138 Subject: named list test
139 MIME-Version: 1.0
140 Content-Type: text/plain; charset="us-ascii"
141 Date:
142
143 This is test of a named list.
144 EOF
145
146 test_alias sendmail/smtp "${testname}.expected"
147
148 # check blind list with -mts sendmail/pipe, which should fail
149 start_test "blind list with -mts sendmail/pipe, which should fail"
150 cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
151 From: Mr Nobody <nobody@example.com>
152 To: blind_list
153 Subject: blind list test
154
155 This is test of a blind list.
156 EOF
157
158 cat >"${testname}.expected" <<EOF
159 post: blind lists not compatible with sendmail/pipe
160 send: message not delivered to anyone
161 EOF
162
163 test_alias sendmail/pipe "${testname}.expected"
164
165 # check that alias expansion happens in the From: line when doing a bcc
166 start_test "that alias expansion happens in the From: line when doing a bcc"
167 cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
168 From: four
169 To: one
170 Bcc: two
171 Subject: from bcc expansion test
172
173 This is test of from line expansion for a bcc.
174 EOF
175
176 cat >"${testname}.expected" <<EOF
177 EHLO nosuchhost.example.com
178 MAIL FROM:<four@example.com>
179 RCPT TO:<one@example.com>
180 RCPT TO:<two@example.com>
181 RSET
182 MAIL FROM:<four@example.com>
183 RCPT TO:<one@example.com>
184 DATA
185 From: Mister Four <four@example.com>
186 To: one@example.com
187 Subject: from bcc expansion test
188 MIME-Version: 1.0
189 Content-Type: text/plain; charset="us-ascii"
190 Date:
191
192 This is test of from line expansion for a bcc.
193 .
194 RSET
195 MAIL FROM:<four@example.com>
196 RCPT TO:<two@example.com>
197 DATA
198 From: Mister Four <four@example.com>
199 Date:
200 Subject: from bcc expansion test
201 BCC:
202
203 ------- Blind-Carbon-Copy
204
205 From: Mister Four <four@example.com>
206 To: one@example.com
207 Subject: from bcc expansion test
208 MIME-Version: 1.0
209 Content-Type: text/plain; charset="us-ascii"
210 Date:
211
212 This is test of from line expansion for a bcc.
213
214 ------- End of Blind-Carbon-Copy
215 .
216 QUIT
217 EOF
218
219 test_post "${testname}.actual" "${testname}.expected" \
220 "-alias ${MH_TEST_DIR}/Mail/aliases"
221
222
223 finish_test
224 exit ${failed:-0}