]> diplodocus.org Git - nmh/blob - test/dist/test-dist
Update XOAUTH2 documentation.
[nmh] / 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 check_exit '-eq 1' dist -
20 check_exit '-eq 1' dist -editor
21 check_exit '-eq 1' dist -editor foo -editor
22 check_exit '-eq 1' dist -nowhatnowproc -whatnowproc foo -whatnowproc
23 check_exit '-eq 1' dist -file
24 check_exit '-eq 1' dist -file foo -file bar
25 check_exit '-eq 1' dist -form
26 check_exit '-eq 1' dist -draftfolder
27 check_exit '-eq 1' dist -draftfolder foo -draftfolder bar
28 check_exit '-eq 1' dist -draftmessage
29 check_exit '-eq 1' dist -draftmessage 42 -draftmessage 314
30 check_exit '-eq 1' dist -from
31 check_exit '-eq 1' dist -to
32 check_exit '-eq 1' dist -cc
33 check_exit '-eq 1' dist -fcc
34 check_exit '-eq 1' dist -width
35 check_exit '-eq 1' dist -width 42 -width 0
36 check_exit '-eq 1' dist -atfile -noatfile -
37 check_exit '-eq 1' dist + @
38 check_exit '-eq 1' dist 42 314
39 check_exit '-eq 1' dist -file foo 42
40
41 expected=$MH_TEST_DIR/$$.expected
42 expected_err=$MH_TEST_DIR/$$.expected_err
43 actual=$MH_TEST_DIR/$$.actual
44 actual_err=$MH_TEST_DIR/$$.actual_err
45 localmbox=`${MH_LIBEXEC_DIR}/ap -format "%(localmbox)" 0 | sed 's/^<\(.*\)>$/\1/'`
46
47 #### Use sendmail/pipe below to override default mts.
48 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
49 sed -e 's/^mts:.*/mts: sendmail\/pipe/' "${MHMTSCONF}" > "$mts_fakesendmail"
50 printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
51 MHMTSCONF="$mts_fakesendmail"
52
53 # arguments: dist switches
54 test_dist ()
55 {
56 printf 'send\n' | run_prog dist "$@" >/dev/null
57
58 # fakesendmail drops the message and any cc's into this mbox.
59 mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
60 inc -silent -file "$mbox"
61 rm -f "$mbox"
62
63 # It's hard to calculate the exact Date: header post is going to
64 # use, so we'll just use sed to remove the actual date so we can
65 # easily compare it against our "correct" output.
66 sed -e 's/^Resent-Date:.*/Resent-Date:/' `mhpath last` > "$actual"
67
68 check "$expected" "$actual"
69 }
70
71
72 # check -help
73 start_test "-help"
74 cat >"$expected" <<EOF
75 Usage: dist [+folder] [msg] [switches]
76 switches are:
77 -[no]annotate
78 -draftfolder +folder
79 -draftmessage msg
80 -nodraftfolder
81 -editor editor
82 -noedit
83 -form formfile
84 -[no]inplace
85 -whatnowproc program
86 -nowhatnowproc
87 -version
88 -help
89 -from address
90 -to address
91 -cc address
92 -fcc mailbox
93 -width columns
94 -[no]atfile
95 EOF
96
97 #### Skip nmh intro text.
98 dist -help 2>&1 | sed '/^$/,$d' >"$actual"
99 check "$expected" "$actual"
100
101 # check -version
102 start_test "-version"
103 case `dist -v` in
104 dist\ --*) ;;
105 * ) printf '%s: dist -v generated unexpected output\n' "$0" >&2
106 failed=`expr ${failed:-0} + 1`;;
107 esac
108
109 # check unknown switch
110 start_test "unknown switch"
111 run_test "dist -nonexistent" 'dist: -nonexistent unknown'
112
113 folder +outbox -create -fast >/dev/null
114 folder +inbox -fast 1 >/dev/null
115
116 # For most tests, use -nowhatnow and just check that the draft
117 # looks correct.
118
119 # check basic dist operation, including -noedit and -to
120 start_test "basic dist operation, including -noedit and -to"
121 cat >"$expected" <<EOF
122 From: Test1 <test1@example.com>
123 To: Some User <user@example.com>
124 Date: Fri, 29 Sep 2006 00:00:00
125 Message-Id: 1@test.nmh
126 Subject: Testing message 1
127 Resent-From: ${localmbox}
128 Resent-To: somebody@example.com
129 Resent-Date:
130
131 This is message number 1
132 EOF
133
134 test_dist -noedit -to somebody@example.com
135
136 # check +folder and msg
137 start_test "+folder and msg"
138 folder +outbox -fast >/dev/null
139
140 cat >"$expected" <<EOF
141 From: Test1 <test1@example.com>
142 To: Some User <user@example.com>
143 Date: Fri, 29 Sep 2006 00:00:00
144 Message-Id: 1@test.nmh
145 Subject: Testing message 1
146 Resent-From: ${localmbox}
147 Resent-To: somebody@example.com
148 Resent-Date:
149
150 This is message number 1
151 EOF
152
153 test_dist +inbox 1 -noedit -to somebody@example.com
154
155 # check -form
156 start_test "-form"
157 cat >"${MH_TEST_DIR}/Mail/distform" <<'EOF'
158 Resent-From: me@example.com
159 Resent-To: you@example.com
160 EOF
161
162 cat >"$expected" <<EOF
163 From: Test1 <test1@example.com>
164 To: Some User <user@example.com>
165 Date: Fri, 29 Sep 2006 00:00:00
166 Message-Id: 1@test.nmh
167 Subject: Testing message 1
168 Resent-From: me@example.com
169 Resent-To: you@example.com
170 Resent-Date:
171
172 This is message number 1
173 EOF
174
175 test_dist 1 -noedit -form "${MH_TEST_DIR}"/Mail/distform
176
177 rm "${MH_TEST_DIR}"/Mail/distform
178
179 # check -annotate
180 start_test "-annotate"
181 cat >"$expected" <<EOF
182 From: Test2 <test2@example.com>
183 To: Some User <user@example.com>
184 Date: Fri, 29 Sep 2006 00:00:00
185 Message-Id: 2@test.nmh
186 Subject: Testing message 2
187 Resent-From: ${localmbox}
188 Resent-To: somebody@example.com
189 Resent-Date:
190
191 This is message number 2
192 EOF
193
194 test_dist 2 -noedit -to somebody@example.com -annotate
195
196 cat >"$expected" <<EOF
197 Resent:
198 Resent: somebody@example.com
199 From: Test2 <test2@example.com>
200 To: Some User <user@example.com>
201 Date: Fri, 29 Sep 2006 00:00:00
202 Message-Id: 2@test.nmh
203 Subject: Testing message 2
204
205 This is message number 2
206 EOF
207
208 # The annotation is done by a separate process, so we need to wait for
209 # it to complete.
210 i=1
211 until grep '^Resent:' "${MH_TEST_DIR}"/Mail/inbox/2 >/dev/null; do
212 sleep 2
213 arith_eval $i + 1
214 i=$arith_val
215 if [ $i -gt 60 ]; then
216 printf '%s: -annotate failed, will not wait any longer\n' "$0"
217 break
218 fi
219 done
220
221 # Strip date from line of this form:
222 # Resent: Sat, 06 Oct 2012 08:24:08 -0500
223 sed -e 's/^Resent:.*:.*/Resent:/' "${MH_TEST_DIR}"/Mail/inbox/2 >"$actual"
224
225 check "$expected" "$actual"
226
227 # check -noannotate
228 start_test "-noannotate"
229 cat >"$expected" <<EOF
230 From: Test1 <test1@example.com>
231 To: Some User <user@example.com>
232 Date: Fri, 29 Sep 2006 00:00:00
233 Message-Id: 1@test.nmh
234 Subject: Testing message 1
235 Resent-From: ${localmbox}
236 Resent-To: somebody@example.com
237 Resent-Date:
238
239 This is message number 1
240 EOF
241
242 test_dist 1 -noedit -to somebody@example.com -annotate -noannotate
243
244 cat >"$expected" <<EOF
245 From: Test1 <test1@example.com>
246 To: Some User <user@example.com>
247 Date: Fri, 29 Sep 2006 00:00:00
248 Message-Id: 1@test.nmh
249 Subject: Testing message 1
250
251 This is message number 1
252 EOF
253
254 check "${MH_TEST_DIR}"/Mail/inbox/1 "$expected" 'keep first'
255
256 check_for_hard_links
257 if [ $hard_links_supported -eq 1 ]; then
258 # check -noinplace
259 start_test "-noinplace"
260 # Hard link the message and verify that the new one doesn't get annotated.
261 cp "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.copy"
262 ln "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
263 cat >"$expected" <<EOF
264 From: Test8 <test8@example.com>
265 To: Some User <user@example.com>
266 Date: Fri, 29 Sep 2006 00:00:00
267 Message-Id: 8@test.nmh
268 Subject: Testing message 8
269 Resent-From: ${localmbox}
270 Resent-To: somebody@example.com
271 Resent-Date:
272
273 This is message number 8
274 EOF
275 test_dist 8 -noedit -to somebody@example.com -annotate -noinplace
276 mv -f "${MH_TEST_DIR}/Mail/inbox/8.copy" "${MH_TEST_DIR}/Mail/inbox/8"
277 check "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link" \
278 'keep first'
279
280 # check -inplace
281 start_test "-inplace"
282 # Hard link the message and verify that the new one does get annotated.
283 ln "${MH_TEST_DIR}/Mail/inbox/9" "${MH_TEST_DIR}/Mail/inbox/9.link"
284 cat >"$expected" <<EOF
285 From: Test9 <test9@example.com>
286 To: Some User <user@example.com>
287 Date: Fri, 29 Sep 2006 00:00:00
288 Message-Id: 9@test.nmh
289 Subject: Testing message 9
290 Resent-From: ${localmbox}
291 Resent-To: somebody@example.com
292 Resent-Date:
293
294 This is message number 9
295 EOF
296 test_dist 9 -noedit -to somebody@example.com -annotate -noinplace -inplace
297 check "${MH_TEST_DIR}/Mail/inbox/9" "${MH_TEST_DIR}/Mail/inbox/9.link"
298 fi
299
300 # check -draftfolder
301 start_test "-draftfolder"
302 cat >"$expected" <<EOF
303 From: Test3 <test3@example.com>
304 To: Some User <user@example.com>
305 Date: Fri, 29 Sep 2006 00:00:00
306 Message-Id: 3@test.nmh
307 Subject: Testing message 3
308 Resent-From: ${localmbox}
309 Resent-To: somebody@example.com
310 Resent-Date:
311
312 This is message number 3
313 EOF
314
315 test_dist 3 -noedit -to somebody@example.com -draftfolder drafts
316
317 # check -draftmsg
318 start_test "-draftmsg"
319 cat >"$expected" <<EOF
320 From: Test3 <test3@example.com>
321 To: Some User <user@example.com>
322 Date: Fri, 29 Sep 2006 00:00:00
323 Message-Id: 3@test.nmh
324 Subject: Testing message 3
325 Resent-From: ${localmbox}
326 Resent-To: somebody@example.com
327 Resent-Date:
328
329 This is message number 3
330 EOF
331
332 touch $MH_TEST_DIR/Mail/drafts/3
333 test_dist 3 -noedit -to somebody@example.com -draftfolder drafts -draftmessage 2
334
335 # check -nodraftfolder
336 start_test "-nodraftfolder"
337 cat >"$expected" <<EOF
338 From: Test3 <test3@example.com>
339 To: Some User <user@example.com>
340 Date: Fri, 29 Sep 2006 00:00:00
341 Message-Id: 3@test.nmh
342 Subject: Testing message 3
343 Resent-From: ${localmbox}
344 Resent-To: somebody@example.com
345 Resent-Date:
346
347 This is message number 3
348 EOF
349
350 test_dist 3 -noedit -to somebody@example.com -draftfolder nonexistent \
351 -nodraftfolder
352 if test -d "${MH_TEST_DIR}/Mail/nonexistent"; then
353 echo "$0: -nodraftfolder test failed."
354 failed=`expr ${failed:-0} + 1`
355 fi
356
357 # check -from
358 start_test "-from"
359 cat >"$expected" <<EOF
360 From: Test1 <test1@example.com>
361 To: Some User <user@example.com>
362 Date: Fri, 29 Sep 2006 00:00:00
363 Message-Id: 1@test.nmh
364 Subject: Testing message 1
365 Resent-From: me@example.com
366 Resent-To: somebody@example.com
367 Resent-Date:
368
369 This is message number 1
370 EOF
371
372 test_dist 1 -noedit -to somebody@example.com -from me@example.com
373
374 # check -cc
375 start_test "-cc"
376 cat >"$expected" <<EOF
377 From: Test1 <test1@example.com>
378 To: Some User <user@example.com>
379 Date: Fri, 29 Sep 2006 00:00:00
380 Message-Id: 1@test.nmh
381 Subject: Testing message 1
382 Resent-From: ${localmbox}
383 Resent-To: somebody@example.com
384 Resent-cc: cc@example.com
385 Resent-Date:
386
387 This is message number 1
388 EOF
389
390 test_dist 1 -noedit -to somebody@example.com -cc cc@example.com
391
392 # check -fcc
393 start_test "-fcc"
394 cat >"$expected" <<EOF
395 From: Test1 <test1@example.com>
396 To: Some User <user@example.com>
397 Date: Fri, 29 Sep 2006 00:00:00
398 Message-Id: 1@test.nmh
399 Subject: Testing message 1
400 Resent-From: ${localmbox}
401 Resent-To: somebody@example.com
402 Resent-Date:
403
404 This is message number 1
405 EOF
406
407 test_dist 1 -noedit -to somebody@example.com -fcc outbox
408 run_test 'scan +outbox -width 6' ' 1 '
409
410 # check -fcc with +
411 start_test "-fcc with +"
412 cat >"$expected" <<EOF
413 From: Test1 <test1@example.com>
414 To: Some User <user@example.com>
415 Date: Fri, 29 Sep 2006 00:00:00
416 Message-Id: 1@test.nmh
417 Subject: Testing message 1
418 Resent-From: ${localmbox}
419 Resent-To: somebody@example.com
420 Resent-Date:
421
422 This is message number 1
423 EOF
424
425 test_dist +inbox 1 -noedit -to somebody@example.com -fcc +outbox
426 run_test 'scan +outbox -width 6 2' ' 2 '
427
428 # check Distribute- and Distribution-
429 start_test "Distribute- and Distribution-"
430 cat >"$expected" <<EOF
431 -- Network Recipients --
432 dist-recipient at example.com
433 EOF
434
435 folder -f +inbox >/dev/null
436 arith_eval `pick last` + 1
437 new_msg=$arith_val
438 cat >`mhpath new` <<EOF
439 From: Test$new_msg <test$new_msg@example.com>
440 Date: Sun, 10 May 2020 10:00:00
441 EOF
442
443 cat >`mhpath new` <<EOF
444 Distribution-From: <a@example.com>
445 Distribute-To: <dist-recipient@example.com>
446 EOF
447
448 mhdist=`pick last` mhaltmsg=`mhpath $new_msg` whom `mhpath last` >"$actual"
449 check "$expected" "$actual"
450
451 #
452 # Check that dist encodes headers using RFC-2047 properly
453 #
454 start_test "dist encodes headers using RFC-2047 properly"
455 require_locale en_US.UTF-8 en_US.UTF8 en_US.utf-8 en_US.utf8
456
457 cat >"$expected" <<EOF
458 From: Test1 <test1@example.com>
459 To: Some User <user@example.com>
460 Date: Fri, 29 Sep 2006 00:00:00
461 Message-Id: 1@test.nmh
462 Subject: Testing message 1
463 Resent-From: =?UTF-8?Q?Mr_F=C3=B8o_Bar?= <resent-from@example.com>
464 Resent-To: =?UTF-8?Q?Mr_Nobod=C3=BF?= <resent-to@example.com>
465 Resent-Date:
466
467 This is message number 1
468 EOF
469
470 test_dist +inbox 1 -noedit -from 'Mr Føo Bar <resent-from@example.com>' \
471 -to 'Mr Nobodÿ <resent-to@example.com>' -fcc +outbox
472
473 finish_test
474 exit ${failed:-0}