Added test-anno, test-dist, test-msgchk, and test-rcvtty.
[mmh] / test / dist / test-dist
1 #!/bin/sh
2 ######################################################
3 #
4 # Test dist
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 . "$MH_OBJ_DIR/test/common.sh"
16
17 setup_test
18
19 expected=$MH_TEST_DIR/$$.expected
20 expected_err=$MH_TEST_DIR/$$.expected_err
21 actual=$MH_TEST_DIR/$$.actual
22 actual_err=$MH_TEST_DIR/$$.actual_err
23 localmbox=`${MH_LIB_DIR}/ap -format "%(localmbox)" 0`
24
25 #### Use sendmail/pipe below to override default mts.
26 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
27 sed -e 's/^mts:.*/mts: sendmail\/pipe/' "${MHMTSCONF}" > "$mts_fakesendmail"
28 printf "sendmail: ${srcdir}/test/fakesendmail\n" >>"$mts_fakesendmail"
29 MHMTSCONF="$mts_fakesendmail"
30
31 # arguments: dist switches
32 test_dist ()
33 {
34   printf "send" | dist "$@" >/dev/null
35
36   # fakesendmail drops the message and any cc's into this mbox.
37   mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
38   inc -silent -file "$mbox"
39   rm -f "$mbox" "$mbox.map"
40
41   # It's hard to calculate the exact Date: header post is going to
42   # use, so we'll just use sed to remove the actual date so we can
43   # easily compare it against our "correct" output.
44   sed -e 's/^Resent-Date:.*/Resent-Date:/' `mhpath last` > "$actual"
45
46   check "$expected" "$actual"
47 }
48
49
50 # check -help
51 cat >"$expected" <<EOF
52 Usage: dist [+folder] [msg] [switches]
53   switches are:
54   -[no]annotate
55   -draftfolder +folder
56   -draftmessage msg
57   -nodraftfolder
58   -editor editor
59   -noedit
60   -form formfile
61   -[no]inplace
62   -whatnowproc program
63   -nowhatnowproc
64   -version
65   -help
66   -from address
67   -to address
68   -cc address
69   -fcc mailbox
70   -width columns
71   -[no]atfile
72 EOF
73
74 dist -help >"$actual" 2>&1
75 check "$expected" "$actual"
76
77 # check -version
78 case `dist -v` in
79   dist\ --*) ;;
80   *        ) printf "$0: dist -v generated unexpected output\n" >&2
81              failed=`expr ${failed:-0} + 1`;;
82 esac
83
84 # check unknown switch
85 run_test "dist -nonexistent" 'dist: -nonexistent unknown'
86
87 folder +outbox -create -fast >/dev/null
88 folder +inbox -fast 1 >/dev/null
89
90 # For most tests, use -nowhatnow and just check that the draft
91 # looks correct.
92
93 # check basic dist operation, including -noedit and -to
94 cat >"$expected" <<EOF
95 From: Test1 <test1@example.com>
96 To: Some User <user@example.com>
97 Date: Fri, 29 Sep 2006 00:00:00
98 Subject: Testing message 1
99 Resent-From: ${localmbox}
100 Resent-To: somebody@example.com
101 Resent-Date:
102
103 This is message number 1
104 EOF
105
106 test_dist -noedit -to somebody@example.com
107
108 # check +folder and msg
109 folder +outbox -fast >/dev/null
110
111 cat >"$expected" <<EOF
112 From: Test1 <test1@example.com>
113 To: Some User <user@example.com>
114 Date: Fri, 29 Sep 2006 00:00:00
115 Subject: Testing message 1
116 Resent-From: ${localmbox}
117 Resent-To: somebody@example.com
118 Resent-Date:
119
120 This is message number 1
121 EOF
122
123 test_dist +inbox 1 -noedit -to somebody@example.com
124
125 # check -form
126 cat >"${MH_TEST_DIR}/Mail/distform" <<'EOF'
127 Resent-From: me@example.com
128 Resent-To: you@example.com
129 EOF
130
131 cat >"$expected" <<EOF
132 From: Test1 <test1@example.com>
133 To: Some User <user@example.com>
134 Date: Fri, 29 Sep 2006 00:00:00
135 Subject: Testing message 1
136 Resent-From: me@example.com
137 Resent-To: you@example.com
138 Resent-Date:
139
140 This is message number 1
141 EOF
142
143 test_dist 1 -noedit -form "${MH_TEST_DIR}"/Mail/distform
144
145 rm "${MH_TEST_DIR}"/Mail/distform
146
147 # check -annotate
148 cat >"$expected" <<EOF
149 From: Test2 <test2@example.com>
150 To: Some User <user@example.com>
151 Date: Fri, 29 Sep 2006 00:00:00
152 Subject: Testing message 2
153 Resent-From: ${localmbox}
154 Resent-To: somebody@example.com
155 Resent-Date:
156
157 This is message number 2
158 EOF
159
160 test_dist 2 -noedit -to somebody@example.com -annotate
161
162 cat >"$expected" <<EOF
163 Resent:
164 Resent: somebody@example.com
165 From: Test2 <test2@example.com>
166 To: Some User <user@example.com>
167 Date: Fri, 29 Sep 2006 00:00:00
168 Subject: Testing message 2
169
170 This is message number 2
171 EOF
172
173 # The annotation is done by a separate process, so we need to wait for
174 # it to complete.
175 i=1
176 until grep '^Resent:' "${MH_TEST_DIR}"/Mail/inbox/2 >/dev/null; do
177   sleep 2
178   arith_eval $i + 1
179   i=$arith_val
180   if [ $i -gt 60 ]; then
181     printf "$0: -annotate failed, will not wait any longer\n"
182     break
183   fi
184 done
185
186 # Strip date from line of this form:
187 # Resent: Sat, 06 Oct 2012 08:24:08 -0500
188 sed -e 's/^Resent:.*:.*/Resent:/' "${MH_TEST_DIR}"/Mail/inbox/2 >"$actual"
189
190 check "$expected" "$actual"
191
192 # check -noannotate
193 cat >"$expected" <<EOF
194 From: Test1 <test1@example.com>
195 To: Some User <user@example.com>
196 Date: Fri, 29 Sep 2006 00:00:00
197 Subject: Testing message 1
198 Resent-From: ${localmbox}
199 Resent-To: somebody@example.com
200 Resent-Date:
201
202 This is message number 1
203 EOF
204
205 test_dist 1 -noedit -to somebody@example.com -annotate -noannotate
206
207 cat >"$expected" <<EOF
208 From: Test1 <test1@example.com>
209 To: Some User <user@example.com>
210 Date: Fri, 29 Sep 2006 00:00:00
211 Subject: Testing message 1
212
213 This is message number 1
214 EOF
215
216 check "${MH_TEST_DIR}"/Mail/inbox/1 "$expected" 'keep first'
217
218 check_for_hard_links
219 if [ $hard_links_supported -eq 1 ]; then
220   # check -noinplace
221   # Hard link the message and verify that the new one doesn't get annotated.
222   cp "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.copy"
223   ln "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
224   cat >"$expected" <<EOF
225 From: Test8 <test8@example.com>
226 To: Some User <user@example.com>
227 Date: Fri, 29 Sep 2006 00:00:00
228 Subject: Testing message 8
229 Resent-From: ${localmbox}
230 Resent-To: somebody@example.com
231 Resent-Date:
232
233 This is message number 8
234 EOF
235   test_dist 8 -noedit -to somebody@example.com -annotate -noinplace
236   mv -f "${MH_TEST_DIR}/Mail/inbox/8.copy" "${MH_TEST_DIR}/Mail/inbox/8"
237   check "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link" \
238     'keep first'
239
240   # check -inplace
241   # Hard link the message and verify that the new one does get annotated.
242   ln "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
243   cat >"$expected" <<EOF
244 From: Test8 <test8@example.com>
245 To: Some User <user@example.com>
246 Date: Fri, 29 Sep 2006 00:00:00
247 Subject: Testing message 8
248 Resent-From: ${localmbox}
249 Resent-To: somebody@example.com
250 Resent-Date:
251
252 This is message number 8
253 EOF
254   test_dist 8 -noedit -to somebody@example.com -annotate -noinplace -inplace
255   check "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
256 fi
257
258 # check -draftfolder
259 cat >"$expected" <<EOF
260 From: Test3 <test3@example.com>
261 To: Some User <user@example.com>
262 Date: Fri, 29 Sep 2006 00:00:00
263 Subject: Testing message 3
264 Resent-From: ${localmbox}
265 Resent-To: somebody@example.com
266 Resent-Date:
267
268 This is message number 3
269 EOF
270
271 test_dist 3 -noedit -to somebody@example.com -draftfolder drafts
272
273 # check -draftmsg
274 cat >"$expected" <<EOF
275 From: Test3 <test3@example.com>
276 To: Some User <user@example.com>
277 Date: Fri, 29 Sep 2006 00:00:00
278 Subject: Testing message 3
279 Resent-From: ${localmbox}
280 Resent-To: somebody@example.com
281 Resent-Date:
282
283 This is message number 3
284 EOF
285
286 touch $MH_TEST_DIR/Mail/drafts/3
287 test_dist 3 -noedit -to somebody@example.com -draftfolder drafts -draftmessage 2
288
289 # check -nodraftfolder
290 cat >"$expected" <<EOF
291 From: Test3 <test3@example.com>
292 To: Some User <user@example.com>
293 Date: Fri, 29 Sep 2006 00:00:00
294 Subject: Testing message 3
295 Resent-From: ${localmbox}
296 Resent-To: somebody@example.com
297 Resent-Date:
298
299 This is message number 3
300 EOF
301
302 test_dist 3 -noedit -to somebody@example.com -draftfolder nonexistent \
303   -nodraftfolder
304 if test -d "${MH_TEST_DIR}/Mail/nonexistent"; then
305   echo "$0: -nodraftfolder test failed."
306   failed=`expr ${failed:-0} + 1`
307 fi
308
309 # check -from
310 cat >"$expected" <<EOF
311 From: Test1 <test1@example.com>
312 To: Some User <user@example.com>
313 Date: Fri, 29 Sep 2006 00:00:00
314 Subject: Testing message 1
315 Resent-From: me@example.com
316 Resent-To: somebody@example.com
317 Resent-Date:
318
319 This is message number 1
320 EOF
321
322 test_dist 1 -noedit -to somebody@example.com -from me@example.com
323
324 # check -cc
325 cat >"$expected" <<EOF
326 From: Test1 <test1@example.com>
327 To: Some User <user@example.com>
328 Date: Fri, 29 Sep 2006 00:00:00
329 Subject: Testing message 1
330 Resent-From: ${localmbox}
331 Resent-To: somebody@example.com
332 Resent-cc: cc@example.com
333 Resent-Date:
334
335 This is message number 1
336 EOF
337
338 test_dist 1 -noedit -to somebody@example.com -cc cc@example.com
339
340 # check -fcc
341 cat >"$expected" <<EOF
342 From: Test1 <test1@example.com>
343 To: Some User <user@example.com>
344 Date: Fri, 29 Sep 2006 00:00:00
345 Subject: Testing message 1
346 Resent-From: ${localmbox}
347 Resent-To: somebody@example.com
348 Resent-Date:
349
350 This is message number 1
351 EOF
352
353 test_dist 1 -noedit -to somebody@example.com -fcc outbox
354 run_test 'scan +outbox -width 6' '   1 '
355
356 cat >"$expected" <<EOF
357 From: Test1 <test1@example.com>
358 To: Some User <user@example.com>
359 Date: Fri, 29 Sep 2006 00:00:00
360 Subject: Testing message 1
361 Resent-From: ${localmbox}
362 Resent-To: somebody@example.com
363 Resent-Date:
364
365 This is message number 1
366 EOF
367
368 test_dist +inbox 1 -noedit -to somebody@example.com -fcc +outbox
369 run_test 'scan +outbox -width 6 2' '   2 '
370
371
372 exit ${failed:-0}