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