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