]> diplodocus.org Git - nmh/blob - test/dist/test-dist
mhbuildsbr.c: Flip logic, moving goto to then-block; no need for else.
[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 cat >"$expected" <<EOF
74 Usage: dist [+folder] [msg] [switches]
75 switches are:
76 -[no]annotate
77 -draftfolder +folder
78 -draftmessage msg
79 -nodraftfolder
80 -editor editor
81 -noedit
82 -form formfile
83 -[no]inplace
84 -whatnowproc program
85 -nowhatnowproc
86 -version
87 -help
88 -from address
89 -to address
90 -cc address
91 -fcc mailbox
92 -width columns
93 -[no]atfile
94 EOF
95
96 #### Skip nmh intro text.
97 dist -help | sed '/^$/,$d' >"$actual" 2>&1
98 check "$expected" "$actual"
99
100 # check -version
101 case `dist -v` in
102 dist\ --*) ;;
103 * ) printf '%s: dist -v generated unexpected output\n' "$0" >&2
104 failed=`expr ${failed:-0} + 1`;;
105 esac
106
107 # check unknown switch
108 run_test "dist -nonexistent" 'dist: -nonexistent unknown'
109
110 folder +outbox -create -fast >/dev/null
111 folder +inbox -fast 1 >/dev/null
112
113 # For most tests, use -nowhatnow and just check that the draft
114 # looks correct.
115
116 # check basic dist operation, including -noedit and -to
117 cat >"$expected" <<EOF
118 From: Test1 <test1@example.com>
119 To: Some User <user@example.com>
120 Date: Fri, 29 Sep 2006 00:00:00
121 Message-Id: 1@test.nmh
122 Subject: Testing message 1
123 Resent-From: ${localmbox}
124 Resent-To: somebody@example.com
125 Resent-Date:
126
127 This is message number 1
128 EOF
129
130 test_dist -noedit -to somebody@example.com
131
132 # check +folder and msg
133 folder +outbox -fast >/dev/null
134
135 cat >"$expected" <<EOF
136 From: Test1 <test1@example.com>
137 To: Some User <user@example.com>
138 Date: Fri, 29 Sep 2006 00:00:00
139 Message-Id: 1@test.nmh
140 Subject: Testing message 1
141 Resent-From: ${localmbox}
142 Resent-To: somebody@example.com
143 Resent-Date:
144
145 This is message number 1
146 EOF
147
148 test_dist +inbox 1 -noedit -to somebody@example.com
149
150 # check -form
151 cat >"${MH_TEST_DIR}/Mail/distform" <<'EOF'
152 Resent-From: me@example.com
153 Resent-To: you@example.com
154 EOF
155
156 cat >"$expected" <<EOF
157 From: Test1 <test1@example.com>
158 To: Some User <user@example.com>
159 Date: Fri, 29 Sep 2006 00:00:00
160 Message-Id: 1@test.nmh
161 Subject: Testing message 1
162 Resent-From: me@example.com
163 Resent-To: you@example.com
164 Resent-Date:
165
166 This is message number 1
167 EOF
168
169 test_dist 1 -noedit -form "${MH_TEST_DIR}"/Mail/distform
170
171 rm "${MH_TEST_DIR}"/Mail/distform
172
173 # check -annotate
174 cat >"$expected" <<EOF
175 From: Test2 <test2@example.com>
176 To: Some User <user@example.com>
177 Date: Fri, 29 Sep 2006 00:00:00
178 Message-Id: 2@test.nmh
179 Subject: Testing message 2
180 Resent-From: ${localmbox}
181 Resent-To: somebody@example.com
182 Resent-Date:
183
184 This is message number 2
185 EOF
186
187 test_dist 2 -noedit -to somebody@example.com -annotate
188
189 cat >"$expected" <<EOF
190 Resent:
191 Resent: somebody@example.com
192 From: Test2 <test2@example.com>
193 To: Some User <user@example.com>
194 Date: Fri, 29 Sep 2006 00:00:00
195 Message-Id: 2@test.nmh
196 Subject: Testing message 2
197
198 This is message number 2
199 EOF
200
201 # The annotation is done by a separate process, so we need to wait for
202 # it to complete.
203 i=1
204 until grep '^Resent:' "${MH_TEST_DIR}"/Mail/inbox/2 >/dev/null; do
205 sleep 2
206 arith_eval $i + 1
207 i=$arith_val
208 if [ $i -gt 60 ]; then
209 printf '%s: -annotate failed, will not wait any longer\n' "$0"
210 break
211 fi
212 done
213
214 # Strip date from line of this form:
215 # Resent: Sat, 06 Oct 2012 08:24:08 -0500
216 sed -e 's/^Resent:.*:.*/Resent:/' "${MH_TEST_DIR}"/Mail/inbox/2 >"$actual"
217
218 check "$expected" "$actual"
219
220 # check -noannotate
221 cat >"$expected" <<EOF
222 From: Test1 <test1@example.com>
223 To: Some User <user@example.com>
224 Date: Fri, 29 Sep 2006 00:00:00
225 Message-Id: 1@test.nmh
226 Subject: Testing message 1
227 Resent-From: ${localmbox}
228 Resent-To: somebody@example.com
229 Resent-Date:
230
231 This is message number 1
232 EOF
233
234 test_dist 1 -noedit -to somebody@example.com -annotate -noannotate
235
236 cat >"$expected" <<EOF
237 From: Test1 <test1@example.com>
238 To: Some User <user@example.com>
239 Date: Fri, 29 Sep 2006 00:00:00
240 Message-Id: 1@test.nmh
241 Subject: Testing message 1
242
243 This is message number 1
244 EOF
245
246 check "${MH_TEST_DIR}"/Mail/inbox/1 "$expected" 'keep first'
247
248 check_for_hard_links
249 if [ $hard_links_supported -eq 1 ]; then
250 # check -noinplace
251 # Hard link the message and verify that the new one doesn't get annotated.
252 cp "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.copy"
253 ln "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
254 cat >"$expected" <<EOF
255 From: Test8 <test8@example.com>
256 To: Some User <user@example.com>
257 Date: Fri, 29 Sep 2006 00:00:00
258 Message-Id: 8@test.nmh
259 Subject: Testing message 8
260 Resent-From: ${localmbox}
261 Resent-To: somebody@example.com
262 Resent-Date:
263
264 This is message number 8
265 EOF
266 test_dist 8 -noedit -to somebody@example.com -annotate -noinplace
267 mv -f "${MH_TEST_DIR}/Mail/inbox/8.copy" "${MH_TEST_DIR}/Mail/inbox/8"
268 check "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link" \
269 'keep first'
270
271 # check -inplace
272 # Hard link the message and verify that the new one does get annotated.
273 ln "${MH_TEST_DIR}/Mail/inbox/9" "${MH_TEST_DIR}/Mail/inbox/9.link"
274 cat >"$expected" <<EOF
275 From: Test9 <test9@example.com>
276 To: Some User <user@example.com>
277 Date: Fri, 29 Sep 2006 00:00:00
278 Message-Id: 9@test.nmh
279 Subject: Testing message 9
280 Resent-From: ${localmbox}
281 Resent-To: somebody@example.com
282 Resent-Date:
283
284 This is message number 9
285 EOF
286 test_dist 9 -noedit -to somebody@example.com -annotate -noinplace -inplace
287 check "${MH_TEST_DIR}/Mail/inbox/9" "${MH_TEST_DIR}/Mail/inbox/9.link"
288 fi
289
290 # check -draftfolder
291 cat >"$expected" <<EOF
292 From: Test3 <test3@example.com>
293 To: Some User <user@example.com>
294 Date: Fri, 29 Sep 2006 00:00:00
295 Message-Id: 3@test.nmh
296 Subject: Testing message 3
297 Resent-From: ${localmbox}
298 Resent-To: somebody@example.com
299 Resent-Date:
300
301 This is message number 3
302 EOF
303
304 test_dist 3 -noedit -to somebody@example.com -draftfolder drafts
305
306 # check -draftmsg
307 cat >"$expected" <<EOF
308 From: Test3 <test3@example.com>
309 To: Some User <user@example.com>
310 Date: Fri, 29 Sep 2006 00:00:00
311 Message-Id: 3@test.nmh
312 Subject: Testing message 3
313 Resent-From: ${localmbox}
314 Resent-To: somebody@example.com
315 Resent-Date:
316
317 This is message number 3
318 EOF
319
320 touch $MH_TEST_DIR/Mail/drafts/3
321 test_dist 3 -noedit -to somebody@example.com -draftfolder drafts -draftmessage 2
322
323 # check -nodraftfolder
324 cat >"$expected" <<EOF
325 From: Test3 <test3@example.com>
326 To: Some User <user@example.com>
327 Date: Fri, 29 Sep 2006 00:00:00
328 Message-Id: 3@test.nmh
329 Subject: Testing message 3
330 Resent-From: ${localmbox}
331 Resent-To: somebody@example.com
332 Resent-Date:
333
334 This is message number 3
335 EOF
336
337 test_dist 3 -noedit -to somebody@example.com -draftfolder nonexistent \
338 -nodraftfolder
339 if test -d "${MH_TEST_DIR}/Mail/nonexistent"; then
340 echo "$0: -nodraftfolder test failed."
341 failed=`expr ${failed:-0} + 1`
342 fi
343
344 # check -from
345 cat >"$expected" <<EOF
346 From: Test1 <test1@example.com>
347 To: Some User <user@example.com>
348 Date: Fri, 29 Sep 2006 00:00:00
349 Message-Id: 1@test.nmh
350 Subject: Testing message 1
351 Resent-From: me@example.com
352 Resent-To: somebody@example.com
353 Resent-Date:
354
355 This is message number 1
356 EOF
357
358 test_dist 1 -noedit -to somebody@example.com -from me@example.com
359
360 # check -cc
361 cat >"$expected" <<EOF
362 From: Test1 <test1@example.com>
363 To: Some User <user@example.com>
364 Date: Fri, 29 Sep 2006 00:00:00
365 Message-Id: 1@test.nmh
366 Subject: Testing message 1
367 Resent-From: ${localmbox}
368 Resent-To: somebody@example.com
369 Resent-cc: cc@example.com
370 Resent-Date:
371
372 This is message number 1
373 EOF
374
375 test_dist 1 -noedit -to somebody@example.com -cc cc@example.com
376
377 # check -fcc
378 cat >"$expected" <<EOF
379 From: Test1 <test1@example.com>
380 To: Some User <user@example.com>
381 Date: Fri, 29 Sep 2006 00:00:00
382 Message-Id: 1@test.nmh
383 Subject: Testing message 1
384 Resent-From: ${localmbox}
385 Resent-To: somebody@example.com
386 Resent-Date:
387
388 This is message number 1
389 EOF
390
391 test_dist 1 -noedit -to somebody@example.com -fcc outbox
392 run_test 'scan +outbox -width 6' ' 1 '
393
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 +inbox 1 -noedit -to somebody@example.com -fcc +outbox
408 run_test 'scan +outbox -width 6 2' ' 2 '
409
410 #
411 # Check that dist encodes headers using RFC-2047 properly
412 #
413
414 require_locale en_US.UTF-8 en_US.UTF8 en_US.utf-8 en_US.utf8
415
416 cat >"$expected" <<EOF
417 From: Test1 <test1@example.com>
418 To: Some User <user@example.com>
419 Date: Fri, 29 Sep 2006 00:00:00
420 Message-Id: 1@test.nmh
421 Subject: Testing message 1
422 Resent-From: =?UTF-8?Q?Mr_F=C3=B8o_Bar?= <resent-from@example.com>
423 Resent-To: =?UTF-8?Q?Mr_Nobod=C3=BF?= <resent-to@example.com>
424 Resent-Date:
425
426 This is message number 1
427 EOF
428
429 test_dist +inbox 1 -noedit -from 'Mr Føo Bar <resent-from@example.com>' \
430 -to 'Mr Nobodÿ <resent-to@example.com>' -fcc +outbox
431
432 exit ${failed:-0}